Skip to content

Enable matching against multiple patterns to determine server readiness #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 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 Down Expand Up @@ -61,13 +60,13 @@ private void awaitRedisServerReady() throws IOException {
//Something goes wrong. Stream is ended before server was activated.
throw new RuntimeException("Can't start redis server. Check logs for details.");
}
} while (!outputLine.matches(redisReadyPattern()));
} while (!isReady(outputLine));
} finally {
IOUtils.closeQuietly(reader);
}
}

protected abstract String redisReadyPattern();
protected abstract boolean isReady(String outputLine);

private ProcessBuilder createRedisProcessBuilder() {
File executable = new File(args.get(0));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/redis/embedded/RedisSentinel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public RedisSentinel(List<String> args, int port) {

public static RedisSentinelBuilder builder() { return new RedisSentinelBuilder(); }


@Override
protected String redisReadyPattern() {
return REDIS_READY_PATTERN;
protected boolean isReady(String outputLine) {
return outputLine.matches(REDIS_READY_PATTERN);
}
}
6 changes: 4 additions & 2 deletions src/main/java/redis/embedded/RedisServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class RedisServer extends AbstractRedisInstance {
private static final String REDIS_READY_PATTERN = ".*The server is now ready to accept connections on port.*";
private static final String REDIS_4_READY_PATTERN = ".*Ready to accept connections.*";
private static final int DEFAULT_REDIS_PORT = 6379;

public RedisServer() throws IOException {
Expand Down Expand Up @@ -48,8 +49,9 @@ public static RedisServerBuilder builder() {
return new RedisServerBuilder();
}


@Override
protected String redisReadyPattern() {
return REDIS_READY_PATTERN;
protected boolean isReady(String outputLine) {
return outputLine.matches(REDIS_READY_PATTERN) || outputLine.matches(REDIS_4_READY_PATTERN);
}
}