Search in sources :

Example 1 with AlwaysContinueProductionExceptionHandler

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

the class RecordCollectorTest method shouldNotThrowStreamsExceptionOnFlushIfASendFailedWithContinueExceptionHandler.

@SuppressWarnings("unchecked")
@Test
public void shouldNotThrowStreamsExceptionOnFlushIfASendFailedWithContinueExceptionHandler() {
    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.flush();
}
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 2 with AlwaysContinueProductionExceptionHandler

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

the class RecordCollectorTest method shouldThrowIfTopicIsUnknownWithContinueExceptionHandler.

@SuppressWarnings("unchecked")
@Test(expected = StreamsException.class)
public void shouldThrowIfTopicIsUnknownWithContinueExceptionHandler() {
    final RecordCollector collector = new RecordCollectorImpl(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {

        @Override
        public List<PartitionInfo> partitionsFor(final String topic) {
            return Collections.EMPTY_LIST;
        }
    }, "test", logContext, new AlwaysContinueProductionExceptionHandler());
    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) DefaultPartitioner(org.apache.kafka.clients.producer.internals.DefaultPartitioner) List(java.util.List) Test(org.junit.Test)

Example 3 with AlwaysContinueProductionExceptionHandler

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

the class RecordCollectorTest method shouldThrowStreamsExceptionOnSubsequentCloseIfFatalEvenWithContinueExceptionHandler.

@Test
public void shouldThrowStreamsExceptionOnSubsequentCloseIfFatalEvenWithContinueExceptionHandler() {
    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::closeClean);
    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 4 with AlwaysContinueProductionExceptionHandler

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

the class RecordCollectorTest method shouldThrowStreamsExceptionOnSubsequentSendIfFatalEvenWithContinueExceptionHandler.

@Test
public void shouldThrowStreamsExceptionOnSubsequentSendIfFatalEvenWithContinueExceptionHandler() {
    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.send(topic, "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner));
    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 5 with AlwaysContinueProductionExceptionHandler

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

the class RecordCollectorTest method shouldNotThrowStreamsExceptionOnCloseIfASendFailedWithContinueExceptionHandler.

@SuppressWarnings("unchecked")
@Test
public void shouldNotThrowStreamsExceptionOnCloseIfASendFailedWithContinueExceptionHandler() {
    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.close();
}
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)

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