Skip to content

Commit

Permalink
Merge pull request ozimov#10 from ashok2ashok/master
Browse files Browse the repository at this point in the history
Issue-51: Prints Process Logs in RuntimeException Message
  • Loading branch information
robertotru authored Mar 12, 2020
2 parents 7201b29 + ba98e75 commit aeef6be
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 aeef6be

Please sign in to comment.