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

Some failure test #11

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -129,4 +129,40 @@ public void testSendOneMessageRestartConsumerEnsureOneMessageOnly() throws Excep
await().atMost(2, SECONDS).until(() -> messageCounter.get() == 1);
consumer1.stop();
}

@Test
public void handleMessageWithExceptionTest() throws Exception {
final String topic = "handle_exception_topic";
createTopic(topic);

AtomicInteger messageCounter = new AtomicInteger();

Consumer<String> action1 = (message) -> {
throw new RuntimeException("unexpected");
};

Consumer<String> action2 = (message) -> {
messageCounter.incrementAndGet();
};

BlockingQueueConsumer<String, String> consumer1 = new BlockingQueueConsumer<>(topic, props,
42, action1);
consumer1.start();

BlockingQueueConsumer<String, String> consumer2 = new BlockingQueueConsumer<>(topic, props,
42, action2);
consumer2.start();

SimpleTestProducer testProducer = new SimpleTestProducer("Lorem-Radio", topic, kafkaConnect);
logger.info("Sending {} messages", NUMBER_OF_MESSAGES);

for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
testProducer.send(LOREM_IPSUM.paragraph());
}

await().atMost(60, SECONDS).until(() -> messageCounter.get() >= NUMBER_OF_MESSAGES);

testProducer.close();
consumer2.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ void relay(ConsumerRecord<K, V> message) throws InterruptedException {
if (!topic.equals(message.topic())) {
throw new ConsumerException(String.format("Message from unexpected topic: '%s'", message.topic()));
}

Processor<K, V> processor = processors.get(message.partition());
if (processor.isStopped()) {
throw new ConsumerException(
String.format("Processor '%s-%s' has stopped", message.topic(), message.partition())
);
}
processor.queue(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void run() {
} catch (Exception ex) {
logger.error("Error while relaying messages from kafka to queue: {}", ex.getMessage(), ex);
blockingQueueConsumer.stop();
break;
}
}
commitOffsets();
Expand Down