Skip to content

Commit

Permalink
Merge pull request ozimov#8 from DmitryErmolchik/master
Browse files Browse the repository at this point in the history
Tests to check REDIS_READY_PATTERN for Redis version 2.x, 3.x, 4.x were added
  • Loading branch information
robertotru authored May 19, 2018
2 parents f6ae219 + f215d68 commit 7201b29
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 13 deletions.
37 changes: 35 additions & 2 deletions src/test/java/redis/embedded/RedisSentinelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

public class RedisSentinelTest {
private RedisSentinel sentinel;
Expand Down Expand Up @@ -57,7 +60,7 @@ public void testSimpleOperationsAfterRun() throws Exception {
//then
assertEquals("1", jedis.mget("abc").get(0));
assertEquals("2", jedis.mget("def").get(0));
assertEquals(null, jedis.mget("xyz").get(0));
assertNull(jedis.mget("xyz").get(0));
} finally {
if (jedis != null)
pool.returnResource(jedis);
Expand All @@ -66,4 +69,34 @@ public void testSimpleOperationsAfterRun() throws Exception {
}
}

@Test
public void testAwaitRedisSentinelReady() throws Exception {
String readyPattern = RedisSentinel.builder().build().redisReadyPattern();

assertReadyPattern(new BufferedReader(
new InputStreamReader(getClass()
.getClassLoader()
.getResourceAsStream("redis-2.x-sentinel-startup-output.txt"))),
readyPattern);

assertReadyPattern(new BufferedReader(
new InputStreamReader(getClass()
.getClassLoader()
.getResourceAsStream("redis-3.x-sentinel-startup-output.txt"))),
readyPattern);

assertReadyPattern(new BufferedReader(
new InputStreamReader(getClass()
.getClassLoader()
.getResourceAsStream("redis-4.x-sentinel-startup-output.txt"))),
readyPattern);
}

private void assertReadyPattern(BufferedReader reader, String readyPattern) throws IOException {
String outputLine;
do {
outputLine = reader.readLine();
assertNotNull(outputLine);
} while (!outputLine.matches(readyPattern));
}
}
57 changes: 46 additions & 11 deletions src/test/java/redis/embedded/RedisServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
import redis.embedded.util.Architecture;
import redis.embedded.util.OS;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static org.junit.Assert.*;

