Skip to content
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

Update sentinel ready pattern for redis 3.2 and add an overloaded sta… #99

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
13 changes: 9 additions & 4 deletions src/main/java/redis/embedded/AbstractRedisInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ public boolean isActive() {
return active;
}

@Override
@Override
public synchronized void start() throws EmbeddedRedisException {
start(redisReadyPattern());
}

@Override
public synchronized void start(String redisReadyPattern) throws EmbeddedRedisException {
if (active) {
throw new EmbeddedRedisException("This redis server instance is already running...");
}
try {
redisProcess = createRedisProcessBuilder().start();
logErrors();
awaitRedisServerReady();
awaitRedisServerReady(redisReadyPattern);
active = true;
} catch (IOException e) {
throw new EmbeddedRedisException("Failed to start Redis instance", e);
Expand All @@ -51,7 +56,7 @@ private void logErrors() {
executor.submit(printReaderTask);
}

private void awaitRedisServerReady() throws IOException {
private void awaitRedisServerReady(String redisReadyPattern) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(redisProcess.getInputStream()));
try {
String outputLine;
Expand All @@ -61,7 +66,7 @@ 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 (!outputLine.matches(redisReadyPattern));
} finally {
IOUtils.closeQuietly(reader);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/redis/embedded/Redis.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface Redis {

void start() throws EmbeddedRedisException;

void start(String redisReadyPattern) throws EmbeddedRedisException;

void stop() throws EmbeddedRedisException;

List<Integer> ports();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/embedded/RedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public void start() throws EmbeddedRedisException {
}
}

@Override
public void start(String redisReadyPattern) throws EmbeddedRedisException {
for(Redis redis : sentinels) {
redis.start(redisReadyPattern);
}
for(Redis redis : servers) {
redis.start(redisReadyPattern);
}
}

@Override
public void stop() throws EmbeddedRedisException {
for(Redis redis : sentinels) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/embedded/RedisSentinel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

public class RedisSentinel extends AbstractRedisInstance {
private static final String REDIS_READY_PATTERN = ".*Sentinel runid is.*";
private static final String REDIS_READY_PATTERN = ".*Sentinel (runid|ID) is.*";

public RedisSentinel(List<String> args, int port) {
super(port);
Expand Down