Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 2.68 KB

File metadata and controls

70 lines (50 loc) · 2.68 KB

embedded-toxiproxy

Convenient and simple to use wrapper for ToxiProxy:

Maven dependency

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

Consumes (via bootstrap.properties)

  • embedded.toxiproxy.enabled (true|false, default is 'false') Enables ToxiProxy container.

  • embedded.toxiproxy.proxies.{module}.enabled (true|false, default is 'false') Enables ToxiProxy proxy for specific module.

  • embedded.toxiproxy.reuseContainer (true|false, default is 'false')

  • embedded.toxiproxy.dockerImage (default is set to 'ghcr.io/shopify/toxiproxy:2.9.0')

  • embedded.toxiproxy.waitTimeoutInSeconds (default is 60 seconds)

Tip
See other common container properties in com.playtika.testcontainer.common.properties.CommonContainerProperties.

Produces

  • embedded.toxiproxy.host

  • embedded.toxiproxy.controlPort

  • embedded.toxiproxy.networkAlias

Example

By default ToxiProxy container is disabled. There are two ways to enable it:

  1. Add embedded.toxiproxy.enabled=true to your src/test/resources/bootstrap.properties. Enables creation of the container with ToxiProxy TCP proxy. Next step is to [_create_vanilla_proxy].

  2. Add embedded.toxiproxy.proxies.{module}.enabled to your src/test/resources/bootstrap.properties. Enables both creation of the container with ToxiProxy TCP proxy and a proxy to your {module}. Please check that this module has already built-in support for ToxiProxy, otherwise you will need to create proxy manually. For the modules that have built-in proxy creation please refer to the documentation of the module.

Create vanilla proxy
@Value("${embedded.toxiproxy.host}")
String host;

@Value("${embedded.toxiproxy.controlPort}")
int controlPort;

ToxiproxyClient toxiproxyClient = new ToxiproxyClient(host, controlPort);
Proxy proxy = toxiproxyClient.createProxy(
                                          "my-service-proxy", // Name of the proxy, any that you like
                                          // NOTE: {toxi-proxy-avail-port} must be in the range [8666; 8666 + 31] (these ports are exposed by default).
                                          "0.0.0.0:{toxi-proxy-avail-port}", // Toxiproxy will listen on this address.
                                          "{my-service-host}:{my-service-port}"); // Your service is exposed at this address

proxy.toxics()
        .latency("latency", ToxicDirection.DOWNSTREAM, 1_100)
        .setJitter(100);