Search in sources :

Example 6 with LogAndContinueExceptionHandler

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

the class RecordQueueTest method shouldThrowOnNegativeTimestamp.

@Test
public void shouldThrowOnNegativeTimestamp() {
    final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(new ConsumerRecord<>("topic", 1, 1, -1L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()));
    final RecordQueue queue = new RecordQueue(new TopicPartition("topic", 1), mockSourceNodeWithMetrics, new FailOnInvalidTimestamp(), new LogAndContinueExceptionHandler(), new InternalMockProcessorContext(), new LogContext());
    final StreamsException exception = assertThrows(StreamsException.class, () -> queue.addRawRecords(records));
    assertThat(exception.getMessage(), equalTo("Input record ConsumerRecord(topic = topic, partition = 1, " + "leaderEpoch = null, offset = 1, CreateTime = -1, serialized key size = 0, serialized value size = 0, " + "headers = RecordHeaders(headers = [], isReadOnly = false), key = 1, value = 10) has invalid (negative) " + "timestamp. Possibly because a pre-0.10 producer client was used to write this record to Kafka without " + "embedding a timestamp, or because the input topic was created before upgrading the Kafka cluster to 0.10+. " + "Use a different TimestampExtractor to process this data."));
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) TopicPartition(org.apache.kafka.common.TopicPartition) StreamsException(org.apache.kafka.streams.errors.StreamsException) FailOnInvalidTimestamp(org.apache.kafka.streams.processor.FailOnInvalidTimestamp) LogContext(org.apache.kafka.common.utils.LogContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 7 with LogAndContinueExceptionHandler

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

the class RecordQueueTest method shouldDropOnNegativeTimestamp.

@Test
public void shouldDropOnNegativeTimestamp() {
    final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(new ConsumerRecord<>("topic", 1, 1, -1L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()));
    final RecordQueue queue = new RecordQueue(new TopicPartition("topic", 1), mockSourceNodeWithMetrics, new LogAndSkipOnInvalidTimestamp(), new LogAndContinueExceptionHandler(), new InternalMockProcessorContext(), new LogContext());
    queue.addRawRecords(records);
    assertEquals(0, queue.size());
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) TopicPartition(org.apache.kafka.common.TopicPartition) LogAndSkipOnInvalidTimestamp(org.apache.kafka.streams.processor.LogAndSkipOnInvalidTimestamp) LogContext(org.apache.kafka.common.utils.LogContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 8 with LogAndContinueExceptionHandler

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

the class GlobalStateTaskTest method shouldNotThrowStreamsExceptionWhenValueDeserializationFails.

@Test
public void shouldNotThrowStreamsExceptionWhenValueDeserializationFails() {
    final GlobalStateUpdateTask globalStateTask2 = new GlobalStateUpdateTask(logContext, topology, context, stateMgr, new LogAndContinueExceptionHandler());
    final byte[] key = new IntegerSerializer().serialize(topic2, 1);
    final byte[] recordValue = new LongSerializer().serialize(topic2, 10L);
    maybeDeserialize(globalStateTask2, key, recordValue, false);
}
Also used : LongSerializer(org.apache.kafka.common.serialization.LongSerializer) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) Test(org.junit.Test)

Example 9 with LogAndContinueExceptionHandler

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

the class TopologyTestDriver method setupGlobalTask.

private void setupGlobalTask(final Time mockWallClockTime, final StreamsConfig streamsConfig, final StreamsMetricsImpl streamsMetrics, final ThreadCache cache) {
    if (globalTopology != null) {
        final MockConsumer<byte[], byte[]> globalConsumer = new MockConsumer<>(OffsetResetStrategy.NONE);
        for (final String topicName : globalTopology.sourceTopics()) {
            final TopicPartition partition = new TopicPartition(topicName, 0);
            globalPartitionsByInputTopic.put(topicName, partition);
            offsetsByTopicOrPatternPartition.put(partition, new AtomicLong());
            globalConsumer.updatePartitions(topicName, Collections.singletonList(new PartitionInfo(topicName, 0, null, null, null)));
            globalConsumer.updateBeginningOffsets(Collections.singletonMap(partition, 0L));
            globalConsumer.updateEndOffsets(Collections.singletonMap(partition, 0L));
        }
        globalStateManager = new GlobalStateManagerImpl(logContext, mockWallClockTime, globalTopology, globalConsumer, stateDirectory, stateRestoreListener, streamsConfig);
        final GlobalProcessorContextImpl globalProcessorContext = new GlobalProcessorContextImpl(streamsConfig, globalStateManager, streamsMetrics, cache, mockWallClockTime);
        globalStateManager.setGlobalProcessorContext(globalProcessorContext);
        globalStateTask = new GlobalStateUpdateTask(logContext, globalTopology, globalProcessorContext, globalStateManager, new LogAndContinueExceptionHandler());
        globalStateTask.initialize();
        globalProcessorContext.setRecordContext(null);
    } else {
        globalStateManager = null;
        globalStateTask = null;
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) GlobalProcessorContextImpl(org.apache.kafka.streams.processor.internals.GlobalProcessorContextImpl) TopicPartition(org.apache.kafka.common.TopicPartition) GlobalStateManagerImpl(org.apache.kafka.streams.processor.internals.GlobalStateManagerImpl) PartitionInfo(org.apache.kafka.common.PartitionInfo) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) GlobalStateUpdateTask(org.apache.kafka.streams.processor.internals.GlobalStateUpdateTask)

Aggregations

LogAndContinueExceptionHandler (org.apache.kafka.streams.errors.LogAndContinueExceptionHandler)9 Test (org.junit.Test)8 TopicPartition (org.apache.kafka.common.TopicPartition)5 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)4 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)4 LongSerializer (org.apache.kafka.common.serialization.LongSerializer)4 LogContext (org.apache.kafka.common.utils.LogContext)4 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)2 FailOnInvalidTimestamp (org.apache.kafka.streams.processor.FailOnInvalidTimestamp)2 LogAndSkipOnInvalidTimestamp (org.apache.kafka.streams.processor.LogAndSkipOnInvalidTimestamp)2 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 GlobalProcessorContextImpl (org.apache.kafka.streams.processor.internals.GlobalProcessorContextImpl)1 GlobalStateManagerImpl (org.apache.kafka.streams.processor.internals.GlobalStateManagerImpl)1 GlobalStateUpdateTask (org.apache.kafka.streams.processor.internals.GlobalStateUpdateTask)1