2
2
3
3
import java .io .File ;
4
4
import java .io .IOException ;
5
+ import java .io .InputStream ;
5
6
import java .util .Collections ;
6
7
import java .util .List ;
7
8
import java .util .function .Consumer ;
@@ -40,9 +41,10 @@ public synchronized void start() throws IOException {
40
41
.directory (new File (args .get (0 )).getParentFile ())
41
42
.start ();
42
43
addShutdownHook ("RedisInstanceCleaner" , checkedToRuntime (this ::stop ));
44
+ awaitServerReady (process , readyPattern , soutListener , serrListener );
45
+
43
46
if (serrListener != null )
44
47
newDaemonThread (() -> logStream (process .getErrorStream (), serrListener )).start ();
45
- awaitServerReady (process , readyPattern , soutListener );
46
48
if (soutListener != null )
47
49
newDaemonThread (() -> logStream (process .getInputStream (), soutListener )).start ();
48
50
@@ -52,11 +54,22 @@ public synchronized void start() throws IOException {
52
54
}
53
55
}
54
56
55
- private static void awaitServerReady (final Process process , final Pattern readyPattern ,
56
- final Consumer <String > soutListener ) throws IOException {
57
+ private static void awaitServerReady (final Process process , final Pattern readyPattern
58
+ , final Consumer < String > soutListener , final Consumer <String > serrListener ) throws IOException {
57
59
final StringBuilder log = new StringBuilder ();
58
- if (!findMatchInStream (process .getInputStream (), readyPattern , soutListener , log ))
59
- throw new IOException ("Ready pattern not found in log. Startup log: " + log );
60
+ if (!findMatchInStream (process .getInputStream (), readyPattern , soutListener , log )) {
61
+ final String stdOut = log .toString ();
62
+ final String stdErr = readFully (process .getErrorStream (), serrListener );
63
+
64
+ throw new IOException ("Redis-server process appears not to have started. "
65
+ + (isNullOrEmpty (stdOut ) ? "No output was found in standard-out." : "stdandard-out contains this: " + stdOut )
66
+ + " "
67
+ + (isNullOrEmpty (stdErr ) ? "No output was found in standard-err." : "stdandard-err contains this: " + stdErr )
68
+ );
69
+ }
70
+ }
71
+ private static boolean isNullOrEmpty (final String value ) {
72
+ return value == null || value .isEmpty ();
60
73
}
61
74
62
75
public synchronized void stop () throws IOException {
0 commit comments