diff --git a/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/clustered/BaseClusterEmbeddedKeyDbTest.java b/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/clustered/BaseClusterEmbeddedKeyDbTest.java index 27c4ad1be..4a9062d53 100644 --- a/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/clustered/BaseClusterEmbeddedKeyDbTest.java +++ b/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/clustered/BaseClusterEmbeddedKeyDbTest.java @@ -20,8 +20,7 @@ @SpringBootTest( classes = BaseClusterEmbeddedKeyDbTest.TestConfiguration.class, properties = { - "embedded.keydb.clustered=true", - "embedded.toxiproxy.proxies.keydb.enabled=true" + "embedded.keydb.clustered=true" } ) abstract class BaseClusterEmbeddedKeyDbTest extends BaseEmbeddedKeyDbTest { diff --git a/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/standalone/BaseStandaloneEmbeddedKeyDbTest.java b/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/standalone/BaseStandaloneEmbeddedKeyDbTest.java index dc2409d72..dae14abe1 100644 --- a/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/standalone/BaseStandaloneEmbeddedKeyDbTest.java +++ b/embedded-keydb/src/test/java/com/playtika/testcontainer/keydb/standalone/BaseStandaloneEmbeddedKeyDbTest.java @@ -1,87 +1,53 @@ package com.playtika.testcontainer.keydb.standalone; import com.playtika.testcontainer.keydb.BaseEmbeddedKeyDbTest; -import eu.rekawek.toxiproxy.model.ToxicDirection; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactoryUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.testcontainers.containers.ToxiproxyContainer; - -import java.util.concurrent.Callable; import static com.playtika.testcontainer.keydb.KeyDbProperties.BEAN_NAME_EMBEDDED_KEYDB; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest( - classes = BaseStandaloneEmbeddedKeyDbTest.TestConfiguration.class, - properties = { - "embedded.toxiproxy.proxies.keydb.enabled=true" - } + classes = BaseStandaloneEmbeddedKeyDbTest.TestConfiguration.class, + properties = { + "embedded.toxiproxy.proxies.keydb.enabled=false" + } ) abstract class BaseStandaloneEmbeddedKeyDbTest extends BaseEmbeddedKeyDbTest { - @Autowired - ToxiproxyContainer.ContainerProxy keyDbContainerProxy; - - @Test - public void shouldEmulateLatency() throws Exception { - ValueOperations ops = template.opsForValue(); - - assertThat(durationOf(() -> ops.get("any"))) - .isLessThan(100L); - - keyDbContainerProxy.toxics().latency("latency", ToxicDirection.UPSTREAM, 1000); - - assertThat(durationOf(() -> ops.get("any"))) - .isGreaterThanOrEqualTo(1000L); - - keyDbContainerProxy.toxics() - .get("latency").remove(); - - assertThat(durationOf(() -> ops.get("any"))) - .isLessThan(100L); - } - - @Test - public void shouldSetupDependsOnForAllClients() throws Exception { - String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, RedisConnectionFactory.class); - assertThat(beanNamesForType) - .as("RedisConnectionFactory should be present") - .hasSize(1) - .contains("redisConnectionFactory"); - asList(beanNamesForType).forEach(this::hasDependsOn); - - beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, RedisTemplate.class); - assertThat(beanNamesForType) - .as("redisTemplates should be present") - .hasSize(2) - .contains("redisTemplate", "stringRedisTemplate"); - asList(beanNamesForType).forEach(this::hasDependsOn); - } - - private void hasDependsOn(String beanName) { - assertThat(beanFactory.getBeanDefinition(beanName).getDependsOn()) - .isNotNull() - .isNotEmpty() - .contains(BEAN_NAME_EMBEDDED_KEYDB); - } - - private static long durationOf(Callable op) throws Exception { - long start = System.currentTimeMillis(); - op.call(); - return System.currentTimeMillis() - start; - } - - @EnableAutoConfiguration - @Configuration - static class TestConfiguration { - } + @Test + public void shouldSetupDependsOnForAllClients() throws Exception { + String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, RedisConnectionFactory.class); + assertThat(beanNamesForType) + .as("RedisConnectionFactory should be present") + .hasSize(1) + .contains("redisConnectionFactory"); + asList(beanNamesForType).forEach(this::hasDependsOn); + + beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, RedisTemplate.class); + assertThat(beanNamesForType) + .as("redisTemplates should be present") + .hasSize(2) + .contains("redisTemplate", "stringRedisTemplate"); + asList(beanNamesForType).forEach(this::hasDependsOn); + } + + private void hasDependsOn(String beanName) { + assertThat(beanFactory.getBeanDefinition(beanName).getDependsOn()) + .isNotNull() + .isNotEmpty() + .contains(BEAN_NAME_EMBEDDED_KEYDB); + } + + @EnableAutoConfiguration + @Configuration + static class TestConfiguration { + } } diff --git a/embedded-keydb/src/test/resources/application-enabled.properties b/embedded-keydb/src/test/resources/application-enabled.properties index 9e83ac736..ab0420a37 100644 --- a/embedded-keydb/src/test/resources/application-enabled.properties +++ b/embedded-keydb/src/test/resources/application-enabled.properties @@ -1,5 +1,5 @@ -spring.data.redis.host=${embedded.keydb.toxiproxy.host} -spring.data.redis.port=${embedded.keydb.toxiproxy.port} +spring.data.redis.host=${embedded.keydb.host} +spring.data.redis.port=${embedded.keydb.port} spring.data.redis.timeout=2500 diff --git a/embedded-redis/src/test/java/com/playtika/testcontainer/redis/clustered/BaseClusterEmbeddedRedisTest.java b/embedded-redis/src/test/java/com/playtika/testcontainer/redis/clustered/BaseClusterEmbeddedRedisTest.java index 09a58e6e2..e08c5089d 100644 --- a/embedded-redis/src/test/java/com/playtika/testcontainer/redis/clustered/BaseClusterEmbeddedRedisTest.java +++ b/embedded-redis/src/test/java/com/playtika/testcontainer/redis/clustered/BaseClusterEmbeddedRedisTest.java @@ -20,8 +20,7 @@ @SpringBootTest( classes = BaseClusterEmbeddedRedisTest.TestConfiguration.class, properties = { - "embedded.redis.clustered=true", - "embedded.toxiproxy.proxies.redis.enabled=true" + "embedded.redis.clustered=true" } ) public abstract class BaseClusterEmbeddedRedisTest extends BaseEmbeddedRedisTest { diff --git a/embedded-redis/src/test/java/com/playtika/testcontainer/redis/standalone/BaseStandaloneEmbeddedRedisTest.java b/embedded-redis/src/test/java/com/playtika/testcontainer/redis/standalone/BaseStandaloneEmbeddedRedisTest.java index 192e77da4..2ca440549 100644 --- a/embedded-redis/src/test/java/com/playtika/testcontainer/redis/standalone/BaseStandaloneEmbeddedRedisTest.java +++ b/embedded-redis/src/test/java/com/playtika/testcontainer/redis/standalone/BaseStandaloneEmbeddedRedisTest.java @@ -1,54 +1,23 @@ package com.playtika.testcontainer.redis.standalone; import com.playtika.testcontainer.redis.BaseEmbeddedRedisTest; -import eu.rekawek.toxiproxy.model.ToxicDirection; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactoryUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.testcontainers.containers.ToxiproxyContainer; - -import java.util.concurrent.Callable; import static com.playtika.testcontainer.redis.RedisProperties.BEAN_NAME_EMBEDDED_REDIS; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest( - classes = BaseStandaloneEmbeddedRedisTest.TestConfiguration.class, - properties = { - "embedded.toxiproxy.proxies.redis.enabled=true" - } + classes = BaseStandaloneEmbeddedRedisTest.TestConfiguration.class ) public abstract class BaseStandaloneEmbeddedRedisTest extends BaseEmbeddedRedisTest { - @Autowired - ToxiproxyContainer.ContainerProxy redisContainerProxy; - - @Test - public void shouldEmulateLatency() throws Exception { - ValueOperations ops = template.opsForValue(); - - assertThat(durationOf(() -> ops.get("any"))) - .isLessThan(100L); - - redisContainerProxy.toxics().latency("latency", ToxicDirection.UPSTREAM, 1000); - - assertThat(durationOf(() -> ops.get("any"))) - .isGreaterThanOrEqualTo(1000L); - - redisContainerProxy.toxics() - .get("latency").remove(); - - assertThat(durationOf(() -> ops.get("any"))) - .isLessThan(100L); - } - @Test public void shouldSetupDependsOnForAllClients() throws Exception { String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, RedisConnectionFactory.class); @@ -73,12 +42,6 @@ private void hasDependsOn(String beanName) { .contains(BEAN_NAME_EMBEDDED_REDIS); } - private static long durationOf(Callable op) throws Exception { - long start = System.currentTimeMillis(); - op.call(); - return System.currentTimeMillis() - start; - } - @EnableAutoConfiguration @Configuration static class TestConfiguration { diff --git a/embedded-redis/src/test/resources/application-enabled.properties b/embedded-redis/src/test/resources/application-enabled.properties index ea5770541..e56bb5506 100644 --- a/embedded-redis/src/test/resources/application-enabled.properties +++ b/embedded-redis/src/test/resources/application-enabled.properties @@ -1,5 +1,5 @@ -spring.data.redis.host=${embedded.redis.toxiproxy.host} -spring.data.redis.port=${embedded.redis.toxiproxy.port} +spring.data.redis.host=${embedded.redis.host} +spring.data.redis.port=${embedded.redis.port} spring.data.redis.timeout=2500