Skip to content

Commit

Permalink
KAFKA-12297 - Test case for callback
Browse files Browse the repository at this point in the history
  • Loading branch information
aadubey authored and omkreddy committed Feb 12, 2021
1 parent 4c4b91f commit cebb7c6
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.ProducerFencedException;
import org.apache.kafka.common.record.RecordBatch;
import org.apache.kafka.common.serialization.IntegerSerializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.apache.kafka.test.MockSerializer;
Expand All @@ -42,6 +43,7 @@
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -735,6 +737,27 @@ public void shouldNotBeFlushedAfterFlush() {
assertTrue(producer.flushed());
}

@Test
public void testMetadataOnException() throws InterruptedException {
buildMockProducer(false);
Future<RecordMetadata> md1 = producer.send(record2, (md, exception) -> {
assertNotNull(md);
assertEquals(md.offset(), -1L, "Invalid offset");
assertEquals(md.timestamp(), RecordBatch.NO_TIMESTAMP, "Invalid timestamp");
//assertEquals(md.checksum(), -1L, "Invalid checksum");
assertEquals(md.serializedKeySize(), -1L, "Invalid Serialized Key size");
assertEquals(md.serializedValueSize(), -1L, "Invalid Serialized value size");
});
IllegalArgumentException e = new IllegalArgumentException("dummy exception");
assertTrue(producer.errorNext(e), "Complete the second request with an error");
try {
md1.get();
fail("Something went wrong, expected an error");
} catch (ExecutionException err) {
assertEquals(e, err.getCause());
}
}

private boolean isError(Future<?> future) {
try {
future.get();
Expand Down

0 comments on commit cebb7c6

Please sign in to comment.