use of com.datastax.testcontainers.ChaosNetworkContainer in project cdc-apache-cassandra by datastax.
the class PulsarCassandraSourceTests method testReadTimeout.
@Test
public void testReadTimeout() throws InterruptedException, IOException {
final String ksName = "ksx";
try (ChaosNetworkContainer<?> chaosContainer = new ChaosNetworkContainer<>(cassandraContainer2.getContainerName(), "100s")) {
try (CqlSession cqlSession = cassandraContainer1.getCqlSession()) {
cqlSession.execute("CREATE KEYSPACE IF NOT EXISTS " + ksName + " WITH replication = {'class':'SimpleStrategy','replication_factor':'2'};");
cqlSession.execute("CREATE TABLE IF NOT EXISTS " + ksName + ".table1 (id text PRIMARY KEY, a int) WITH cdc=true");
cqlSession.execute("INSERT INTO " + ksName + ".table1 (id, a) VALUES('1',1)");
deployConnector(ksName, "table1", NativeAvroConverter.class, NativeAvroConverter.class);
chaosContainer.start();
cqlSession.execute("INSERT INTO " + ksName + ".table1 (id, a) VALUES('2',1)");
cqlSession.execute("INSERT INTO " + ksName + ".table1 (id, a) VALUES('3',1)");
}
try (PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarContainer.getPulsarBrokerUrl()).build()) {
try (Consumer<GenericRecord> consumer = pulsarClient.newConsumer(org.apache.pulsar.client.api.Schema.AUTO_CONSUME()).topic(String.format(Locale.ROOT, "data-%s.table1", ksName)).subscriptionName("sub1").subscriptionType(SubscriptionType.Key_Shared).subscriptionMode(SubscriptionMode.Durable).subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe()) {
Message<GenericRecord> msg;
int numMessage = 0;
while ((msg = consumer.receive(180, TimeUnit.SECONDS)) != null && numMessage < 3) {
numMessage++;
consumer.acknowledge(msg);
}
assertEquals(3, numMessage);
assertEquals(0, connectorStatus(ksName, "table1"));
}
}
} finally {
dumpFunctionLogs("cassandra-source-" + ksName + "-table1");
undeployConnector(ksName, "table1");
}
}
use of com.datastax.testcontainers.ChaosNetworkContainer in project cdc-apache-cassandra by datastax.
the class PulsarCassandraSourceTests method testConnectionFailure.
@Test
public void testConnectionFailure() throws InterruptedException, IOException {
final String ksName = "ksx2";
try (ChaosNetworkContainer<?> chaosContainer = new ChaosNetworkContainer<>(cassandraContainer1.getContainerName(), "100s")) {
try (CqlSession cqlSession = cassandraContainer1.getCqlSession()) {
cqlSession.execute("CREATE KEYSPACE IF NOT EXISTS " + ksName + " WITH replication = {'class':'SimpleStrategy','replication_factor':'2'};");
cqlSession.execute("CREATE TABLE IF NOT EXISTS " + ksName + ".table1 (id text PRIMARY KEY, a int) WITH cdc=true");
cqlSession.execute("INSERT INTO " + ksName + ".table1 (id, a) VALUES('1',1)");
cqlSession.execute("INSERT INTO " + ksName + ".table1 (id, a) VALUES('2',1)");
cqlSession.execute("INSERT INTO " + ksName + ".table1 (id, a) VALUES('3',1)");
}
chaosContainer.start();
deployConnector(ksName, "table1", NativeAvroConverter.class, NativeAvroConverter.class);
try (PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarContainer.getPulsarBrokerUrl()).build()) {
try (Consumer<GenericRecord> consumer = pulsarClient.newConsumer(org.apache.pulsar.client.api.Schema.AUTO_CONSUME()).topic(String.format(Locale.ROOT, "data-%s.table1", ksName)).subscriptionName("sub1").subscriptionType(SubscriptionType.Key_Shared).subscriptionMode(SubscriptionMode.Durable).subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe()) {
Message<GenericRecord> msg;
int numMessage = 0;
while ((msg = consumer.receive(180, TimeUnit.SECONDS)) != null && numMessage < 3) {
numMessage++;
consumer.acknowledge(msg);
}
assertEquals(3, numMessage);
assertEquals(0, connectorStatus(ksName, "table1"));
}
}
} finally {
dumpFunctionLogs("cassandra-source-" + ksName + "-table1");
undeployConnector(ksName, "table1");
}
}
use of com.datastax.testcontainers.ChaosNetworkContainer in project cdc-apache-cassandra by datastax.
the class PulsarSingleNodeTests method testPulsarReconnection.
@Test
@SuppressWarnings("unchecked")
public void testPulsarReconnection() throws IOException, InterruptedException {
if (version.equals(AgentTestUtil.Version.C3)) {
log.info("Skipping this test for agent c3");
return;
}
String pulsarServiceUrl = "pulsar://pulsar:" + pulsarContainer.BROKER_PORT;
int numMutation = 100;
try (CassandraContainer<?> cassandraContainer1 = createCassandraContainer(1, pulsarServiceUrl, testNetwork)) {
cassandraContainer1.start();
try (CqlSession cqlSession = cassandraContainer1.getCqlSession()) {
cqlSession.execute("CREATE KEYSPACE IF NOT EXISTS pulsarfailure WITH replication = {'class':'SimpleStrategy','replication_factor':'1'};");
cqlSession.execute("CREATE TABLE IF NOT EXISTS pulsarfailure.table1 (a int, b blob, PRIMARY KEY (a)) with cdc=true;");
for (int i = 0; i < numMutation; i++) {
cqlSession.execute("INSERT INTO pulsarfailure.table1 (a,b) VALUES (?, ?);", i, AgentTestUtil.randomizeBuffer(getSegmentSize() / 4));
}
}
try (CqlSession cqlSession = cassandraContainer1.getCqlSession();
ChaosNetworkContainer<?> chaosContainer = new ChaosNetworkContainer<>(pulsarContainer.getContainerName(), "100s")) {
chaosContainer.start();
// write 100 mutations during 100s (pulsar request timeout is 60s)
for (int i = 0; i < numMutation; i++) {
cqlSession.execute("INSERT INTO pulsarfailure.table1 (a,b) VALUES (?, ?);", 2 * i, AgentTestUtil.randomizeBuffer(getSegmentSize() / 4));
Thread.sleep(1000);
}
}
// wait the end of the network outage.
Thread.sleep(1000);
int msgCount = 0;
long maxLatency = 0;
try (PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarContainer.getPulsarBrokerUrl()).build();
Consumer<GenericRecord> consumer = pulsarClient.newConsumer(Schema.AUTO_CONSUME()).topic("events-pulsarfailure.table1").subscriptionName("sub1").subscriptionType(SubscriptionType.Key_Shared).subscriptionMode(SubscriptionMode.Durable).subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe()) {
Message<GenericRecord> msg;
while ((msg = consumer.receive(240, TimeUnit.SECONDS)) != null && msgCount < 2 * numMutation) {
Assert.assertNotNull("Expecting one message, check the agent log", msg);
msgCount++;
consumer.acknowledgeAsync(msg);
long writetime = Long.parseLong(msg.getProperty(Constants.WRITETIME));
long now = System.currentTimeMillis();
long latency = now * 1000 - writetime;
maxLatency = Math.max(maxLatency, latency);
consumer.acknowledgeAsync(msg);
}
assertEquals(2 * numMutation, msgCount);
assertTrue(maxLatency > 0);
}
}
}
Aggregations