From 3d73ba4f8ea21171e0fe4c2c05dd11a8959386d7 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 30 Oct 2019 00:44:25 +0330 Subject: [PATCH 1/4] Fixed the Max Memory Limit for the Embedded Redis Server --- .../redis/template/RedisKeyCommandsIntegrationTest.java | 2 +- .../redis/template/RedisTemplateListOpsIntegrationTest.java | 2 +- .../redis/template/RedisTemplateValueOpsIntegrationTest.java | 2 +- .../spring/data/redis/RedisMessageListenerIntegrationTest.java | 2 +- .../data/redis/repo/StudentRepositoryIntegrationTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisKeyCommandsIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisKeyCommandsIntegrationTest.java index 1333f94653..af790c99b7 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisKeyCommandsIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisKeyCommandsIntegrationTest.java @@ -38,7 +38,7 @@ public class RedisKeyCommandsIntegrationTest { @BeforeClass public static void startRedisServer() throws IOException { - redisServer = new RedisServerBuilder().port(6379).setting("maxheap 256M").build(); + redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build(); redisServer.start(); } diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateListOpsIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateListOpsIntegrationTest.java index 88c4fa6eed..58846d7c27 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateListOpsIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateListOpsIntegrationTest.java @@ -36,7 +36,7 @@ public class RedisTemplateListOpsIntegrationTest { @BeforeClass public static void startRedisServer() throws IOException { - redisServer = new RedisServerBuilder().port(6379).setting("maxheap 128M").build(); + redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build(); redisServer.start(); } diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateValueOpsIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateValueOpsIntegrationTest.java index afa5267582..5d12f90f34 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateValueOpsIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateValueOpsIntegrationTest.java @@ -38,7 +38,7 @@ public class RedisTemplateValueOpsIntegrationTest { @BeforeClass public static void startRedisServer() throws IOException { - redisServer = new RedisServerBuilder().port(6379).setting("maxheap 256M").build(); + redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build(); redisServer.start(); } diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java index 1c69b63c09..b2862e26c3 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java @@ -33,7 +33,7 @@ public class RedisMessageListenerIntegrationTest { @BeforeClass public static void startRedisServer() throws IOException { - redisServer = new RedisServerBuilder().port(6379).setting("maxheap 256M").build(); + redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build(); redisServer.start(); } diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java index b1a36475c3..24191a42b9 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java @@ -34,7 +34,7 @@ public class StudentRepositoryIntegrationTest { @BeforeClass public static void startRedisServer() throws IOException { - redisServer = new RedisServerBuilder().port(6379).setting("maxheap 128M").build(); + redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build(); redisServer.start(); } From ff853f6be4f279d12a8b16ecb6fcecd1875eb15e Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 30 Oct 2019 08:08:48 +0330 Subject: [PATCH 2/4] Wait a little bit longer. --- .../spring/data/redis/RedisMessageListenerIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java index b2862e26c3..6f9e6a8757 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java @@ -46,7 +46,7 @@ public class RedisMessageListenerIntegrationTest { public void testOnMessage() throws Exception { String message = "Message " + UUID.randomUUID(); redisMessagePublisher.publish(message); - Thread.sleep(100); + Thread.sleep(1000); assertTrue(RedisMessageSubscriber.messageList.get(0).contains(message)); } } \ No newline at end of file From 7e5dfdcf45e837247ea21cdfb465edbce1749237 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 31 Oct 2019 00:48:17 +0330 Subject: [PATCH 3/4] Disabling the Fork Option Each test setups a Redis server before test class and tears it down after them. Since each Redis server listens on port 6379, we can't let them to listen to the same port with parallel options. --- persistence-modules/spring-data-redis/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-redis/pom.xml b/persistence-modules/spring-data-redis/pom.xml index 4ae8ac0a87..cd8c729844 100644 --- a/persistence-modules/spring-data-redis/pom.xml +++ b/persistence-modules/spring-data-redis/pom.xml @@ -87,7 +87,8 @@ ${maven-surefire-plugin.version} true - true + false + 0 -Xmx1024m From 5be2b72eff7d670cd4b5a59bcfad2b5b2a0fe4d0 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 31 Oct 2019 00:49:42 +0330 Subject: [PATCH 4/4] Fixed failing connection. --- .../SpringContextIntegrationTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-redis/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/org/baeldung/SpringContextIntegrationTest.java index e093892365..f5c8177cbe 100644 --- a/persistence-modules/spring-data-redis/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/org/baeldung/SpringContextIntegrationTest.java @@ -1,16 +1,35 @@ package org.baeldung; +import com.baeldung.spring.data.redis.config.RedisConfig; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import redis.embedded.RedisServerBuilder; -import com.baeldung.spring.data.redis.config.RedisConfig; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS; @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext(classMode = BEFORE_CLASS) @ContextConfiguration(classes = RedisConfig.class) public class SpringContextIntegrationTest { + private static redis.embedded.RedisServer redisServer; + + @BeforeClass + public static void startRedisServer() { + redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build(); + redisServer.start(); + } + + @AfterClass + public static void stopRedisServer() { + redisServer.stop(); + } + @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { }