Search in sources :

Example 6 with OffsetCheckpoint

use of org.apache.kafka.streams.state.internals.OffsetCheckpoint in project kafka by apache.

the class ProcessorStateManagerTest method setup.

@Before
public void setup() {
    baseDir = TestUtils.tempDirectory();
    stateDirectory = new StateDirectory(applicationId, baseDir.getPath(), new MockTime());
    checkpointFile = new File(stateDirectory.directoryForTask(taskId), ProcessorStateManager.CHECKPOINT_FILE_NAME);
    checkpoint = new OffsetCheckpoint(checkpointFile);
}
Also used : OffsetCheckpoint(org.apache.kafka.streams.state.internals.OffsetCheckpoint) File(java.io.File) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 7 with OffsetCheckpoint

use of org.apache.kafka.streams.state.internals.OffsetCheckpoint in project kafka by apache.

the class GlobalStateManagerImplTest method writeCheckpoint.

private Map<TopicPartition, Long> writeCheckpoint() throws IOException {
    final OffsetCheckpoint checkpoint = new OffsetCheckpoint(checkpointFile);
    final Map<TopicPartition, Long> expected = Collections.singletonMap(t1, 1L);
    checkpoint.write(expected);
    return expected;
}
Also used : OffsetCheckpoint(org.apache.kafka.streams.state.internals.OffsetCheckpoint) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 8 with OffsetCheckpoint

use of org.apache.kafka.streams.state.internals.OffsetCheckpoint in project kafka by apache.

the class ProcessorStateManagerTest method testChangeLogOffsets.

@Test
public void testChangeLogOffsets() throws IOException {
    final TaskId taskId = new TaskId(0, 0);
    long lastCheckpointedOffset = 10L;
    String storeName1 = "store1";
    String storeName2 = "store2";
    String storeName3 = "store3";
    String storeTopicName1 = ProcessorStateManager.storeChangelogTopic(applicationId, storeName1);
    String storeTopicName2 = ProcessorStateManager.storeChangelogTopic(applicationId, storeName2);
    String storeTopicName3 = ProcessorStateManager.storeChangelogTopic(applicationId, storeName3);
    Map<String, String> storeToChangelogTopic = new HashMap<>();
    storeToChangelogTopic.put(storeName1, storeTopicName1);
    storeToChangelogTopic.put(storeName2, storeTopicName2);
    storeToChangelogTopic.put(storeName3, storeTopicName3);
    OffsetCheckpoint checkpoint = new OffsetCheckpoint(new File(stateDirectory.directoryForTask(taskId), ProcessorStateManager.CHECKPOINT_FILE_NAME));
    checkpoint.write(Collections.singletonMap(new TopicPartition(storeTopicName1, 0), lastCheckpointedOffset));
    TopicPartition partition1 = new TopicPartition(storeTopicName1, 0);
    TopicPartition partition2 = new TopicPartition(storeTopicName2, 0);
    TopicPartition partition3 = new TopicPartition(storeTopicName3, 1);
    MockStateStoreSupplier.MockStateStore store1 = new MockStateStoreSupplier.MockStateStore(storeName1, true);
    MockStateStoreSupplier.MockStateStore store2 = new MockStateStoreSupplier.MockStateStore(storeName2, true);
    MockStateStoreSupplier.MockStateStore store3 = new MockStateStoreSupplier.MockStateStore(storeName3, true);
    // if there is an source partition, inherit the partition id
    Set<TopicPartition> sourcePartitions = Utils.mkSet(new TopicPartition(storeTopicName3, 1));
    // standby
    ProcessorStateManager stateMgr = new ProcessorStateManager(taskId, sourcePartitions, true, stateDirectory, storeToChangelogTopic, changelogReader);
    try {
        stateMgr.register(store1, true, store1.stateRestoreCallback);
        stateMgr.register(store2, true, store2.stateRestoreCallback);
        stateMgr.register(store3, true, store3.stateRestoreCallback);
        Map<TopicPartition, Long> changeLogOffsets = stateMgr.checkpointed();
        assertEquals(3, changeLogOffsets.size());
        assertTrue(changeLogOffsets.containsKey(partition1));
        assertTrue(changeLogOffsets.containsKey(partition2));
        assertTrue(changeLogOffsets.containsKey(partition3));
        assertEquals(lastCheckpointedOffset, (long) changeLogOffsets.get(partition1));
        assertEquals(-1L, (long) changeLogOffsets.get(partition2));
        assertEquals(-1L, (long) changeLogOffsets.get(partition3));
    } finally {
        stateMgr.close(Collections.<TopicPartition, Long>emptyMap());
    }
}
Also used : OffsetCheckpoint(org.apache.kafka.streams.state.internals.OffsetCheckpoint) TaskId(org.apache.kafka.streams.processor.TaskId) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) File(java.io.File) Test(org.junit.Test)

Aggregations

OffsetCheckpoint (org.apache.kafka.streams.state.internals.OffsetCheckpoint)8 File (java.io.File)7 TopicPartition (org.apache.kafka.common.TopicPartition)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)4 PartitionInfo (org.apache.kafka.common.PartitionInfo)3 MockTime (org.apache.kafka.common.utils.MockTime)3 TaskId (org.apache.kafka.streams.processor.TaskId)3 Map (java.util.Map)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)2 MockStateStoreSupplier (org.apache.kafka.test.MockStateStoreSupplier)2 Metrics (org.apache.kafka.common.metrics.Metrics)1 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)1 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)1 StateStore (org.apache.kafka.streams.processor.StateStore)1 InMemoryKeyValueStore (org.apache.kafka.streams.state.internals.InMemoryKeyValueStore)1 ThreadCache (org.apache.kafka.streams.state.internals.ThreadCache)1 NoOpProcessorContext (org.apache.kafka.test.NoOpProcessorContext)1