Search in sources :

Example 1 with LogAndFailExceptionHandler

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

the class RecordQueueTest method shouldPassPartitionTimeToTimestampExtractor.

@Test
public void shouldPassPartitionTimeToTimestampExtractor() {
    final PartitionTimeTrackingTimestampExtractor timestampExtractor = new PartitionTimeTrackingTimestampExtractor();
    final RecordQueue queue = new RecordQueue(new TopicPartition("topic", 1), mockSourceNodeWithMetrics, timestampExtractor, new LogAndFailExceptionHandler(), context, new LogContext());
    assertTrue(queue.isEmpty());
    assertEquals(0, queue.size());
    assertEquals(RecordQueue.UNKNOWN, queue.headRecordTimestamp());
    // add three 3 out-of-order records with timestamp 2, 1, 3, 4
    final List<ConsumerRecord<byte[], byte[]>> list1 = Arrays.asList(new ConsumerRecord<>("topic", 1, 2, 0L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()), new ConsumerRecord<>("topic", 1, 1, 0L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()), new ConsumerRecord<>("topic", 1, 3, 0L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()), new ConsumerRecord<>("topic", 1, 4, 0L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()));
    assertEquals(RecordQueue.UNKNOWN, timestampExtractor.partitionTime);
    queue.addRawRecords(list1);
    // no (known) timestamp has yet been passed to the timestamp extractor
    assertEquals(RecordQueue.UNKNOWN, timestampExtractor.partitionTime);
    queue.poll();
    assertEquals(2L, timestampExtractor.partitionTime);
    queue.poll();
    assertEquals(2L, timestampExtractor.partitionTime);
    queue.poll();
    assertEquals(3L, timestampExtractor.partitionTime);
}
Also used : LogAndFailExceptionHandler(org.apache.kafka.streams.errors.LogAndFailExceptionHandler) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) TopicPartition(org.apache.kafka.common.TopicPartition) LogContext(org.apache.kafka.common.utils.LogContext) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 2 with LogAndFailExceptionHandler

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

the class GlobalStateTaskTest method before.

@Before
public void before() {
    final Set<String> storeNames = Utils.mkSet("t1-store", "t2-store");
    final Map<String, SourceNode> sourceByTopics = new HashMap<>();
    sourceByTopics.put(topic1, sourceOne);
    sourceByTopics.put(topic2, sourceTwo);
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put("t1-store", topic1);
    storeToTopic.put("t2-store", topic2);
    topology = ProcessorTopology.with(Utils.mkList(sourceOne, sourceTwo, processorOne, processorTwo), sourceByTopics, Collections.<StateStore>emptyList(), storeToTopic);
    offsets.put(t1, 50L);
    offsets.put(t2, 100L);
    stateMgr = new GlobalStateManagerStub(storeNames, offsets);
    globalStateTask = new GlobalStateUpdateTask(topology, context, stateMgr, new LogAndFailExceptionHandler(), logContext);
}
Also used : MockSourceNode(org.apache.kafka.test.MockSourceNode) LogAndFailExceptionHandler(org.apache.kafka.streams.errors.LogAndFailExceptionHandler) HashMap(java.util.HashMap) GlobalStateManagerStub(org.apache.kafka.test.GlobalStateManagerStub) StateStore(org.apache.kafka.streams.processor.StateStore) Before(org.junit.Before)

Example 3 with LogAndFailExceptionHandler

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

the class GlobalStateTaskTest method before.

@Before
public void before() {
    final Set<String> storeNames = Utils.mkSet("t1-store", "t2-store");
    final Map<String, SourceNode<?, ?>> sourceByTopics = new HashMap<>();
    sourceByTopics.put(topic1, sourceOne);
    sourceByTopics.put(topic2, sourceTwo);
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put("t1-store", topic1);
    storeToTopic.put("t2-store", topic2);
    topology = ProcessorTopologyFactories.with(asList(sourceOne, sourceTwo, processorOne, processorTwo), sourceByTopics, Collections.emptyList(), storeToTopic);
    offsets.put(t1, 50L);
    offsets.put(t2, 100L);
    stateMgr = new GlobalStateManagerStub(storeNames, offsets, testDirectory);
    globalStateTask = new GlobalStateUpdateTask(logContext, topology, context, stateMgr, new LogAndFailExceptionHandler());
}
Also used : MockSourceNode(org.apache.kafka.test.MockSourceNode) LogAndFailExceptionHandler(org.apache.kafka.streams.errors.LogAndFailExceptionHandler) HashMap(java.util.HashMap) GlobalStateManagerStub(org.apache.kafka.test.GlobalStateManagerStub) Before(org.junit.Before)

Aggregations

LogAndFailExceptionHandler (org.apache.kafka.streams.errors.LogAndFailExceptionHandler)3 HashMap (java.util.HashMap)2 GlobalStateManagerStub (org.apache.kafka.test.GlobalStateManagerStub)2 MockSourceNode (org.apache.kafka.test.MockSourceNode)2 Before (org.junit.Before)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)1 LogContext (org.apache.kafka.common.utils.LogContext)1 StateStore (org.apache.kafka.streams.processor.StateStore)1 Test (org.junit.Test)1