Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup the AWS SQS Sink test #11

Merged
merged 1 commit into from
Dec 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private boolean checkMessages(List<Message> messages) {
}



private void consumeMessages(CountDownLatch latch) {
try {
awssqsClient.receive(TestCommon.DEFAULT_SQS_QUEUE, this::checkMessages);
Expand All @@ -111,38 +110,48 @@ private void consumeMessages(CountDownLatch latch) {
}
}

private void produceMessages() {
try {
KafkaClient<String, String> kafkaClient = new KafkaClient<>(kafka.getBootstrapServers());

for (int i = 0; i < expect; i++) {
kafkaClient.produce(TestCommon.DEFAULT_TEST_TOPIC, "Sink test message " + i);
}
} catch (Throwable t) {
LOG.error("Unable to publish messages to the broker: {}", t.getMessage(), t);
fail(String.format("Unable to publish messages to the broker: {}", t.getMessage()));
}
}


@Test(timeout = 90000)
public void testBasicSendReceive() {
try {
CountDownLatch latch = new CountDownLatch(1);
CountDownLatch latch = new CountDownLatch(2);

ExecutorService service = Executors.newFixedThreadPool(2);
service.submit(() -> kafkaConnectRunner.run());
ExecutorService service = Executors.newCachedThreadPool();
service.submit(() -> kafkaConnectRunner.run(latch));

LOG.debug("Creating the consumer ...");
service.submit(() -> consumeMessages(latch));

KafkaClient<String, String> kafkaClient = new KafkaClient<>(kafka.getBootstrapServers());

for (int i = 0; i < expect; i++) {
kafkaClient.produce(TestCommon.DEFAULT_TEST_TOPIC, "Sink test message " + i);
}

LOG.debug("Created the consumer ... About to receive messages");
LOG.debug("Creating the producer and sending messages ...");
produceMessages();

if (latch.await(120, TimeUnit.SECONDS)) {
LOG.debug("Waiting for the test to complete");
if (latch.await(80, TimeUnit.SECONDS)) {
Assert.assertTrue("Didn't process the expected amount of messages: " + received + " != " + expect,
received == expect);
} else {
fail("Failed to receive the messages within the specified time");
}

kafkaConnectRunner.stop();
} catch (Exception e) {
LOG.error("Amazon SQS test failed: {}", e.getMessage(), e);
fail(e.getMessage());
} finally {
kafkaConnectRunner.stop();
}

}


}