From ba98e75c7b285a69bd1cc05442a476ddc84324ef Mon Sep 17 00:00:00 2001 From: Ashok Goli Date: Thu, 12 Mar 2020 14:26:19 -0500 Subject: [PATCH] Issue-51: Prints Process Logs in RuntimeException Message This resolves the issue: https://github.com/kstyrc/embedded-redis/issues/51 While resolving logs at the process level is preferred as specified in the pull-request: https://github.com/kstyrc/embedded-redis/pull/113 - this fix takes a much more conservative approach and prints the redis process logs only in case of an error/exception when the server startup pattern is not found. That way we do not need to worry about logs in case of successful redis server starts. Dist updated to trusty to resolves travis jdk8 build issue caused by xenial dist Removed sudo and curl commands as they are not longer supported. jpm4j is not longer functional and sudo is deprecated in travis --- .travis.yml | 3 +-- .../java/redis/embedded/AbstractRedisInstance.java | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54dff226..5c63c1d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: java -sudo: false # faster builds +dist: trusty jdk: - oraclejdk8 @@ -10,7 +10,6 @@ install: before_script: - pip install --user codecov - - curl http://www.jpm4j.org/install/script | sh script: - mvn -U -B -V test --fail-at-end -Dsource.skip=true -Dmaven.javadoc.skip=true diff --git a/src/main/java/redis/embedded/AbstractRedisInstance.java b/src/main/java/redis/embedded/AbstractRedisInstance.java index abeae789..7dd75428 100644 --- a/src/main/java/redis/embedded/AbstractRedisInstance.java +++ b/src/main/java/redis/embedded/AbstractRedisInstance.java @@ -1,5 +1,6 @@ package redis.embedded; +import org.apache.commons.io.IOUtils; import redis.embedded.exceptions.EmbeddedRedisException; import java.io.*; @@ -9,8 +10,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.commons.io.IOUtils; - abstract class AbstractRedisInstance implements Redis { protected List args = Collections.emptyList(); private volatile boolean active = false; @@ -23,12 +22,10 @@ protected AbstractRedisInstance(int port) { this.port = port; } - @Override public boolean isActive() { return active; } - @Override public synchronized void start() throws EmbeddedRedisException { if (active) { throw new EmbeddedRedisException("This redis server instance is already running..."); @@ -54,12 +51,17 @@ private void logErrors() { private void awaitRedisServerReady() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(redisProcess.getInputStream())); try { + StringBuffer outputStringBuffer = new StringBuffer(); String outputLine; do { outputLine = reader.readLine(); if (outputLine == null) { //Something goes wrong. Stream is ended before server was activated. - throw new RuntimeException("Can't start redis server. Check logs for details."); + throw new RuntimeException("Can't start redis server. Check logs for details. Redis process log: "+outputStringBuffer.toString()); + } + else{ + outputStringBuffer.append("\n"); + outputStringBuffer.append(outputLine); } } while (!outputLine.matches(redisReadyPattern())); } finally { @@ -76,7 +78,6 @@ private ProcessBuilder createRedisProcessBuilder() { return pb; } - @Override public synchronized void stop() throws EmbeddedRedisException { if (active) { if (executor != null && !executor.isShutdown()) { @@ -96,7 +97,6 @@ private void tryWaitFor() { } } - @Override public List ports() { return Arrays.asList(port); }