From f215d686d1c174bf083f9d215bb9f250902e9074 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolchik Date: Fri, 18 May 2018 18:31:03 +0300 Subject: [PATCH] Tests to check REDIS_READY_PATTERN for Redis version 2.x, 3.x, 4.x were added --- .../redis/embedded/RedisSentinelTest.java | 37 +++++++++++- .../java/redis/embedded/RedisServerTest.java | 57 +++++++++++++++---- .../redis-2.x-sentinel-startup-output.txt | 19 +++++++ .../redis-2.x-standalone-startup-output.txt | 20 +++++++ .../redis-3.x-sentinel-startup-output.txt | 19 +++++++ .../redis-3.x-standalone-startup-output.txt | 20 +++++++ .../redis-4.x-sentinel-startup-output.txt | 26 +++++++++ .../redis-4.x-standalone-startup-output.txt | 29 ++++++++++ 8 files changed, 214 insertions(+), 13 deletions(-) create mode 100644 src/test/resources/redis-2.x-sentinel-startup-output.txt create mode 100644 src/test/resources/redis-2.x-standalone-startup-output.txt create mode 100644 src/test/resources/redis-3.x-sentinel-startup-output.txt create mode 100644 src/test/resources/redis-3.x-standalone-startup-output.txt create mode 100644 src/test/resources/redis-4.x-sentinel-startup-output.txt create mode 100644 src/test/resources/redis-4.x-standalone-startup-output.txt diff --git a/src/test/java/redis/embedded/RedisSentinelTest.java b/src/test/java/redis/embedded/RedisSentinelTest.java index 5dbc2204..29bfe0de 100644 --- a/src/test/java/redis/embedded/RedisSentinelTest.java +++ b/src/test/java/redis/embedded/RedisSentinelTest.java @@ -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; @@ -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); @@ -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)); + } } \ No newline at end of file diff --git a/src/test/java/redis/embedded/RedisServerTest.java b/src/test/java/redis/embedded/RedisServerTest.java index e85cfaff..5effda49 100644 --- a/src/test/java/redis/embedded/RedisServerTest.java +++ b/src/test/java/redis/embedded/RedisServerTest.java @@ -8,12 +8,16 @@ 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); @@ -21,7 +25,7 @@ public void testSimpleRun() throws Exception { Thread.sleep(1000L); redisServer.stop(); } - + @Test(expected = RuntimeException.class) public void shouldNotAllowMultipleRunsWithoutStop() throws Exception { try { @@ -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); @@ -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(); @@ -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)); + } } diff --git a/src/test/resources/redis-2.x-sentinel-startup-output.txt b/src/test/resources/redis-2.x-sentinel-startup-output.txt new file mode 100644 index 00000000..8c51b452 --- /dev/null +++ b/src/test/resources/redis-2.x-sentinel-startup-output.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/redis-2.x-standalone-startup-output.txt b/src/test/resources/redis-2.x-standalone-startup-output.txt new file mode 100644 index 00000000..1591e75d --- /dev/null +++ b/src/test/resources/redis-2.x-standalone-startup-output.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/redis-3.x-sentinel-startup-output.txt b/src/test/resources/redis-3.x-sentinel-startup-output.txt new file mode 100644 index 00000000..151f7fd1 --- /dev/null +++ b/src/test/resources/redis-3.x-sentinel-startup-output.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/redis-3.x-standalone-startup-output.txt b/src/test/resources/redis-3.x-standalone-startup-output.txt new file mode 100644 index 00000000..2a6f4d28 --- /dev/null +++ b/src/test/resources/redis-3.x-standalone-startup-output.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/redis-4.x-sentinel-startup-output.txt b/src/test/resources/redis-4.x-sentinel-startup-output.txt new file mode 100644 index 00000000..71580d7f --- /dev/null +++ b/src/test/resources/redis-4.x-sentinel-startup-output.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/redis-4.x-standalone-startup-output.txt b/src/test/resources/redis-4.x-standalone-startup-output.txt new file mode 100644 index 00000000..f1f64e26 --- /dev/null +++ b/src/test/resources/redis-4.x-standalone-startup-output.txt @@ -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 \ No newline at end of file