public class RedisServerTest {

private RedisServer redisServer;

@Test(timeout = 1500L)
public void testSimpleRun() throws Exception {
redisServer = new RedisServer(6379);
redisServer.start();
Thread.sleep(1000L);
redisServer.stop();
}

@Test(expected = RuntimeException.class)
public void shouldNotAllowMultipleRunsWithoutStop() throws Exception {
try {
Expand All @@ -32,35 +36,35 @@ public void shouldNotAllowMultipleRunsWithoutStop() throws Exception {
redisServer.stop();
}
}

@Test
public void shouldAllowSubsequentRuns() throws Exception {
redisServer = new RedisServer(6379);
redisServer.start();
redisServer.stop();

redisServer.start();
redisServer.stop();

redisServer.start();
redisServer.stop();
}

@Test
public void testSimpleOperationsAfterRun() throws Exception {
redisServer = new RedisServer(6379);
redisServer.start();

JedisPool pool = null;
Jedis jedis = null;
try {
pool = new JedisPool("localhost", 6379);
jedis = pool.getResource();
jedis.mset("abc", "1", "def", "2");

assertEquals("1", jedis.mget("abc").get(0));
assertEquals("2", jedis.mget("def").get(0));
assertEquals(null, jedis.mget("xyz").get(0));
assertNull(jedis.mget("xyz").get(0));
} finally {
if (jedis != null)
pool.returnResource(jedis);
Expand Down Expand Up @@ -98,7 +102,7 @@ public void shouldOverrideDefaultExecutable() throws Exception {
.override(OS.WINDOWS, Architecture.x86, Resources.getResource("redis-server-2.8.19.exe").getFile())
.override(OS.WINDOWS, Architecture.x86_64, Resources.getResource("redis-server-2.8.19.exe").getFile())
.override(OS.MAC_OS_X, Resources.getResource("redis-server-2.8.19").getFile());

redisServer = new RedisServerBuilder()
.redisExecProvider(customProvider)
.build();
Expand All @@ -111,9 +115,40 @@ public void shouldFailWhenBadExecutableGiven() throws Exception {
.override(OS.WINDOWS, Architecture.x86, "some")
.override(OS.WINDOWS, Architecture.x86_64, "some")
.override(OS.MAC_OS_X, "some");

redisServer = new RedisServerBuilder()
.redisExecProvider(buggyProvider)
.build();
}

@Test
public void testAwaitRedisServerReady() throws Exception {
String readyPattern = RedisServer.builder().build().redisReadyPattern();

assertReadyPattern(new BufferedReader(
new InputStreamReader(getClass()
.getClassLoader()
.getResourceAsStream("redis-2.x-standalone-startup-output.txt"))),
readyPattern);

assertReadyPattern(new BufferedReader(
new InputStreamReader(getClass()
.getClassLoader()
.getResourceAsStream("redis-3.x-standalone-startup-output.txt"))),
readyPattern);

assertReadyPattern(new BufferedReader(
new InputStreamReader(getClass()
.getClassLoader()
.getResourceAsStream("redis-4.x-standalone-startup-output.txt"))),
readyPattern);
}

private void assertReadyPattern(BufferedReader reader, String readyPattern) throws IOException {
String outputLine;
do {
outputLine = reader.readLine();
assertNotNull(outputLine);
} while (!outputLine.matches(readyPattern));
}
}
19 changes: 19 additions & 0 deletions src/test/resources/redis-2.x-sentinel-startup-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.19 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 26379
| `-._ `._ / _.-' | PID: 5532
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

[5532] 18 May 18:23:19.755 # Sentinel runid is 19036a5984e785f22fbf267af283649226736049
20 changes: 20 additions & 0 deletions src/test/resources/redis-2.x-standalone-startup-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.19 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 6212
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

[6212] 18 May 18:23:17.244 # Server started, Redis version 2.8.19
[6212] 18 May 18:23:17.244 * The server is now ready to accept connections on port 6379
19 changes: 19 additions & 0 deletions src/test/resources/redis-3.x-sentinel-startup-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8332
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

[8332] 18 May 12:24:04.651 # Sentinel ID is 4bb1b2d80c74deb14e116664261c47b5a9c4b185
20 changes: 20 additions & 0 deletions src/test/resources/redis-3.x-standalone-startup-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1592
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

[1592] 18 May 12:22:56.535 # Server started, Redis version 3.2.100
[1592] 18 May 12:22:56.535 * The server is now ready to accept connections on port 6379
26 changes: 26 additions & 0 deletions src/test/resources/redis-4.x-sentinel-startup-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
2091:X 18 May 18:04:58.961 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2091:X 18 May 18:04:58.962 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=2091, just started
2091:X 18 May 18:04:58.962 # Configuration loaded
2091:X 18 May 18:04:58.963 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
2091:X 18 May 18:04:58.963 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
2091:X 18 May 18:04:58.963 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2091
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

2091:X 18 May 18:04:58.964 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2091:X 18 May 18:04:58.970 # Sentinel ID is 70592a23712d81e2ebc460624a95a0a0fd13a737
29 changes: 29 additions & 0 deletions src/test/resources/redis-4.x-standalone-startup-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
1780:C 18 May 18:03:03.442 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1780:C 18 May 18:03:03.442 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=1780, just started
1780:C 18 May 18:03:03.442 # Configuration loaded
1780:M 18 May 18:03:03.443 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1780:M 18 May 18:03:03.443 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1780:M 18 May 18:03:03.443 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1780
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

1780:M 18 May 18:03:03.444 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1780:M 18 May 18:03:03.445 # Server initialized
1780:M 18 May 18:03:03.445 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1780:M 18 May 18:03:03.445 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1780:M 18 May 18:03:03.445 * Ready to accept connections

0 comments on commit 7201b29

Please sign in to comment.