serviceLoaderInst;
21 |
22 | public void registerToxiProxyProxies(@Observes AfterAutoStart event, CubeRegistry registry) {
23 | Proxy proxy = proxyInst.get();
24 | if (proxy != null) {
25 | Cube> cube = registry.getCube(proxy.getName());
26 |
27 | final ProxyManager proxyManager = serviceLoaderInst.get().onlyOne(ProxyManager.class);
28 | if (cube != null) {
29 | proxyManager.proxyStarted(cube);
30 | }
31 |
32 | proxyManager.populateProxies();
33 | }
34 | }
35 |
36 | /**
37 | * public void registerProxy(AfterStart event, CubeRegistry registry) {
38 | *
39 | * Proxy proxy = proxyInst.get();
40 | * Cube> cube = registry.getCube(event.getCubeId());
41 | * if(cube != null && isNotProxyCube(cube, proxy)) {
42 | * serviceLoaderInst.get().onlyOne(ProxyManager.class).cubeStarted(cube);
43 | * }
44 | * }
45 | *
46 | * public void createProxyClient(AfterStart event, CubeRegistry registry) {
47 | *
48 | * Proxy proxy = proxyInst.get();
49 | *
50 | * Cube> cube = registry.getCube(event.getCubeId());
51 | * if(cube != null && isProxyCube(cube, proxy)) {
52 | * serviceLoaderInst.get().onlyOne(ProxyManager.class).proxyStarted(cube);
53 | * }
54 | *
55 | * }
56 | **/
57 |
58 | public void unregisterProxy(@Observes AfterStop event, CubeRegistry registry) {
59 | Proxy proxy = proxyInst.get();
60 | if (proxy != null) {
61 | Cube> cube = registry.getCube(event.getCubeId());
62 | if (cube != null && isNotProxyCube(cube, proxy)) {
63 | serviceLoaderInst.get().onlyOne(ProxyManager.class).cubeStopped(cube);
64 | }
65 | }
66 | }
67 |
68 | private boolean isNotProxyCube(Cube> cube, Proxy proxy) {
69 | return !isProxyCube(cube, proxy);
70 | }
71 |
72 | private boolean isProxyCube(Cube> cube, Proxy proxy) {
73 | return proxy.getName().equals(cube.getId());
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/core/src/test/java/org/arquillian/cube/q/InstallProxyTestCase.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q;
2 |
3 | import org.arquillian.cube.docker.impl.client.CubeDockerConfiguration;
4 | import org.arquillian.cube.docker.impl.client.config.DockerCompositions;
5 | import org.arquillian.cube.q.core.InstallProxy;
6 | import org.arquillian.cube.q.spi.Proxy;
7 | import org.arquillian.cube.q.spi.ProxyManager;
8 | import org.jboss.arquillian.config.descriptor.api.ArquillianDescriptor;
9 | import org.jboss.arquillian.core.api.annotation.ApplicationScoped;
10 | import org.jboss.arquillian.core.spi.ServiceLoader;
11 | import org.jboss.arquillian.core.test.AbstractManagerTestBase;
12 | import org.junit.Assert;
13 | import org.junit.Before;
14 | import org.junit.Test;
15 | import org.junit.runner.RunWith;
16 | import org.mockito.Mock;
17 | import org.mockito.Mockito;
18 | import org.mockito.runners.MockitoJUnitRunner;
19 |
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | @RunWith(MockitoJUnitRunner.class)
25 | public class InstallProxyTestCase extends AbstractManagerTestBase {
26 |
27 | private static final String CONTENT =
28 | "a:\n" +
29 | " image: a/a\n" +
30 | " portBindings: [8089/tcp]\n" +
31 | " links:\n" +
32 | " - b:b\n" +
33 | "b:\n" +
34 | " image: b/b\n" +
35 | " exposedPorts: [2112/tcp]\n";
36 |
37 | @Mock
38 | private ArquillianDescriptor descriptor;
39 |
40 | @Mock
41 | private ServiceLoader serviceLoader;
42 |
43 | @Mock
44 | private ProxyManager proxyManager;
45 |
46 | @Override
47 | protected void addExtensions(List> extensions) {
48 | extensions.add(InstallProxy.class);
49 | }
50 |
51 | @Before
52 | public void setup() {
53 |
54 | Proxy p = new Proxy.Builder().build();
55 |
56 | bind(ApplicationScoped.class, ArquillianDescriptor.class, descriptor);
57 | bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
58 |
59 | Mockito.when(serviceLoader.onlyOne(ProxyManager.class)).thenReturn(proxyManager);
60 | Mockito.when(proxyManager.install(Mockito.any(DockerCompositions.class))).thenReturn(p);
61 | }
62 |
63 | @Test
64 | public void shouldInstallProxy() throws Exception {
65 | CubeDockerConfiguration config = createConfig(CONTENT);
66 | fire(config);
67 |
68 | DockerCompositions cubes = config.getDockerContainersContent();
69 | Assert.assertEquals(3, cubes.getContainerIds().size());
70 |
71 | System.out.println(config.toString());
72 | }
73 |
74 | private CubeDockerConfiguration createConfig(String content) {
75 | Map parameters = new HashMap<>();
76 |
77 | parameters.put("serverVersion", "1.13");
78 | parameters.put("serverUri", "http://localhost:25123");
79 | parameters.put("dockerContainers", content);
80 |
81 | return CubeDockerConfiguration.fromMap(parameters, null);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/simianarmy/src/main/java/org/arquillian/cube/q/simianarmy/QSimianArmyAction.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.simianarmy;
2 |
3 | import org.arquillian.cube.q.api.OperativeSystemChaos;
4 | import org.arquillian.cube.q.simianarmy.client.BlockPortSimianArmyChaosScript;
5 | import org.arquillian.cube.q.simianarmy.client.BurnCpuSimianArmyChaosScript;
6 | import org.arquillian.cube.q.simianarmy.client.BurnIoSimianArmyChaosScript;
7 | import org.arquillian.cube.q.simianarmy.client.FillDiskSimianArmyChaosScript;
8 | import org.arquillian.cube.q.simianarmy.client.KillProcessSimianArmyChaosScript;
9 | import org.arquillian.cube.q.simianarmy.client.NullRouteSimianArmyChaosScript;
10 | import org.arquillian.cube.q.simianarmy.client.SimianArmyScriptChaos;
11 | import org.arquillian.cube.spi.Cube;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | public class QSimianArmyAction implements OperativeSystemChaos.Action {
17 |
18 | private Cube cube;
19 | private List scripts = new ArrayList<>();
20 |
21 | public QSimianArmyAction(Cube cube) {
22 | this.cube = cube;
23 | }
24 |
25 | @Override
26 | public OperativeSystemChaos.Action burnCpu(OperativeSystemChaos.NumberCpuType numberCpu) {
27 | scripts.add(new BurnCpuSimianArmyChaosScript(numberCpu.getValue()));
28 | return this;
29 | }
30 |
31 | @Override
32 | public OperativeSystemChaos.Action burnIo() {
33 | scripts.add(new BurnIoSimianArmyChaosScript());
34 | return this;
35 | }
36 |
37 | @Override
38 | public OperativeSystemChaos.Action failDns() {
39 | return blockPort(OperativeSystemChaos.PortSizeType.port(53));
40 | }
41 |
42 | @Override
43 | public OperativeSystemChaos.Action fillDisk(OperativeSystemChaos.SizeType size) {
44 | scripts.add(new FillDiskSimianArmyChaosScript(size.getValue()));
45 | return this;
46 | }
47 |
48 | @Override
49 | public OperativeSystemChaos.Action killProcess(String processName) {
50 | scripts.add(new KillProcessSimianArmyChaosScript(processName));
51 | return this;
52 | }
53 |
54 | @Override
55 | public OperativeSystemChaos.Action nullRoute() {
56 | scripts.add(new NullRouteSimianArmyChaosScript());
57 | return this;
58 | }
59 |
60 | @Override
61 | public OperativeSystemChaos.Action blockPort(OperativeSystemChaos.PortSizeType port) {
62 | scripts.add(new BlockPortSimianArmyChaosScript(port.getValue()));
63 | return this;
64 | }
65 |
66 | @Override
67 | public void exec() throws Exception {
68 | executeScripts();
69 | }
70 |
71 | @Override
72 | public void exec(Perform perform) throws Exception {
73 | try {
74 | executeScripts();
75 | perform.execute();
76 | } finally {
77 | killDDProcess();
78 | }
79 | }
80 |
81 | @Override
82 | public void exec(RunCondition runCondition, Perform perform) throws Exception {
83 | try {
84 | executeScripts();
85 | while (runCondition.isExecutable()) {
86 | perform.execute();
87 | }
88 | } finally {
89 | killDDProcess();
90 | }
91 | }
92 |
93 | private void killDDProcess() {
94 | new KillProcessSimianArmyChaosScript("dd").apply(cube);
95 | }
96 |
97 | private void executeScripts() {
98 | for (SimianArmyScriptChaos script : this.scripts) {
99 | script.apply(this.cube);
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/api/src/main/java/org/arquillian/cube/q/api/OperativeSystemChaos.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.api;
2 |
3 | /**
4 | * Interface for executing chaos at operative system level.
5 | */
6 | public interface OperativeSystemChaos {
7 |
8 | /**
9 | * Method to set in which container you want to run the process.
10 | *
11 | * @param containerId
12 | * of container.
13 | *
14 | * @return Action element to set the chaos.
15 | */
16 | Action on(String containerId);
17 |
18 | /**
19 | * Interface that abstracts on how operative system chaos is implemented
20 | */
21 | interface Action extends Q {
22 |
23 | /**
24 | * Burn CPU setting CPU to 100%
25 | *
26 | * @param numberCpu
27 | * to run this process.
28 | *
29 | * @return this element.
30 | */
31 | Action burnCpu(NumberCpuType numberCpu);
32 |
33 | /**
34 | * Burn IO channels
35 | *
36 | * @return this element.
37 | */
38 | Action burnIo();
39 |
40 | /**
41 | * Provoke a fail in DNS server (blocking port 53)
42 | *
43 | * @return this element.
44 | */
45 | Action failDns();
46 |
47 | /**
48 | * Fill the disk with trash
49 | *
50 | * @param size
51 | * of the trash
52 | *
53 | * @return this element.
54 | */
55 | Action fillDisk(SizeType size);
56 |
57 | /**
58 | * Kills process in specified interval
59 | *
60 | * @param processName
61 | * to kill
62 | *
63 | * @return this element.
64 | */
65 | Action killProcess(String processName);
66 |
67 | /**
68 | * Set null route
69 | *
70 | * @return this element.
71 | */
72 | Action nullRoute();
73 |
74 | /**
75 | * Blocks a port
76 | *
77 | * @param port
78 | * port(s) to block
79 | *
80 | * @return this element.
81 | */
82 | Action blockPort(PortSizeType port);
83 | }
84 |
85 | final class NumberCpuType extends Q.IntegerType {
86 |
87 | protected NumberCpuType(int value) {
88 | super(value);
89 | }
90 |
91 | public static NumberCpuType cpus(int cpu) {
92 | return new NumberCpuType(cpu);
93 | }
94 |
95 | public static NumberCpuType singleCpu() {
96 | return new NumberCpuType(1);
97 | }
98 | }
99 |
100 | final class SizeType extends Q.LongType {
101 |
102 | protected SizeType(long value) {
103 | super(value);
104 | }
105 |
106 | /**
107 | * Default size of 65GB
108 | *
109 | * @return Size element.
110 | */
111 | public static SizeType defaultSize() {
112 | return new SizeType(65536);
113 | }
114 |
115 | public static SizeType sizeInMegas(long size) {
116 | return new SizeType(size);
117 | }
118 | }
119 |
120 | final class PortSizeType extends Q.ArrayType {
121 |
122 | protected PortSizeType(Integer[] value) {
123 | super(value);
124 | }
125 |
126 | public static PortSizeType port(Integer port) {
127 | return new PortSizeType(new Integer[] {port});
128 | }
129 |
130 | public static PortSizeType ports(Integer... ports) {
131 | return new PortSizeType(ports);
132 | }
133 |
134 | public static PortSizeType portRange(int start, int stop) {
135 | int totalNumber = (stop - start) + 1;
136 | Integer[] ports = new Integer[totalNumber];
137 |
138 | int currentPort = start;
139 | for (int i = 0; i < ports.length; i++) {
140 | ports[i] = currentPort;
141 | currentPort++;
142 | }
143 |
144 | return new PortSizeType(ports);
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/simianarmy/src/test/java/org/arquillia/cube/q/simianarmy/client/SimianArmyScriptChaosTest.java:
--------------------------------------------------------------------------------
1 | package org.arquillia.cube.q.simianarmy.client;
2 |
3 | import org.arquillian.cube.q.simianarmy.client.BlockPortSimianArmyChaosScript;
4 | import org.arquillian.cube.q.simianarmy.client.BurnCpuSimianArmyChaosScript;
5 | import org.arquillian.cube.q.simianarmy.client.BurnIoSimianArmyChaosScript;
6 | import org.arquillian.cube.q.simianarmy.client.FillDiskSimianArmyChaosScript;
7 | import org.arquillian.cube.q.simianarmy.client.KillProcessSimianArmyChaosScript;
8 | import org.arquillian.cube.q.simianarmy.client.NullRouteSimianArmyChaosScript;
9 | import org.arquillian.cube.spi.Cube;
10 | import org.arquillian.cube.spi.metadata.CanExecuteProcessInContainer;
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.mockito.Mock;
15 | import org.mockito.runners.MockitoJUnitRunner;
16 |
17 | import static org.mockito.Mockito.times;
18 | import static org.mockito.Mockito.verify;
19 | import static org.mockito.Mockito.when;
20 |
21 | @RunWith(MockitoJUnitRunner.class)
22 | public class SimianArmyScriptChaosTest {
23 |
24 | @Mock
25 | Cube cube;
26 |
27 | @Mock
28 | CanExecuteProcessInContainer canExecuteProcessInContainer;
29 |
30 | @Before
31 | public void configureMocks() {
32 | when(cube.hasMetadata(CanExecuteProcessInContainer.class)).thenReturn(true);
33 | when(cube.getMetadata(CanExecuteProcessInContainer.class)).thenReturn(canExecuteProcessInContainer);
34 | }
35 |
36 | @Test
37 | public void shouldBlockPort() {
38 | final BlockPortSimianArmyChaosScript blockPortSimianArmyChaosScript =
39 | new BlockPortSimianArmyChaosScript(new Integer[] {80, 8080});
40 | blockPortSimianArmyChaosScript.apply(cube);
41 |
42 | verify(canExecuteProcessInContainer).exec("iptables", "-A", "INPUT", "-p", "tcp", "-m", "tcp", "--dport", "80",
43 | "-j", "DROP");
44 | verify(canExecuteProcessInContainer).exec("iptables", "-A", "INPUT", "-p", "udp", "-m", "udp", "--dport", "80",
45 | "-j", "DROP");
46 | verify(canExecuteProcessInContainer).exec("iptables", "-A", "INPUT", "-p", "tcp", "-m", "tcp", "--dport", "8080",
47 | "-j", "DROP");
48 | verify(canExecuteProcessInContainer).exec("iptables", "-A", "INPUT", "-p", "udp", "-m", "udp", "--dport", "8080",
49 | "-j", "DROP");
50 | }
51 |
52 | @Test
53 | public void shouldBurnCpu() {
54 | final BurnCpuSimianArmyChaosScript burnCpuSimianArmyChaosScript = new BurnCpuSimianArmyChaosScript(2);
55 | burnCpuSimianArmyChaosScript.apply(cube);
56 |
57 | verify(canExecuteProcessInContainer, times(2)).exec("dd", "if=/dev/zero", "of=/dev/null");
58 | }
59 |
60 | @Test
61 | public void shouldBurnIo() {
62 | BurnIoSimianArmyChaosScript burnIoSimianArmyChaosScript = new BurnIoSimianArmyChaosScript();
63 | burnIoSimianArmyChaosScript.apply(cube);
64 |
65 | verify(canExecuteProcessInContainer).exec("dd", "if=/dev/urandom", "of=/burn", "bs=1M", "count=1024",
66 | "iflag=fullblock");
67 | }
68 |
69 | @Test
70 | public void shouldFillDisk() {
71 | final FillDiskSimianArmyChaosScript fillDiskSimianArmyChaosScript = new FillDiskSimianArmyChaosScript(10000);
72 | fillDiskSimianArmyChaosScript.apply(cube);
73 |
74 | verify(canExecuteProcessInContainer).exec("dd", "if=/dev/urandom", "of=/burn", "bs=1M", "count=10000",
75 | "iflag=fullblock");
76 | }
77 |
78 | @Test
79 | public void shouldKillProcess() {
80 | KillProcessSimianArmyChaosScript killProcessSimianArmyChaosScript = new KillProcessSimianArmyChaosScript("java");
81 | killProcessSimianArmyChaosScript.apply(cube);
82 |
83 | verify(canExecuteProcessInContainer).exec("pkill", "-f", "java");
84 | }
85 |
86 | @Test
87 | public void shouldNullRoute() {
88 | NullRouteSimianArmyChaosScript nullRouteSimianArmyChaosScript = new NullRouteSimianArmyChaosScript();
89 | nullRouteSimianArmyChaosScript.apply(cube);
90 |
91 | verify(canExecuteProcessInContainer).exec("ip", "route", "add", "blackhole", "10.0.0.0/8");
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/ftest-toxic-reporter/src/test/java/org/arquillian/cube/q/toxic/reporter/ToxicFunctionalTest.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.toxic.reporter;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.arquillian.cube.HostIp;
5 | import org.arquillian.cube.impl.util.IOUtil;
6 | import org.arquillian.cube.q.api.NetworkChaos;
7 | import org.jboss.arquillian.junit.Arquillian;
8 | import org.jboss.arquillian.test.api.ArquillianResource;
9 | import org.junit.After;
10 | import org.junit.AfterClass;
11 | import org.junit.BeforeClass;
12 | import org.junit.Rule;
13 | import org.junit.Test;
14 | import org.junit.rules.ExpectedException;
15 | import org.junit.rules.TestName;
16 | import org.junit.runner.RunWith;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.net.SocketException;
21 | import java.net.URL;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | import static org.arquillian.cube.q.api.NetworkChaos.DistributedLatencyType.logNormalLatencyInMillis;
26 | import static org.arquillian.cube.q.api.NetworkChaos.RateType.rate;
27 | import static org.arquillian.cube.q.api.NetworkChaos.TimeoutType.timeoutInMillis;
28 | import static org.arquillian.cube.q.api.Q.IterationRunCondition.times;
29 | import static org.assertj.core.api.Assertions.assertThat;
30 |
31 | @RunWith(Arquillian.class)
32 | public class ToxicFunctionalTest {
33 |
34 | @ArquillianResource
35 | private NetworkChaos networkChaos;
36 |
37 | @HostIp
38 | private String ip;
39 |
40 | @Rule
41 | public TestName name = new TestName();
42 |
43 | @Rule
44 | public ExpectedException thrown = ExpectedException.none();
45 |
46 | private static List executedMethods = new ArrayList<>();
47 |
48 | private static final String LOG_DIR = (System.getProperty("user.dir") + "/target/reports/chaos/");
49 |
50 | @BeforeClass
51 | public static void clean_json_files_dir_from_target_reports() throws IOException {
52 | File chaosDir = new File(LOG_DIR);
53 | if (chaosDir.exists()) {
54 | FileUtils.cleanDirectory(new File(LOG_DIR));
55 | }
56 | }
57 |
58 | @Test
59 | public void should_add_timeout() throws Exception {
60 | thrown.expect(SocketException.class);
61 | thrown.expectMessage("Unexpected end of file from server");
62 | networkChaos.on("hw", 8080).timeout(timeoutInMillis(1000)).exec(() -> {
63 | getResponse();
64 | });
65 | }
66 |
67 | @Test
68 | public void should_add_bandwidth_with_iterations() throws Exception {
69 | networkChaos.on("hw", 8080).bandwidth(rate(1000)).exec(times(3), () -> {
70 | getResponse();
71 | });
72 | }
73 |
74 | @Test
75 | public void should_add_log_normal_latency_and_bandwidth_with_iterations() throws Exception {
76 | NetworkChaos.Action chaosAction = networkChaos.on("hw", 8080);
77 |
78 | chaosAction.bandwidth(NetworkChaos.DistributedRateType.logNormalLatencyInMillis(3000, 0.2));
79 | chaosAction.latency(logNormalLatencyInMillis(2000, 0.3));
80 |
81 | chaosAction.exec(times(3), () -> {
82 | getResponse();
83 | });
84 | }
85 |
86 | @After
87 | public void add_method_name() {
88 | executedMethods.add(name.getMethodName() + ".json");
89 | }
90 |
91 | @AfterClass
92 | public static void verify_json_files_in_reports_dir() {
93 | File chaosDir = new File(LOG_DIR);
94 | final int size = executedMethods.size();
95 | final String[] fileNames = executedMethods.toArray(new String[executedMethods.size()]);
96 |
97 | assertThat(chaosDir.exists()).isTrue();
98 | assertThat(chaosDir.list()).hasSize(size).containsExactlyInAnyOrder(fileNames);
99 | }
100 |
101 | private void getResponse() throws IOException {
102 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
103 | final long l = System.currentTimeMillis();
104 | String response = IOUtil.asString(url.openStream());
105 | System.out.println(response);
106 | System.out.println("Time:" + (System.currentTimeMillis() - l));
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/toxic/src/main/java/org/arquillian/cube/q/toxic/client/ToxiProxyScenario.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.toxic.client;
2 |
3 | import eu.rekawek.toxiproxy.Proxy;
4 | import org.arquillian.cube.q.api.Q;
5 | import org.arquillian.cube.q.toxic.event.ToxicCreated;
6 | import org.arquillian.cube.q.toxic.event.ToxicUpdated;
7 | import org.jboss.arquillian.core.api.Event;
8 | import org.jboss.arquillian.core.api.Injector;
9 | import org.jboss.arquillian.core.api.annotation.Inject;
10 |
11 | import java.util.HashMap;
12 | import java.util.List;
13 | import java.util.Map;
14 | import java.util.logging.Level;
15 | import java.util.logging.Logger;
16 |
17 | public class ToxiProxyScenario implements ToxiProxy {
18 |
19 | private static final Logger logger = Logger.getLogger(ToxiProxyScenario.class.getName());
20 |
21 | private ToxiProxyClient client;
22 |
23 | private Map proxies;
24 |
25 | private Injector injector;
26 |
27 | public ToxiProxyScenario(ToxiProxyClient client, Injector injector) {
28 | this.client = client;
29 | this.proxies = new HashMap<>();
30 | this.injector = injector;
31 | }
32 |
33 | public ToxiProxyScenario(ToxiProxyClient client) {
34 | this.client = client;
35 | this.proxies = new HashMap<>();
36 | }
37 |
38 | public void register(String name, String listen, String upstream) {
39 | proxies.put(name, client.createProxy(name, listen, upstream));
40 | }
41 |
42 | public void reset() {
43 | client.reset();
44 | proxies = client.getProxies();
45 | }
46 |
47 | public Scenario given(String name) {
48 | if (!proxies.containsKey(name)) {
49 | throw new IllegalArgumentException("No known proxy with name " + name);
50 | }
51 |
52 | ToxicScenario toxicScenario = new ToxicScenario(proxies.get(name));
53 |
54 | return injector.inject(toxicScenario);
55 | }
56 |
57 | public class ToxicScenario implements Scenario {
58 |
59 | private Proxy proxy;
60 | private List toxics;
61 |
62 | @Inject
63 | private Event toxicCreated;
64 |
65 | @Inject
66 | private Event toxicUpdated;
67 |
68 | public ToxicScenario(Proxy proxy) {
69 | this.proxy = proxy;
70 | }
71 |
72 | @Override
73 | public Scenario given(String name) {
74 | return ToxiProxyScenario.this.given(name);
75 | }
76 |
77 | @Override
78 | public Scenario using(final List toxics) {
79 | this.toxics = toxics;
80 | return this;
81 | }
82 |
83 | @Override
84 | public void then(Callable callable) throws Exception {
85 | try {
86 | execute();
87 | callable.call();
88 | } finally {
89 | reset();
90 | }
91 | }
92 |
93 | @Override
94 | public void then(Q.RunCondition runCondition, Callable callable) throws Exception {
95 | try {
96 | execute(runCondition);
97 | callable.call();
98 | } finally {
99 | reset();
100 | }
101 | }
102 |
103 | @Override
104 | public void execute() throws Exception {
105 | for (ToxiProxyClient.BaseToxic toxic : toxics) {
106 | logger.log(Level.FINER, String.format("Next toxic is created %s.", toxic.toString()));
107 | client.createToxic(proxy, toxic);
108 | toxicCreated.fire(new ToxicCreated(toxic));
109 | }
110 | }
111 |
112 | @Override
113 | public void execute(Q.RunCondition runCondition) throws Exception {
114 | for (ToxiProxyClient.BaseToxic toxic : toxics) {
115 | logger.log(Level.FINER, String.format("Next toxic is created %s.", toxic.toString()));
116 | client.createToxic(proxy, toxic);
117 | toxicCreated.fire(new ToxicCreated(toxic, runCondition));
118 | }
119 | }
120 |
121 | @Override
122 | public void update() throws Exception {
123 | for (ToxiProxyClient.BaseToxic toxic : toxics) {
124 | logger.log(Level.FINER, String.format("Next toxic is updated %s.", toxic.toString()));
125 | client.updateToxic(proxy, toxic);
126 | toxicUpdated.fire(new ToxicUpdated(toxic));
127 | }
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/api/src/main/java/org/arquillian/cube/q/api/Q.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.api;
2 |
3 | import java.util.Arrays;
4 | import java.util.concurrent.TimeUnit;
5 |
6 | public interface Q {
7 |
8 | void exec() throws Exception;
9 |
10 | void exec(Perform perform) throws Exception;
11 |
12 | void exec(RunCondition runCondition, Perform perform) throws Exception;
13 |
14 | interface Perform {
15 | void execute() throws Exception;
16 | }
17 |
18 | interface RunCondition {
19 | boolean isExecutable();
20 | }
21 |
22 | class DurationRunCondition implements Q.RunCondition {
23 |
24 | private long finishTime;
25 |
26 | protected DurationRunCondition(long duration, TimeUnit unit) {
27 | final long durationInMillis = unit.toMillis(duration);
28 | this.finishTime = System.currentTimeMillis() + durationInMillis;
29 | }
30 |
31 | public long getFinishTime() {
32 | return finishTime;
33 | }
34 |
35 | public static DurationRunCondition during(long duration, TimeUnit timeUnit) {
36 | return new DurationRunCondition(duration, timeUnit);
37 | }
38 |
39 | @Override
40 | public boolean isExecutable() {
41 | return System.currentTimeMillis() < finishTime;
42 | }
43 | }
44 |
45 | class IterationRunCondition implements Q.RunCondition {
46 | private final long iterations;
47 | protected long currentIteration = 0;
48 |
49 | protected IterationRunCondition(long iterations) {
50 | this.iterations = iterations;
51 | }
52 |
53 | public long getIterations() {
54 | return iterations;
55 | }
56 |
57 | public static IterationRunCondition times(long numberOfIterations) {
58 | return new IterationRunCondition(numberOfIterations);
59 | }
60 |
61 | @Override
62 | public boolean isExecutable() {
63 |
64 | if (currentIteration < iterations) {
65 | currentIteration++;
66 | return true;
67 | } else {
68 | return false;
69 | }
70 | }
71 | }
72 |
73 | abstract class BaseType {
74 | private boolean distributed = false;
75 | protected T value;
76 |
77 | protected BaseType(boolean distributed, T value) {
78 | this.distributed = distributed;
79 | this.value = value;
80 | }
81 |
82 | protected void setDistributed() {
83 | this.distributed = true;
84 | }
85 |
86 | public boolean isDistributed() {
87 | return this.distributed;
88 | }
89 |
90 | public void calculateValue() {
91 | }
92 |
93 | public T getValue() {
94 | return value;
95 | }
96 | }
97 |
98 | abstract class FloatType extends BaseType {
99 | public FloatType(float value) {
100 | super(false, value);
101 | this.value = value;
102 | }
103 |
104 | @Override
105 | public String toString() {
106 | return Float.toString(value);
107 | }
108 | }
109 |
110 | abstract class LongType extends BaseType {
111 | protected LongType(long value) {
112 | super(false, value);
113 | this.value = value;
114 | }
115 |
116 | @Override
117 | public String toString() {
118 | return Long.toString(value);
119 | }
120 | }
121 |
122 | abstract class IntegerType extends BaseType {
123 | protected IntegerType(int value) {
124 | super(false, value);
125 | this.value = value;
126 | }
127 |
128 | @Override
129 | public String toString() {
130 | return Integer.toString(value);
131 | }
132 | }
133 |
134 | abstract class StringType extends BaseType {
135 | protected StringType(String value) {
136 | super(false, value);
137 | this.value = value;
138 | }
139 |
140 | @Override
141 | public String toString() {
142 | return value;
143 | }
144 | }
145 |
146 | abstract class ArrayType extends BaseType {
147 |
148 | protected ArrayType(T[] value) {
149 | super(false, value);
150 | this.value = value;
151 | }
152 |
153 | @Override
154 | public String toString() {
155 | return Arrays.toString(value);
156 | }
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/ftest-toxic/src/test/java/org/arquillian/cube/q/toxic/ToxicFunctionalTestCase.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.toxic;
2 |
3 | import eu.rekawek.toxiproxy.Proxy;
4 | import eu.rekawek.toxiproxy.ToxiproxyClient;
5 | import org.arquillian.cube.HostIp;
6 | import org.arquillian.cube.docker.impl.requirement.RequiresDockerMachine;
7 | import org.arquillian.cube.impl.util.IOUtil;
8 | import org.arquillian.cube.q.api.NetworkChaos;
9 | import org.arquillian.cube.requirement.ArquillianConditionalRunner;
10 | import org.jboss.arquillian.test.api.ArquillianResource;
11 | import org.junit.Assert;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 |
15 | import java.io.IOException;
16 | import java.net.URL;
17 |
18 | import static org.arquillian.cube.q.api.NetworkChaos.DistributedLatencyType.logNormalLatencyInMillis;
19 | import static org.arquillian.cube.q.api.NetworkChaos.LatencyType.latencyInMillis;
20 | import static org.arquillian.cube.q.api.Q.IterationRunCondition.times;
21 | import static org.hamcrest.CoreMatchers.is;
22 |
23 | @RequiresDockerMachine(name = "dev")
24 | @RunWith(ArquillianConditionalRunner.class)
25 | public class ToxicFunctionalTestCase {
26 |
27 | @ArquillianResource
28 | private NetworkChaos networkChaos;
29 |
30 | @HostIp
31 | private String ip;
32 |
33 | @Test
34 | public void should() throws Exception {
35 |
36 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
37 | final long l = System.currentTimeMillis();
38 | String response = IOUtil.asString(url.openStream());
39 | System.out.println("Time:" + (System.currentTimeMillis() - l));
40 | Assert.assertNotNull(response);
41 | }
42 |
43 | @Test
44 | public void shouldAddLatency() throws Exception {
45 | networkChaos.on("pingpong", 8080).latency(latencyInMillis(4000)).exec(() -> {
46 |
47 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
48 | final long l = System.currentTimeMillis();
49 | String response = IOUtil.asString(url.openStream());
50 | System.out.println(response);
51 | System.out.println("Time:" + (System.currentTimeMillis() - l));
52 | });
53 | }
54 |
55 | @Test
56 | public void shouldAddLatencyWithExec() throws Exception {
57 | networkChaos.on("pingpong", 8080).latency(latencyInMillis(4000)).exec();
58 |
59 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
60 | final long l = System.currentTimeMillis();
61 | String response = IOUtil.asString(url.openStream());
62 | System.out.println(response);
63 | System.out.println("Time:" + (System.currentTimeMillis() - l));
64 |
65 | ToxiproxyClient client = new ToxiproxyClient(ip, 8474);
66 | final Proxy proxy = client.getProxy("pingpong:8080");
67 | Assert.assertThat(proxy.toxics().getAll().size(), is(1));
68 | }
69 |
70 | @Test
71 | public void shouldAddLogNormalLatencyWithIterations() throws Exception {
72 | networkChaos.on("pingpong", 8080).latency(logNormalLatencyInMillis(2000, 0.3)).exec(times(2), () -> {
73 |
74 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
75 | final long l = System.currentTimeMillis();
76 | String response = IOUtil.asString(url.openStream());
77 | System.out.println(response);
78 | System.out.println("Time:" + (System.currentTimeMillis() - l));
79 | });
80 | }
81 |
82 | @Test
83 | public void shouldAddLatencyWithIterations() throws Exception {
84 | networkChaos.on("pingpong", 8080).latency(latencyInMillis(4000)).exec(times(2), () -> {
85 |
86 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
87 | final long l = System.currentTimeMillis();
88 | String response = IOUtil.asString(url.openStream());
89 | System.out.println(response);
90 | System.out.println("Time:" + (System.currentTimeMillis() - l));
91 | });
92 | }
93 |
94 | @Test(expected = IOException.class)
95 | public void shouldAddDownToxic() throws Exception {
96 | networkChaos.on("pingpong", 8080).down().exec(() -> {
97 | URL url = new URL("http://" + ip + ":" + 8081 + "/hw/HelloWorld");
98 | final long l = System.currentTimeMillis();
99 | String response = IOUtil.asString(url.openStream());
100 | System.out.println(response);
101 | System.out.println("Time:" + (System.currentTimeMillis() - l));
102 | });
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/toxic/src/test/java/org/arquillian/cube/q/toxic/InstallProxyTestCase.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.toxic;
2 |
3 | import org.arquillian.cube.docker.impl.client.CubeDockerConfiguration;
4 | import org.arquillian.cube.docker.impl.client.config.CubeContainer;
5 | import org.arquillian.cube.docker.impl.client.config.DockerCompositions;
6 | import org.arquillian.cube.docker.impl.client.config.ExposedPort;
7 | import org.arquillian.cube.docker.impl.client.config.Link;
8 | import org.arquillian.cube.docker.impl.client.config.PortBinding;
9 | import org.arquillian.cube.q.core.InstallProxy;
10 | import org.arquillian.cube.q.spi.NetworkChaosConfiguration;
11 | import org.arquillian.cube.q.spi.ProxyManager;
12 | import org.jboss.arquillian.core.api.annotation.ApplicationScoped;
13 | import org.jboss.arquillian.core.spi.ServiceLoader;
14 | import org.jboss.arquillian.core.test.AbstractManagerTestBase;
15 | import org.junit.Before;
16 | import org.junit.Test;
17 | import org.junit.runner.RunWith;
18 | import org.mockito.Mock;
19 | import org.mockito.Mockito;
20 | import org.mockito.runners.MockitoJUnitRunner;
21 |
22 | import java.util.HashMap;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | import static org.assertj.core.api.Assertions.assertThat;
27 |
28 | @RunWith(MockitoJUnitRunner.class)
29 | public class InstallProxyTestCase extends AbstractManagerTestBase {
30 |
31 | private static final String CONTENT =
32 | "a:\n" +
33 | " image: a/a\n" +
34 | " portBindings: [8089/tcp]\n" +
35 | " links:\n" +
36 | " - b:b\n" +
37 | "b:\n" +
38 | " image: b/b\n" +
39 | " exposedPorts: [2112/tcp]\n";
40 |
41 | @Mock
42 | private ServiceLoader loader;
43 |
44 | @Mock
45 | NetworkChaosConfiguration networkChaosConfiguration;
46 |
47 | private ToxicProxyHandler t;
48 |
49 | @Override
50 | protected void addExtensions(List> extensions) {
51 | extensions.add(InstallProxy.class);
52 | }
53 |
54 | @Before
55 | public void setup() {
56 | t = new ToxicProxyHandler();
57 | t.networkChaosConfigurationInstance = () -> {
58 | Mockito.when(networkChaosConfiguration.isToxifyPortBinding()).thenReturn(false);
59 | return networkChaosConfiguration;
60 | };
61 | Mockito.when(loader.onlyOne(ProxyManager.class)).thenReturn(t);
62 | bind(ApplicationScoped.class, ServiceLoader.class, loader);
63 | }
64 |
65 | @Test
66 | public void shouldInstallProxy() throws Exception {
67 | CubeDockerConfiguration config = createConfig(CONTENT);
68 | fire(config);
69 |
70 | DockerCompositions cubes = config.getDockerContainersContent();
71 | assertThat(cubes.getContainerIds()).hasSize(3);
72 | }
73 |
74 | @Test
75 | public void shouldRedirectLinksToToxicProxy() {
76 | CubeDockerConfiguration config = createConfig(CONTENT);
77 | fire(config);
78 |
79 | DockerCompositions cubes = config.getDockerContainersContent();
80 | CubeContainer a = cubes.get("a");
81 | assertThat(a.getLinks()).containsExactlyInAnyOrder(new Link("toxiproxy", "b"),
82 | new Link("toxiproxy", "toxiproxy"));
83 |
84 | CubeContainer b = cubes.get("toxiproxy");
85 | assertThat(b.getLinks()).containsExactlyInAnyOrder(new Link("b", "b_toxiproxy"));
86 | }
87 |
88 | @Test
89 | public void shouldRedirtPortBindingToToxicProxy() {
90 |
91 | t = new ToxicProxyHandler();
92 | t.networkChaosConfigurationInstance = () -> {
93 | Mockito.when(networkChaosConfiguration.isToxifyPortBinding()).thenReturn(true);
94 | return networkChaosConfiguration;
95 | };
96 | Mockito.when(loader.onlyOne(ProxyManager.class)).thenReturn(t);
97 |
98 | CubeDockerConfiguration config = createConfig(CONTENT);
99 | fire(config);
100 |
101 | DockerCompositions cubes = config.getDockerContainersContent();
102 | CubeContainer a = cubes.get("a");
103 | System.out.println(config.toString());
104 | assertThat(a.getPortBindings()).isNullOrEmpty();
105 | assertThat(a.getExposedPorts()).containsExactlyInAnyOrder(ExposedPort.valueOf("8089/tcp"));
106 |
107 | CubeContainer b = cubes.get("toxiproxy");
108 | assertThat(b.getLinks()).containsExactlyInAnyOrder(new Link("a", "a_toxiproxy"));
109 | assertThat(b.getPortBindings()).containsExactlyInAnyOrder(PortBinding.valueOf("8474/tcp"),
110 | PortBinding.valueOf("8089/tcp"));
111 | }
112 |
113 | private CubeDockerConfiguration createConfig(String content) {
114 | Map parameters = new HashMap<>();
115 |
116 | parameters.put("serverVersion", "1.13");
117 | parameters.put("serverUri", "http://localhost:25123");
118 | parameters.put("definitionFormat", "CUBE");
119 | parameters.put("dockerContainers", content);
120 | parameters.put("definitionFormat", "CUBE");
121 |
122 | return CubeDockerConfiguration.fromMap(parameters, null);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %*
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 |
121 | set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar""
122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
123 |
124 | # avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %*
125 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
126 | if ERRORLEVEL 1 goto error
127 | goto end
128 |
129 | :error
130 | set ERROR_CODE=1
131 |
132 | :end
133 | @endlocal & set ERROR_CODE=%ERROR_CODE%
134 |
135 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
136 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
137 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
138 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
139 | :skipRcPost
140 |
141 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
142 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
143 |
144 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
145 |
146 | exit /B %ERROR_CODE%
147 |
--------------------------------------------------------------------------------
/reporter/src/main/java/org/arquillian/cube/q/recorder/TakeNetworkChaosInformation.java:
--------------------------------------------------------------------------------
1 | package org.arquillian.cube.q.recorder;
2 |
3 | import com.fasterxml.jackson.core.JsonEncoding;
4 | import com.fasterxml.jackson.core.JsonFactory;
5 | import com.fasterxml.jackson.core.JsonGenerator;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 | import com.fasterxml.jackson.databind.node.ArrayNode;
8 | import com.fasterxml.jackson.databind.node.JsonNodeFactory;
9 | import com.fasterxml.jackson.databind.node.ObjectNode;
10 | import org.arquillian.cube.q.api.Q;
11 | import org.arquillian.cube.q.toxic.QNetworkChaosToxic;
12 | import org.arquillian.cube.q.toxic.client.ToxiProxyClient;
13 | import org.arquillian.cube.q.toxic.event.ToxicCreated;
14 | import org.arquillian.cube.q.toxic.event.ToxicUpdated;
15 | import org.arquillian.reporter.api.builder.Reporter;
16 | import org.arquillian.reporter.api.event.SectionEvent;
17 | import org.arquillian.reporter.api.event.TestMethodSection;
18 | import org.arquillian.reporter.api.model.entry.FileEntry;
19 | import org.arquillian.reporter.api.model.report.TestMethodReport;
20 | import org.arquillian.reporter.config.ReporterConfiguration;
21 | import org.jboss.arquillian.core.api.Event;
22 | import org.jboss.arquillian.core.api.annotation.Inject;
23 | import org.jboss.arquillian.core.api.annotation.Observes;
24 | import org.jboss.arquillian.test.spi.annotation.TestScoped;
25 | import org.jboss.arquillian.test.spi.event.suite.After;
26 |
27 | import java.io.File;
28 | import java.io.IOException;
29 | import java.lang.reflect.Method;
30 | import java.nio.file.Files;
31 | import java.nio.file.Path;
32 | import java.nio.file.Paths;
33 | import java.util.ArrayList;
34 | import java.util.LinkedHashMap;
35 | import java.util.List;
36 | import java.util.Map;
37 |
38 | import static org.arquillian.cube.q.recorder.NetworkChaosInformationReportKey.TOXICITY_DETAILS_PATH;
39 |
40 | /**
41 | * Class that reports general information about network toxics.
42 | */
43 | public class TakeNetworkChaosInformation {
44 |
45 | private static final String CREATE = "create";
46 | private static final String UPDATE = "update";
47 |
48 | @Inject
49 | Event sectionEvent;
50 |
51 | @TestScoped
52 | private List