Search in sources :

Example 1 with ToxiproxyContainer

use of org.testcontainers.containers.ToxiproxyContainer in project hazelcast by hazelcast.

the class PostgresCdcNetworkIntegrationTest method initToxiproxy.

private ToxiproxyContainer initToxiproxy(Network network) {
    ToxiproxyContainer toxiproxy = namedTestContainer(new ToxiproxyContainer().withNetwork(network));
    toxiproxy.start();
    return toxiproxy;
}
Also used : ToxiproxyContainer(org.testcontainers.containers.ToxiproxyContainer)

Example 2 with ToxiproxyContainer

use of org.testcontainers.containers.ToxiproxyContainer in project hazelcast by hazelcast.

the class PostgresCdcNetworkIntegrationTest method when_shortConnectionLossDuringBinlogReading_then_connectorDoesNotNoticeAnything.

@Test
public void when_shortConnectionLossDuringBinlogReading_then_connectorDoesNotNoticeAnything() throws Exception {
    try (Network network = initNetwork();
        ToxiproxyContainer toxiproxy = initToxiproxy(network)) {
        postgres = initPostgres(network, null);
        ToxiproxyContainer.ContainerProxy proxy = initProxy(toxiproxy, postgres);
        Pipeline pipeline = initPipeline(proxy.getContainerIpAddress(), proxy.getProxyPort());
        // when connector is up and transitions to binlog reading
        HazelcastInstance hz = createHazelcastInstances(2)[0];
        Job job = hz.getJet().newJob(pipeline);
        assertEqualsEventually(() -> hz.getMap("results").size(), 4);
        SECONDS.sleep(3);
        insertRecords(postgres, 1005);
        assertEqualsEventually(() -> hz.getMap("results").size(), 5);
        // and the connection is cut
        proxy.setConnectionCut(true);
        // and some new events get generated in the DB
        insertRecords(postgres, 1006, 1007);
        // and some time passes
        MILLISECONDS.sleep(5 * RECONNECT_INTERVAL_MS);
        // and the connection is re-established
        proxy.setConnectionCut(false);
        // then
        try {
            // then job keeps running, connector starts freshly, including snapshotting
            assertEqualsEventually(() -> hz.getMap("results").size(), 7);
            assertEquals(RUNNING, job.getStatus());
        } finally {
            abortJob(job);
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ToxiproxyContainer(org.testcontainers.containers.ToxiproxyContainer) Network(org.testcontainers.containers.Network) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) AbstractCdcIntegrationTest(com.hazelcast.jet.cdc.AbstractCdcIntegrationTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 3 with ToxiproxyContainer

use of org.testcontainers.containers.ToxiproxyContainer in project hazelcast by hazelcast.

the class KinesisFailureTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    assumeTrue(DockerClientFactory.instance().isDockerAvailable());
    localStack = new LocalStackContainer(parse("localstack/localstack").withTag("0.12.3")).withNetwork(NETWORK).withServices(Service.KINESIS);
    localStack.start();
    toxiProxy = new ToxiproxyContainer(parse("shopify/toxiproxy").withTag("2.1.0")).withNetwork(NETWORK).withNetworkAliases("toxiproxy");
    toxiProxy.start();
    System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true");
    // with the jackson versions we use (2.11.x) Localstack doesn't without disabling CBOR
    // https://github.com/localstack/localstack/issues/3208
    PROXY = toxiProxy.getProxy(localStack, 4566);
    AWS_CONFIG = new AwsConfig().withEndpoint("http://" + PROXY.getContainerIpAddress() + ":" + PROXY.getProxyPort()).withRegion(localStack.getRegion()).withCredentials(localStack.getAccessKey(), localStack.getSecretKey());
    KINESIS = AWS_CONFIG.buildClient();
    HELPER = new KinesisTestHelper(KINESIS, STREAM, Logger.getLogger(KinesisIntegrationTest.class));
}
Also used : AwsConfig(com.hazelcast.jet.kinesis.impl.AwsConfig) ToxiproxyContainer(org.testcontainers.containers.ToxiproxyContainer) LocalStackContainer(org.testcontainers.containers.localstack.LocalStackContainer) BeforeClass(org.junit.BeforeClass)

Example 4 with ToxiproxyContainer

use of org.testcontainers.containers.ToxiproxyContainer in project hazelcast by hazelcast.

the class PostgresCdcNetworkIntegrationTest method when_shortNetworkDisconnectDuringSnapshotting_then_connectorDoesNotNoticeAnything.

@Test
public void when_shortNetworkDisconnectDuringSnapshotting_then_connectorDoesNotNoticeAnything() throws Exception {
    try (Network network = initNetwork();
        ToxiproxyContainer toxiproxy = initToxiproxy(network)) {
        postgres = initPostgres(network, null);
        ToxiproxyContainer.ContainerProxy proxy = initProxy(toxiproxy, postgres);
        Pipeline pipeline = initPipeline(proxy.getContainerIpAddress(), proxy.getProxyPort());
        // when job starts
        HazelcastInstance hz = createHazelcastInstances(2)[0];
        Job job = hz.getJet().newJob(pipeline);
        assertJobStatusEventually(job, RUNNING);
        // and snapshotting is ongoing (we have no exact way of identifying
        // the moment, but random sleep will catch it at least some of the time)
        MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(0, 500));
        // and connection is cut
        proxy.setConnectionCut(true);
        // and some time passes
        MILLISECONDS.sleep(2 * RECONNECT_INTERVAL_MS);
        // it takes the bloody thing ages to notice the connection being down, so it won't notice this...
        // and connection recovers
        proxy.setConnectionCut(false);
        // then connector manages to reconnect and finish snapshot
        try {
            assertEqualsEventually(() -> hz.getMap("results").size(), 4);
        } finally {
            abortJob(job);
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ToxiproxyContainer(org.testcontainers.containers.ToxiproxyContainer) Network(org.testcontainers.containers.Network) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) AbstractCdcIntegrationTest(com.hazelcast.jet.cdc.AbstractCdcIntegrationTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 5 with ToxiproxyContainer

use of org.testcontainers.containers.ToxiproxyContainer in project hazelcast by hazelcast.

the class MySqlCdcNetworkIntegrationTest method when_networkDisconnectDuringBinlogRead_then_connectorReconnectsInternally.

@Test
public void when_networkDisconnectDuringBinlogRead_then_connectorReconnectsInternally() throws Exception {
    try (Network network = initNetwork();
        ToxiproxyContainer toxiproxy = initToxiproxy(network)) {
        mysql = initMySql(network, null);
        ToxiproxyContainer.ContainerProxy proxy = initProxy(toxiproxy, mysql);
        Pipeline pipeline = initPipeline(proxy.getContainerIpAddress(), proxy.getProxyPort());
        // when connector is up and transitions to binlog reading
        HazelcastInstance hz = createHazelcastInstances(2)[0];
        Job job = hz.getJet().newJob(pipeline);
        assertEqualsEventually(() -> hz.getMap("results").size(), 4);
        insertRecords(mysql, 1005);
        assertEqualsEventually(() -> hz.getMap("results").size(), 5);
        // and the connection is cut
        proxy.setConnectionCut(true);
        // and some new events get generated in the DB
        insertRecords(mysql, 1006, 1007);
        // and some time passes
        MILLISECONDS.sleep(2 * RECONNECT_INTERVAL_MS);
        // and the connection is re-established
        proxy.setConnectionCut(false);
        // then the connector catches up
        try {
            assertEqualsEventually(() -> hz.getMap("results").size(), 7);
        } finally {
            abortJob(job);
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ToxiproxyContainer(org.testcontainers.containers.ToxiproxyContainer) Network(org.testcontainers.containers.Network) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) AbstractCdcIntegrationTest(com.hazelcast.jet.cdc.AbstractCdcIntegrationTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

ToxiproxyContainer (org.testcontainers.containers.ToxiproxyContainer)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Job (com.hazelcast.jet.Job)4 AbstractCdcIntegrationTest (com.hazelcast.jet.cdc.AbstractCdcIntegrationTest)4 Pipeline (com.hazelcast.jet.pipeline.Pipeline)4 NightlyTest (com.hazelcast.test.annotation.NightlyTest)4 Test (org.junit.Test)4 Network (org.testcontainers.containers.Network)4 AwsConfig (com.hazelcast.jet.kinesis.impl.AwsConfig)1 BeforeClass (org.junit.BeforeClass)1 LocalStackContainer (org.testcontainers.containers.localstack.LocalStackContainer)1