-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove toxiproxy tests from redis and keydb
- Loading branch information
Showing
6 changed files
with
39 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 32 additions & 66 deletions
98
...est/java/com/playtika/testcontainer/keydb/standalone/BaseStandaloneEmbeddedKeyDbTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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 { | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
embedded-keydb/src/test/resources/application-enabled.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
embedded-redis/src/test/resources/application-enabled.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|