Skip to content

Commit

Permalink
Revert "Fix NPE when only batchHandler is specified (#281)"
Browse files Browse the repository at this point in the history
This reverts commit f02269a.
  • Loading branch information
tsegismont committed Jan 3, 2025
1 parent f02269a commit d0c8e5f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ private void run(Handler<ConsumerRecord<K, V>> handler, Handler<ConsumerRecords<
this.pollRecords(records -> {

if (records != null && records.count() > 0) {
if (handler != null) {
// only set iterator if records are going to be consumed by individual record handler
this.current = records.iterator();
}
this.current = records.iterator();
if (multiHandler != null) {
multiHandler.handle(records);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,8 +1311,7 @@ public void testConsumerBatchHandler(TestContext ctx) throws Exception {
String consumerId = topicName;
Async batch1 = ctx.async();
AtomicInteger index = new AtomicInteger();
int batchSize = 500;
int numMessages = 1000;
int numMessages = 500;
kafkaCluster.useTo().produceStrings(numMessages, batch1::complete, () ->
new ProducerRecord<>(topicName, 0, "key-" + index.get(), "value-" + index.getAndIncrement()));
batch1.awaitSuccess(10000);
Expand All @@ -1326,7 +1325,7 @@ public void testConsumerBatchHandler(TestContext ctx) throws Exception {
Async batchHandler = ctx.async();
batchHandler.handler(ar -> wrappedConsumer.close());
wrappedConsumer.batchHandler(records -> {
ctx.assertEquals(batchSize, records.size());
ctx.assertEquals(numMessages, records.size());
for (int i = 0; i < records.size(); i++) {
KafkaConsumerRecord<Object, Object> record = records.recordAt(i);
int dec = count.decrementAndGet();
Expand All @@ -1335,10 +1334,8 @@ public void testConsumerBatchHandler(TestContext ctx) throws Exception {
} else {
ctx.assertEquals("key-" + (-1 - dec), record.key());
}
if (dec == 0) {
batchHandler.complete();
}
}
batchHandler.complete();
});
wrappedConsumer.subscribe(Collections.singleton(topicName));
}
Expand Down

0 comments on commit d0c8e5f

Please sign in to comment.