Tip
|
This module provides integration with ToxiProxy out of the box. ToxiProxy is a great tool for simulating network conditions, meaning that you can test your application’s resiliency. |
<dependency>
<groupId>com.playtika.testcontainers</groupId>
<artifactId>embedded-aerospike</artifactId>
<scope>test</scope>
</dependency>
-
embedded.aerospike.enabled
(true|false, default is 'true')
-
embedded.aerospike.reuseContainer
(true|false, default is 'false')
-
embedded.aerospike.dockerImage
(default is set to 'aerospike/aerospike-server:7.1.0.5')
-
You can pick wanted version on dockerhub
-
-
embedded.aerospike.featureKey
(base64 of a feature-key-file https://aerospike.com/docs/server/operations/configure/feature-key, default is null) is only required for the EE image
-
embedded.aerospike.waitTimeoutInSeconds
(default is 60 seconds)
-
embedded.toxiproxy.proxies.aerospike.enabled
Enables both creation of the container with ToxiProxy TCP proxy and a proxy to theembedded-aerospike
container. -
embedded.aerospike.time-travel.enabled
Enables time travel to clean expired documents by time. Does not work on ARM(mac m1) because of LUA scripts are not supported on ARM.
-
embedded.aerospike.host
-
embedded.aerospike.port
-
embedded.aerospike.namespace
-
embedded.aerospike.toxiproxy.host
-
embedded.aerospike.toxiproxy.port
-
embedded.aerospike.networkAlias
-
embedded.aerospike.internalPort
-
Bean
AerospikeTestOperations aerospikeTestOperations
-
Bean
ToxiproxyContainer.ContainerProxy aerospikeContainerProxy
Create vanilla client pointed directly to Aerospike server using properties provided by embedded-aerospike
:
@Bean(destroyMethod = "close")
public AerospikeClient aerospikeClient(@Value("${embedded.aerospike.host}") String host,
@Value("${embedded.aerospike.port}") int port) {
ClientPolicy clientPolicy = new ClientPolicy();
return new AerospikeClient(clientPolicy, host, port);
}
You can also create client pointed at ToxiProxy TCP proxy:
-
Provide properties:
src/test/resources/bootstrap.properties
embedded.toxiproxy.proxies.aerospike.enabled=true
-
Create vanilla client
@Bean(destroyMethod = "close") public AerospikeClient aerospikeToxicClient(@Value("${embedded.aerospike.toxiproxy.host}") String host, @Value("${embedded.aerospike.toxiproxy.port}") int port) { ClientPolicy clientPolicy = new ClientPolicy(); return new AerospikeClient(clientPolicy, host, port); }
-
Test
@Value("${embedded.aerospike.namespace}") String namespace; @Autowired ToxiproxyContainer.ContainerProxy aerospikeContainerProxy; @Qualifier("aerospikeToxicClient") @Autowired AerospikeClient aerospikeToxicClient; @Test void addsLatency() throws Exception { Policy policy = new Policy(); policy.setTimeout(200); Key key = new Key(namespace, "any", "any"); Record record = aerospikeToxicClient.get(policy, key); aerospikeContainerProxy.toxics() .latency("latency", ToxicDirection.DOWNSTREAM, 1_100) .setJitter(100); assertThatThrownBy(() -> aerospikeToxicClient.get(policy, key)) .isInstanceOf(AerospikeException.Timeout.class); aerospikeContainerProxy.toxics() .get("latency").remove(); record = aerospikeToxicClient.get(policy, key); }
To configure starter for spring-data-aerospike
without ToxiProxy provide the following properties:
src/test/resources/bootstrap.properties
spring.aerospike.hosts=${embedded.aerospike.host}:${embedded.aerospike.port}
spring.data.aerospike.namespace=${embedded.aerospike.namespace}
To configure starter for spring-data-aerospike
with ToxiProxy provide the following properties:
src/test/resources/bootstrap.properties
embedded.toxiproxy.proxies.aerospike.enabled=true
spring.aerospike.hosts=${embedded.aerospike.toxiproxy.host}:${embedded.aerospike.toxiproxy.port}
spring.data.aerospike.namespace=${embedded.aerospike.namespace}
To manipulate ToxiProxy inject the following bean into your tests:
@Autowired
ToxiproxyContainer.ContainerProxy aerospikeContainerProxy;