Search in sources :

Example 6 with AlwaysContinueProductionExceptionHandler

use of org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler in project apache-kafka-on-k8s by banzaicloud.

the class RecordCollectorTest method shouldNotThrowStreamsExceptionOnSubsequentCallIfASendFailsWithContinueExceptionHandler.

@SuppressWarnings("unchecked")
@Test
public void shouldNotThrowStreamsExceptionOnSubsequentCallIfASendFailsWithContinueExceptionHandler() {
    final RecordCollector collector = new RecordCollectorImpl(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {

        @Override
        public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) {
            callback.onCompletion(null, new Exception());
            return null;
        }
    }, "test", logContext, new AlwaysContinueProductionExceptionHandler());
    collector.send("topic1", "3", "0", null, stringSerializer, stringSerializer, streamPartitioner);
    collector.send("topic1", "3", "0", null, stringSerializer, stringSerializer, streamPartitioner);
}
Also used : AlwaysContinueProductionExceptionHandler(org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler) MockProducer(org.apache.kafka.clients.producer.MockProducer) Callback(org.apache.kafka.clients.producer.Callback) DefaultPartitioner(org.apache.kafka.clients.producer.internals.DefaultPartitioner) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Future(java.util.concurrent.Future) KafkaException(org.apache.kafka.common.KafkaException) StreamsException(org.apache.kafka.streams.errors.StreamsException) Test(org.junit.Test)

Example 7 with AlwaysContinueProductionExceptionHandler

use of org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler in project kafka by apache.

the class RecordCollectorTest method shouldThrowStreamsExceptionOnSubsequentFlushIfFatalEvenWithContinueExceptionHandler.

@Test
public void shouldThrowStreamsExceptionOnSubsequentFlushIfFatalEvenWithContinueExceptionHandler() {
    final KafkaException exception = new AuthenticationException("KABOOM!");
    final RecordCollector collector = new RecordCollectorImpl(logContext, taskId, getExceptionalStreamsProducerOnSend(exception), new AlwaysContinueProductionExceptionHandler(), streamsMetrics);
    collector.send(topic, "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
    final StreamsException thrown = assertThrows(StreamsException.class, collector::flush);
    assertEquals(exception, thrown.getCause());
    assertThat(thrown.getMessage(), equalTo("Error encountered sending record to topic topic for task 0_0 due to:" + "\norg.apache.kafka.common.errors.AuthenticationException: KABOOM!" + "\nWritten offsets would not be recorded and no more records would be sent since this is a fatal error."));
}
Also used : AlwaysContinueProductionExceptionHandler(org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Example 8 with AlwaysContinueProductionExceptionHandler

use of org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler in project kafka by apache.

the class RecordCollectorTest method shouldNotThrowStreamsExceptionOnSubsequentCallIfASendFailsWithContinueExceptionHandler.

@Test
public void shouldNotThrowStreamsExceptionOnSubsequentCallIfASendFailsWithContinueExceptionHandler() {
    final RecordCollector collector = new RecordCollectorImpl(logContext, taskId, getExceptionalStreamsProducerOnSend(new Exception()), new AlwaysContinueProductionExceptionHandler(), streamsMetrics);
    try (final LogCaptureAppender logCaptureAppender = LogCaptureAppender.createAndRegister(RecordCollectorImpl.class)) {
        collector.send(topic, "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
        collector.flush();
        final List<String> messages = logCaptureAppender.getMessages();
        final StringBuilder errorMessage = new StringBuilder("Messages received:");
        for (final String error : messages) {
            errorMessage.append("\n - ").append(error);
        }
        assertTrue(errorMessage.toString(), messages.get(messages.size() - 1).endsWith("Exception handler choose to CONTINUE processing in spite of this error but written offsets would not be recorded."));
    }
    final Metric metric = streamsMetrics.metrics().get(new MetricName("dropped-records-total", "stream-task-metrics", "The total number of dropped records", mkMap(mkEntry("thread-id", Thread.currentThread().getName()), mkEntry("task-id", taskId.toString()))));
    assertEquals(1.0, metric.metricValue());
    collector.send(topic, "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
    collector.flush();
    collector.closeClean();
}
Also used : AlwaysContinueProductionExceptionHandler(org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler) MetricName(org.apache.kafka.common.MetricName) LogCaptureAppender(org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender) Metric(org.apache.kafka.common.Metric) KafkaException(org.apache.kafka.common.KafkaException) StreamsException(org.apache.kafka.streams.errors.StreamsException) InvalidProducerEpochException(org.apache.kafka.common.errors.InvalidProducerEpochException) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) TaskMigratedException(org.apache.kafka.streams.errors.TaskMigratedException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Test(org.junit.Test)

Aggregations

AlwaysContinueProductionExceptionHandler (org.apache.kafka.streams.errors.AlwaysContinueProductionExceptionHandler)8 Test (org.junit.Test)8 KafkaException (org.apache.kafka.common.KafkaException)7 StreamsException (org.apache.kafka.streams.errors.StreamsException)7 MockProducer (org.apache.kafka.clients.producer.MockProducer)4 DefaultPartitioner (org.apache.kafka.clients.producer.internals.DefaultPartitioner)4 AuthenticationException (org.apache.kafka.common.errors.AuthenticationException)4 Future (java.util.concurrent.Future)3 Callback (org.apache.kafka.clients.producer.Callback)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)3 List (java.util.List)1 Metric (org.apache.kafka.common.Metric)1 MetricName (org.apache.kafka.common.MetricName)1 InvalidProducerEpochException (org.apache.kafka.common.errors.InvalidProducerEpochException)1 ProducerFencedException (org.apache.kafka.common.errors.ProducerFencedException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 TaskMigratedException (org.apache.kafka.streams.errors.TaskMigratedException)1 LogCaptureAppender (org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender)1