use of org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata in project kafka by apache.
the class ProcessorStateManagerTest method shouldOverrideOffsetsWhenRestoreAndProcess.
@Test
public void shouldOverrideOffsetsWhenRestoreAndProcess() throws IOException {
final Map<TopicPartition, Long> offsets = singletonMap(persistentStorePartition, 99L);
checkpoint.write(offsets);
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
try {
stateMgr.registerStore(persistentStore, persistentStore.stateRestoreCallback, null);
stateMgr.initializeStoreOffsetsFromCheckpoint(true);
final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
assertThat(storeMetadata, notNullValue());
assertThat(storeMetadata.offset(), equalTo(99L));
stateMgr.restore(storeMetadata, singletonList(consumerRecord));
assertThat(storeMetadata.offset(), equalTo(100L));
// should ignore irrelevant topic partitions
stateMgr.updateChangelogOffsets(mkMap(mkEntry(persistentStorePartition, 220L), mkEntry(irrelevantPartition, 9000L)));
stateMgr.checkpoint();
assertThat(stateMgr.storeMetadata(irrelevantPartition), equalTo(null));
assertThat(storeMetadata.offset(), equalTo(220L));
} finally {
stateMgr.close();
}
}
use of org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowIfRestoreCallbackThrows.
@Test
public void shouldThrowIfRestoreCallbackThrows() {
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
stateMgr.registerStore(persistentStore, (key, value) -> {
throw new RuntimeException("KABOOM!");
}, null);
final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
try {
stateMgr.restore(storeMetadata, singletonList(consumerRecord));
fail("should have thrown processor state exception when IO exception happens");
} catch (final ProcessorStateException e) {
// pass
}
}
use of org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata in project kafka by apache.
the class ProcessorStateManagerTest method shouldRestoreTimestampedStoreWithConverter.
@Test
public void shouldRestoreTimestampedStoreWithConverter() {
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
final MockKeyValueStore store = getConverterStore();
try {
stateMgr.registerStore(store, store.stateRestoreCallback, null);
final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
assertThat(storeMetadata, notNullValue());
stateMgr.restore(storeMetadata, singletonList(consumerRecord));
assertThat(store.keys.size(), is(1));
assertTrue(store.keys.contains(key));
// we just check timestamped value length
assertEquals(17, store.values.get(0).length);
} finally {
stateMgr.close();
}
}
use of org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata in project kafka by apache.
the class ProcessorStateManagerTest method shouldWriteCheckpointForPersistentStore.
@Test
public void shouldWriteCheckpointForPersistentStore() throws IOException {
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
try {
stateMgr.registerStore(persistentStore, persistentStore.stateRestoreCallback, null);
stateMgr.initializeStoreOffsetsFromCheckpoint(true);
final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
assertThat(storeMetadata, notNullValue());
stateMgr.restore(storeMetadata, singletonList(consumerRecord));
stateMgr.checkpoint();
final Map<TopicPartition, Long> read = checkpoint.read();
assertThat(read, equalTo(singletonMap(persistentStorePartition, 100L)));
} finally {
stateMgr.close();
}
}
use of org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata in project kafka by apache.
the class ProcessorStateManagerTest method shouldRestoreStoreWithRestoreCallback.
@Test
public void shouldRestoreStoreWithRestoreCallback() {
final MockRestoreCallback restoreCallback = new MockRestoreCallback();
final KeyValue<byte[], byte[]> expectedKeyValue = KeyValue.pair(keyBytes, valueBytes);
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
try {
stateMgr.registerStore(persistentStore, restoreCallback, null);
final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
assertThat(storeMetadata, notNullValue());
stateMgr.restore(storeMetadata, singletonList(consumerRecord));
assertThat(restoreCallback.restored.size(), is(1));
assertTrue(restoreCallback.restored.contains(expectedKeyValue));
assertEquals(Collections.singletonMap(persistentStorePartition, 101L), stateMgr.changelogOffsets());
} finally {
stateMgr.close();
}
}
Aggregations