Search in sources :

Example 1 with GlobalStateUpdateTask

use of org.apache.kafka.streams.processor.internals.GlobalStateUpdateTask 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

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 LogAndContinueExceptionHandler (org.apache.kafka.streams.errors.LogAndContinueExceptionHandler)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