Search in sources :

Example 1 with BatchIndexAndErrorMessage

use of org.apache.kafka.common.message.ProduceResponseData.BatchIndexAndErrorMessage in project kafka by apache.

the class SenderTest method testRecordErrorPropagatedToApplication.

@Test
public void testRecordErrorPropagatedToApplication() throws InterruptedException {
    int recordCount = 5;
    setup();
    Map<Integer, FutureRecordMetadata> futures = new HashMap<>(recordCount);
    for (int i = 0; i < recordCount; i++) {
        futures.put(i, appendToAccumulator(tp0));
    }
    // send request
    sender.runOnce();
    assertEquals(1, client.inFlightRequestCount());
    assertEquals(1, sender.inFlightBatches(tp0).size());
    OffsetAndError offsetAndError = new OffsetAndError(-1L, Errors.INVALID_RECORD, Arrays.asList(new BatchIndexAndErrorMessage().setBatchIndex(0).setBatchIndexErrorMessage("0"), new BatchIndexAndErrorMessage().setBatchIndex(2).setBatchIndexErrorMessage("2"), new BatchIndexAndErrorMessage().setBatchIndex(3)));
    client.respond(produceResponse(Collections.singletonMap(tp0, offsetAndError)));
    sender.runOnce();
    for (Map.Entry<Integer, FutureRecordMetadata> futureEntry : futures.entrySet()) {
        FutureRecordMetadata future = futureEntry.getValue();
        assertTrue(future.isDone());
        KafkaException exception = TestUtils.assertFutureThrows(future, KafkaException.class);
        Integer index = futureEntry.getKey();
        if (index == 0 || index == 2) {
            assertTrue(exception instanceof InvalidRecordException);
            assertEquals(index.toString(), exception.getMessage());
        } else if (index == 3) {
            assertTrue(exception instanceof InvalidRecordException);
            assertEquals(Errors.INVALID_RECORD.message(), exception.getMessage());
        } else {
            assertEquals(KafkaException.class, exception.getClass());
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) KafkaException(org.apache.kafka.common.KafkaException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) InvalidRecordException(org.apache.kafka.common.InvalidRecordException) BatchIndexAndErrorMessage(org.apache.kafka.common.message.ProduceResponseData.BatchIndexAndErrorMessage) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InvalidRecordException (org.apache.kafka.common.InvalidRecordException)1 KafkaException (org.apache.kafka.common.KafkaException)1 BatchIndexAndErrorMessage (org.apache.kafka.common.message.ProduceResponseData.BatchIndexAndErrorMessage)1 Test (org.junit.jupiter.api.Test)1