Skip to content

Commit

Permalink
Issue-51: Prints Process Logs in RuntimeException Message
Browse files Browse the repository at this point in the history
This resolves the issue: kstyrc#51

While resolving logs at the process level is preferred as specified in the pull-request: kstyrc#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
  • Loading branch information
agoli-dd committed Mar 12, 2020
1 parent 7201b29 commit ba98e75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java

sudo: false # faster builds
dist: trusty

jdk:
- oraclejdk8
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/redis/embedded/AbstractRedisInstance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.embedded;

import org.apache.commons.io.IOUtils;
import redis.embedded.exceptions.EmbeddedRedisException;

import java.io.*;
Expand All @@ -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<String> args = Collections.emptyList();
private volatile boolean active = false;
Expand All @@ -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...");
Expand All @@ -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 {
Expand All @@ -76,7 +78,6 @@ private ProcessBuilder createRedisProcessBuilder() {
return pb;
}

@Override
public synchronized void stop() throws EmbeddedRedisException {
if (active) {
if (executor != null && !executor.isShutdown()) {
Expand All @@ -96,7 +97,6 @@ private void tryWaitFor() {
}
}

@Override
public List<Integer> ports() {
return Arrays.asList(port);
}
Expand Down

0 comments on commit ba98e75

Please sign in to comment.