How to use AtomicInteger method of org.testcontainers.containers.ToxiproxyContainer class

Best Testcontainers-java code snippet using org.testcontainers.containers.ToxiproxyContainer.AtomicInteger

Source:NiFiSmbjClientIT.java Github

copy

Full Screen

...33import java.util.concurrent.CountDownLatch;34import java.util.concurrent.Executors;35import java.util.concurrent.ScheduledExecutorService;36import java.util.concurrent.TimeUnit;37import java.util.concurrent.atomic.AtomicInteger;38import org.apache.nifi.components.PropertyDescriptor;39import org.apache.nifi.controller.ConfigurationContext;40import org.apache.nifi.util.MockConfigurationContext;41import org.junit.jupiter.api.AfterEach;42import org.junit.jupiter.api.BeforeEach;43import org.junit.jupiter.api.Test;44import org.slf4j.Logger;45import org.slf4j.LoggerFactory;46import org.testcontainers.containers.GenericContainer;47import org.testcontainers.containers.Network;48import org.testcontainers.containers.ToxiproxyContainer;49import org.testcontainers.containers.ToxiproxyContainer.ContainerProxy;50import org.testcontainers.containers.output.Slf4jLogConsumer;51import org.testcontainers.containers.wait.strategy.Wait;52import org.testcontainers.images.builder.Transferable;53import org.testcontainers.utility.DockerImageName;54public class NiFiSmbjClientIT {55 private final static Logger sambaContainerLogger = LoggerFactory.getLogger("sambaContainer");56 private final static Logger toxyProxyLogger = LoggerFactory.getLogger("toxiProxy");57 private final Network network = Network.newNetwork();58 private final GenericContainer<?> sambaContainer = new GenericContainer<>(DockerImageName.parse("dperson/samba"))59 .withExposedPorts(139, 445)60 .waitingFor(Wait.forListeningPort())61 .withLogConsumer(new Slf4jLogConsumer(sambaContainerLogger))62 .withNetwork(network)63 .withNetworkAliases("samba")64 .withCommand("-w domain -u username;password -s share;/folder;;no;no;username;;; -p");65 private final ToxiproxyContainer toxiproxy = new ToxiproxyContainer("shopify/toxiproxy")66 .withNetwork(network)67 .withLogConsumer(new Slf4jLogConsumer(toxyProxyLogger))68 .withNetworkAliases("toxiproxy");69 @BeforeEach70 public void beforeEach() {71 sambaContainer.start();72 toxiproxy.start();73 }74 @AfterEach75 public void afterEach() {76 toxiproxy.stop();77 sambaContainer.stop();78 }79 @Test80 public void shouldRescueAfterConnectionFailure() throws Exception {81 writeFile("testDirectory/file", "content");82 writeFile("testDirectory/directory1/file", "content");83 writeFile("testDirectory/directory2/file", "content");84 writeFile("testDirectory/directory2/nested_directory/file", "content");85 ContainerProxy sambaProxy = toxiproxy.getProxy("samba", 445);86 SmbjClientProviderService smbjClientProviderService = new SmbjClientProviderService();87 ConfigurationContext context = mock(ConfigurationContext.class);88 Map<PropertyDescriptor, String> properties = new HashMap<>();89 properties.put(HOSTNAME, sambaProxy.getContainerIpAddress());90 properties.put(PORT, String.valueOf(sambaProxy.getProxyPort()));91 properties.put(SHARE, "share");92 properties.put(USERNAME, "username");93 properties.put(PASSWORD, "password");94 properties.put(DOMAIN, "domain");95 properties.put(TIMEOUT, "0.5 sec");96 MockConfigurationContext mockConfigurationContext = new MockConfigurationContext(properties, null);97 smbjClientProviderService.onEnabled(mockConfigurationContext);98 sambaProxy.toxics().latency("slow", ToxicDirection.DOWNSTREAM, 300);99 AtomicInteger i = new AtomicInteger(0);100 ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);101 CountDownLatch latch = new CountDownLatch(100);102 executorService.scheduleWithFixedDelay(() -> {103 int iteration = i.getAndIncrement();104 if (iteration > 100) {105 return;106 }107 executorService.submit(() -> {108 SmbClientService s = null;109 try {110 s = smbjClientProviderService.getClient();111 if (iteration == 25) {112 sambaProxy.setConnectionCut(true);113 }...

Full Screen

Full Screen

Source:ToxiproxyContainer.java Github

copy

Full Screen

...10import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;11import java.io.IOException;12import java.util.HashMap;13import java.util.Map;14import java.util.concurrent.atomic.AtomicInteger;15/**16 * Container for resiliency testing using <a href="https://github.com/Shopify/toxiproxy">Toxiproxy</a>.17 */18public class ToxiproxyContainer extends GenericContainer<ToxiproxyContainer> {19 private static final String IMAGE_NAME = "shopify/toxiproxy:2.1.0";20 private static final int TOXIPROXY_CONTROL_PORT = 8474;21 private static final int FIRST_PROXIED_PORT = 8666;22 private static final int LAST_PROXIED_PORT = 8666 + 31;23 private ToxiproxyClient client;24 private final Map<String, ContainerProxy> proxies = new HashMap<>();25 private final AtomicInteger nextPort = new AtomicInteger(FIRST_PROXIED_PORT);26 public ToxiproxyContainer() {27 this(IMAGE_NAME);28 }29 public ToxiproxyContainer(String imageName) {30 super(imageName);31 addExposedPorts(TOXIPROXY_CONTROL_PORT);32 setWaitStrategy(new HttpWaitStrategy().forPath("/version").forPort(TOXIPROXY_CONTROL_PORT));33 // allow up to 32 ports to be proxied (arbitrary value). Here we make the ports exposed; whether or not34 // Toxiproxy will listen is controlled at runtime using getProxy(...)35 for (int i = FIRST_PROXIED_PORT; i <= LAST_PROXIED_PORT; i++) {36 addExposedPort(i);37 }38 }39 @Override...

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.ToxiproxyContainer;2import org.testcontainers.containers.ToxiproxyContainer.ContainerProxy;3import org.testcontainers.containers.ToxiproxyContainer.Proxy;4import org.testcontainers.containers.ToxiproxyContainer.ToxicDirection;5import org.testcontainers.containers.ToxiproxyContainer.ToxicList;6import org.testcontainers.containers.ToxiproxyContainer.ToxicList.ToxicListItem;7import org.testcontainers.containers.ToxiproxyContainer.ToxicType;8import org.testcontainers.containers.wait.strategy.Wait;9import org.testcontainers.utility.DockerImageName;10import java.util.concurrent.atomic.AtomicInteger;11import java.util.concurrent.atomic.AtomicReference;12import java.util.List;13import java.util.ArrayList;14public class ToxiproxyContainerTest {15 public static void main(String[] args) throws Exception {16 ToxiproxyContainer toxiproxy = new ToxiproxyContainer(DockerImageName.parse("shopify/toxiproxy:2.1.4"));17 toxiproxy.start();18 ContainerProxy containerProxy = toxiproxy.getProxy("backend", 6379);19 Proxy proxy = containerProxy.getProxy();20 AtomicInteger counter = new AtomicInteger();21 AtomicReference<List<ToxicListItem>> toxicList = new AtomicReference<>(new ArrayList<>());22 RedisContainer redis = new RedisContainer(DockerImageName.parse("redis:6.2.1"))23 .withExposedPorts(6379)24 .waitingFor(Wait.forListeningPort());25 redis.start();26 toxiproxy.start();27 String redisIp = redis.getContainerIpAddress();28 Integer redisPort = redis.getFirstMappedPort();29 ContainerProxy containerProxy = toxiproxy.getProxy(redis, redisPort);30 Proxy proxy = containerProxy.getProxy();31 proxy.setUpstream(redisIp + ":" + redisPort);32 String toxiproxyIp = toxiproxy.getContainerIpAddress();

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.ToxiproxyContainer;2import org.testcontainers.containers.ToxiproxyContainer.ContainerProxy;3import org.testcontainers.containers.ToxiproxyContainer.ProxySpec;4import org.testcontainers.containers.ToxiproxyContainer.ToxicDirection;5import org.testcontainers.containers.ToxiproxyContainer.ToxicList;6import org.testcontainers.containers.ToxiproxyContainer.ToxicList.ToxicListItem;7import org.testcontainers.containers.ToxiproxyContainer.Toxicity;8import org.testcontainers.containers.ToxiproxyContainer.Toxicity.Latency;9import org.testcontainers.containers.ToxiproxyContainer.Toxicity.Timeout;10import org.testcontainers.containers.ToxiproxyContainer.Toxicity.SlowClose;11import org.testcontainers.containers.ToxiproxyContainer.Toxicity.SlowOpen;12import org.testcontainers.containers.ToxiproxyContainer.Toxicity.Slicer;13import org.testcontainers.containers.ToxiproxyContainer.Toxicity.Severity;14import java.util.List;15import java.util.concurrent.atomic.AtomicInteger;16public class AtomicContainerProxy extends ContainerProxy {17 private final ToxiproxyContainer toxiproxy;18 private final AtomicInteger latency = new AtomicInteger();19 private final AtomicInteger timeout = new AtomicInteger();20 private final AtomicInteger slowClose = new AtomicInteger();21 private final AtomicInteger slowOpen = new AtomicInteger();22 private final AtomicInteger slicer = new AtomicInteger();23 public AtomicContainerProxy(ToxiproxyContainer toxiproxy, ProxySpec proxySpec) {24 super(toxiproxy, proxySpec);25 this.toxiproxy = toxiproxy;26 }27 public void setLatency(int latency) {28 this.latency.set(latency);29 }30 public void setTimeout(int timeout) {31 this.timeout.set(timeout);32 }33 public void setSlowClose(int slowClose) {34 this.slowClose.set(slowClose);35 }36 public void setSlowOpen(int slowOpen) {37 this.slowOpen.set(slowOpen);38 }39 public void setSlicer(int slicer) {40 this.slicer.set(slicer);41 }42 public void setLatencyAndTimeout(int latency, int timeout) {43 this.latency.set(latency);44 this.timeout.set(timeout);45 }46 public void setLatencyAndSlowClose(int latency, int slowClose) {47 this.latency.set(latency);

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1public class Test1 {2 public static void main(String[] args) {3 ToxiproxyContainer toxiproxy = new ToxiproxyContainer();4 toxiproxy.start();5 AtomicInteger proxyPort = toxiproxy.getProxyPort();6 System.out.println("proxyPort : " + proxyPort);7 }8}9public class Test2 {10 public static void main(String[] args) {11 ToxiproxyContainer toxiproxy = new ToxiproxyContainer();12 toxiproxy.start();13 AtomicInteger proxyPort = toxiproxy.getProxyPort();14 System.out.println("proxyPort : " + proxyPort);15 }16}17public class Test3 {18 public static void main(String[] args) {19 ToxiproxyContainer toxiproxy = new ToxiproxyContainer();20 toxiproxy.start();21 AtomicInteger proxyPort = toxiproxy.getProxyPort();22 System.out.println("proxyPort : " + proxyPort);23 }24}25public class Test4 {26 public static void main(String[] args) {27 ToxiproxyContainer toxiproxy = new ToxiproxyContainer();28 toxiproxy.start();29 AtomicInteger proxyPort = toxiproxy.getProxyPort();30 System.out.println("proxyPort : " + proxyPort);31 }32}33public class Test5 {34 public static void main(String[] args) {35 ToxiproxyContainer toxiproxy = new ToxiproxyContainer();36 toxiproxy.start();37 AtomicInteger proxyPort = toxiproxy.getProxyPort();38 System.out.println("proxyPort : " + proxyPort);39 }40}41public class Test6 {42 public static void main(String[] args) {43 ToxiproxyContainer toxiproxy = new ToxiproxyContainer();44 toxiproxy.start();

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1public class ToxiproxyContainerTest {2 private static final Logger logger = LoggerFactory.getLogger(ToxiproxyContainerTest.class);3 private static ToxiproxyContainer toxiproxyContainer;4 public static void startToxiproxyContainer() {5 toxiproxyContainer = new ToxiproxyContainer();6 toxiproxyContainer.start();7 }8 public void testToxiproxyContainer() {9 .createProxy("myProxy", 6379);10 logger.info("Proxy port is {}", proxy.getProxyPort());11 logger.info("Proxy host is {}", proxy.getContainerIpAddress());12 }13}14public class ToxiproxyContainerTest {15 private static final Logger logger = LoggerFactory.getLogger(ToxiproxyContainerTest.class);16 private static ToxiproxyContainer toxiproxyContainer;17 public static void startToxiproxyContainer() {18 toxiproxyContainer = new ToxiproxyContainer();19 toxiproxyContainer.start();20 }21 public void testToxiproxyContainer() {22 .createProxy("myProxy", 6379);23 logger.info("Proxy port is {}", proxy.getProxyPort());24 logger.info("Proxy host is {}", proxy.getContainerIpAddress());25 Toxic toxic = proxy.toxics().latency("latency", ToxicDirection.DOWNSTREAM, 1000L);26 logger.info("Toxic name is {}", toxic.getName());27 logger.info("Toxic type is {}", toxic.getType());28 logger.info("Toxic stream is {}", toxic.getStream());29 logger.info("Toxic attributes is {}", toxic.getAttributes());30 }31}

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import org.junit.Test;3import java.io.IOException;4import java.util.concurrent.atomic.AtomicInteger;5public class ToxiproxyContainerTest {6 public void testToxiproxyContainer() throws IOException, InterruptedException {7 ToxiproxyContainer toxiproxyContainer = new ToxiproxyContainer();8 toxiproxyContainer.start();9 AtomicInteger count = new AtomicInteger(1);10 toxiproxyContainer.getToxicProxy(count);11 }12}13package org.testcontainers.containers;14import org.junit.Test;15import java.io.IOException;16import java.util.concurrent.atomic.AtomicInteger;17public class ToxiproxyContainerTest {18 public void testToxiproxyContainer() throws IOException, InterruptedException {19 ToxiproxyContainer toxiproxyContainer = new ToxiproxyContainer();20 toxiproxyContainer.start();21 AtomicInteger count = new AtomicInteger(1);22 toxiproxyContainer.getToxicProxy(count);23 }24}25package org.testcontainers;26import org.junit.Test;27import java.io.IOException;28import java.util.concurrent.atomic.AtomicInteger;29public class ToxiproxyContainerTest {30 public void testToxiproxyContainer() throws IOException, InterruptedException {31 ToxiproxyContainer toxiproxyContainer = new ToxiproxyContainer();32 toxiproxyContainer.start();33 AtomicInteger count = new AtomicInteger(1);34 toxiproxyContainer.getToxicProxy(count);35 }36}37package org.testcontainers;38import org.junit.Test;39import java.io.IOException;40import java.util.concurrent.atomic.AtomicInteger;41public class ToxiproxyContainerTest {

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.ToxiproxyContainer;2import org.testcontainers.containers.wait.strategy.Wait;3import org.testcontainers.containers.wait.strategy.WaitAllStrategy;4import org.testcontainers.containers.wait.strategy.WaitStrategy;5import org.testcontainers.utility.DockerImageName;6public class TestContainer {7 public static void main(String[] args) {8 ToxiproxyContainer toxiproxy = new ToxiproxyContainer(DockerImageName.parse("shopify/toxiproxy:2.1.4"));9 toxiproxy.start();10 System.out.println("Port of the toxiproxy container is: " + toxiproxy.getProxyPort());11 }12}

Full Screen

Full Screen

AtomicInteger

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.testcontainers.containers.GenericContainer;3import org.testcontainers.containers.ToxiproxyContainer;4import org.testcontainers.containers.output.Slf4jLogConsumer;5import org.testcontainers.containers.wait.strategy.Wait;6import org.testcontainers.utility.DockerImageName;7import java.io.IOException;8import java.util.concurrent.atomic.AtomicInteger;9public class ToxiproxyTest {10 private static final AtomicInteger TOXIPROXY_PORT = new AtomicInteger(0);11 private static final AtomicInteger PROXY_PORT = new AtomicInteger(0);12 public void testToxiproxy() throws IOException, InterruptedException {13 ToxiproxyContainer toxiproxyContainer = new ToxiproxyContainer(DockerImageName.parse("shopify/toxiproxy"))14 .withNetwork(null)15 .withExposedPorts(8474);16 toxiproxyContainer.start();17 TOXIPROXY_PORT.set(toxiproxyContainer.getProxyPort());18 System.out.println("Toxiproxy port: " + TOXIPROXY_PORT);19 toxiproxyContainer.getProxy("toxiproxy", "redis:6379").setLatency(5000);20 toxiproxyContainer.getProxy("toxiproxy", "redis:6379").reset();21 toxiproxyContainer.stop();22 }23 public void testToxiproxyWithRedis() throws IOException, InterruptedException {24 ToxiproxyContainer toxiproxyContainer = new ToxiproxyContainer(DockerImageName.parse("shopify/toxiproxy"))25 .withNetwork(null)26 .withExposedPorts(8474);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful