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);
}
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;
}
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());
}
}
Aggregations