-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproducer for the Shopify/toxiproxy#254
- Loading branch information
Showing
9 changed files
with
128 additions
and
193 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 |
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 |
---|---|---|
@@ -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> |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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(); | ||
} | ||
|
||
} |