Skip to content

Commit

Permalink
Reproducer for the Shopify/toxiproxy#254
Browse files Browse the repository at this point in the history
  • Loading branch information
kwart committed Aug 3, 2022
1 parent 143a28f commit 3495f75
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 193 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/md-to-pdf.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Test application
# Toxiproxy issue #254 reproducer

Java/Maven application playground.

MD Syntax guide - http://markdoc.org/ref/markup
See https://github.com/Shopify/toxiproxy/issues/254
31 changes: 31 additions & 0 deletions hazelcast-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<hazelcast xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config
http://www.hazelcast.com/schema/config/hazelcast-config-5.1.xsd">

<properties>
<property name="hazelcast.merge.next.run.delay.seconds">15</property>
<property name="hazelcast.merge.first.run.delay.seconds">20</property>
<property name="hazelcast.partition.migration.chunks.enabled">false</property>
<property name="hazelcast.heartbeat.failuredetector.type">deadline</property>
<property name="hazelcast.heartbeat.interval.seconds">3</property>
<property name="hazelcast.max.no.heartbeat.seconds">10</property>
</properties>

<network>
<public-address>member-proxy:${proxyPort}</public-address>
<port auto-increment="false">5701</port>
<join>
<auto-detection enabled="false"/>
<tcp-ip enabled="true">
<member-list>
<member>member-proxy:${proxyPort0}</member>
<member>member-proxy:${proxyPort1}</member>
<member>member-proxy:${proxyPort2}</member>
</member-list>
</tcp-ip>
</join>
</network>
</hazelcast>
107 changes: 15 additions & 92 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cz.cacek.test</groupId>
Expand All @@ -15,11 +13,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<exec.mainClass>cz.cacek.test.App</exec.mainClass>
<version.junit>4.13.2</version.junit>
<version.log4j2>2.17.2</version.log4j2>

<version.hazelcast>5.1</version.hazelcast>
</properties>

<build>
Expand All @@ -30,104 +23,34 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${exec.mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${exec.mainClass}</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<!-- <artifactId>hazelcast-enterprise</artifactId> -->
<version>${version.hazelcast}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<scope>provided</scope>
<version>2.0.50.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<scope>provided</scope>
<version>4.1.74.Final</version>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.17.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${version.log4j2}</version>
<groupId>org.testcontainers</groupId>
<artifactId>toxiproxy</artifactId>
<version>1.17.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${version.log4j2}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>snapshot-repository</id>
<name>Maven2 Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>

<repository>
<id>Hazelcast Private Snapshot Repository</id>
<url>https://repository.hazelcast.com/snapshot/</url>
</repository>
<repository>
<id>Hazelcast Private Release Repository</id>
<url>https://repository.hazelcast.com/release/</url>
</repository>
<repository>
<id>Hazelcast Development Releases Repository</id>
<url>https://repository.hazelcast.com/devel/</url>
</repository>
</repositories>
</project>
</project>
27 changes: 0 additions & 27 deletions src/main/java/cz/cacek/test/App.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/resources/log4j2.xml

This file was deleted.

82 changes: 80 additions & 2 deletions src/test/java/cz/cacek/test/AppTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,93 @@
package cz.cacek.test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.ToxiproxyContainer;
import org.testcontainers.utility.DockerImageName;

import com.github.dockerjava.api.model.Network.Ipam;

/**
* A test template.
*/
public class AppTest {
@Rule
public Network network = Network.builder().createNetworkCmdModifier(
cmd -> cmd.withName("toxiproxytest").withIpam(new Ipam().withConfig(new Ipam.Config().withSubnet("172.18.5.0/24"))))
.build();
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder(new File("target"));

@Rule
public ToxiproxyContainer toxiproxy = new ToxiproxyContainer(DockerImageName.parse("ghcr.io/shopify/toxiproxy:2.4.0"))
.withEnv("GODEBUG", "schedtrace=2000")
.withNetwork(network).withNetworkAliases("member-proxy");

protected final List<ToxiproxyContainer.ContainerProxy> memberProxies = new ArrayList<>();

@Test
public void testNullToMain() throws Exception {
App.main(null);
public void test() throws Exception {
System.out.println(getIpAddress(toxiproxy));
memberProxies.add(toxiproxy.getProxy("member0", 5701));
memberProxies.add(toxiproxy.getProxy("member1", 5701));
memberProxies.add(toxiproxy.getProxy("member2", 5701));

System.out.println("starting container");
GenericContainer[] hz = new GenericContainer[] { startHz(0), startHz(1), startHz(2) };

// wait for Hazelcast cluster to establish/join
TimeUnit.SECONDS.sleep(30);
System.out.println("cutting connections");
for (ToxiproxyContainer.ContainerProxy memberProxy: memberProxies) {
memberProxy.setConnectionCut(true);
}
System.out.println("connections were cut");

// wait for Hazelcast split-brain detection
TimeUnit.SECONDS.sleep(60);
for (ToxiproxyContainer.ContainerProxy memberProxy: memberProxies) {
System.out.println("removing a toxic");
memberProxy.setConnectionCut(false);
}

System.out.println("all toxics were removed");
TimeUnit.SECONDS.sleep(60);
}

private GenericContainer startHz(int idx) {
GenericContainer hzc = new GenericContainer("hazelcast/hazelcast:5.1.2-slim")
.withNetwork(network)
.withNetworkAliases("member" + idx)
.withEnv("HZ_PHONE_HOME_ENABLED", "false")
.withEnv("JAVA_OPTS", getJavaOpts(idx))
.withFileSystemBind("hazelcast-config.xml", "/opt/hazelcast/config/hazelcast-docker.xml", BindMode.READ_ONLY);
hzc.start();
return hzc;
}

private String getJavaOpts(int idx) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 3; i++) {
int proxyPort = memberProxies.get(i).getOriginalProxyPort();
sb.append(" -DproxyPort").append(i).append("=").append(proxyPort);
if (idx == i) {
sb.append(" -DproxyPort").append("=").append(proxyPort);
}
}
return sb.toString();
}

private static String getIpAddress(ToxiproxyContainer cont) {
return cont.getContainerInfo().getNetworkSettings().getNetworks().values().iterator().next().getIpAddress();
}

}

0 comments on commit 3495f75

Please sign in to comment.