Skip to content

Latest commit

 

History

History
154 lines (121 loc) · 4.87 KB

File metadata and controls

154 lines (121 loc) · 4.87 KB

embedded-aerospike

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.

Maven dependency

pom.xml
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-aerospike</artifactId>
    <scope>test</scope>
</dependency>

Consumes (via bootstrap.properties)

  • 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.2.0.4')

  • 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 the embedded-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.

  • aerospike client library

Produces

  • 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

Example

Create vanilla client

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);
}
Create vanilla client with ToxiProxy

You can also create client pointed at ToxiProxy TCP proxy:

  1. Provide properties:

    src/test/resources/bootstrap.properties
    embedded.toxiproxy.proxies.aerospike.enabled=true
  2. 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);
    }
  3. 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);
    
        }
Setup for spring-data-aerospike-starter

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;