use of org.apache.kafka.test.MockStateStore in project apache-kafka-on-k8s by banzaicloud.
the class ProcessorStateManagerTest method shouldThrowIllegalArgumentExceptionIfStoreNameIsSameAsCheckpointFileName.
@Test
public void shouldThrowIllegalArgumentExceptionIfStoreNameIsSameAsCheckpointFileName() throws IOException {
final ProcessorStateManager stateManager = new ProcessorStateManager(taskId, noPartitions, false, stateDirectory, Collections.<String, String>emptyMap(), changelogReader, false, logContext);
try {
stateManager.register(new MockStateStore(ProcessorStateManager.CHECKPOINT_FILE_NAME, true), null);
fail("should have thrown illegal argument exception when store name same as checkpoint file");
} catch (final IllegalArgumentException e) {
// pass
}
}
use of org.apache.kafka.test.MockStateStore in project apache-kafka-on-k8s by banzaicloud.
the class ProcessorStateManagerTest method shouldFlushAllStoresEvenIfStoreThrowsExcepiton.
@Test
public void shouldFlushAllStoresEvenIfStoreThrowsExcepiton() throws IOException {
final ProcessorStateManager stateManager = new ProcessorStateManager(taskId, Collections.singleton(changelogTopicPartition), false, stateDirectory, Collections.singletonMap(storeName, changelogTopic), changelogReader, false, logContext);
final AtomicBoolean flushedStore = new AtomicBoolean(false);
final MockStateStore stateStore1 = new MockStateStore(storeName, true) {
@Override
public void flush() {
throw new RuntimeException("KABOOM!");
}
};
final MockStateStore stateStore2 = new MockStateStore(storeName + "2", true) {
@Override
public void flush() {
flushedStore.set(true);
}
};
stateManager.register(stateStore1, stateStore1.stateRestoreCallback);
stateManager.register(stateStore2, stateStore2.stateRestoreCallback);
try {
stateManager.flush();
} catch (final ProcessorStateException expected) {
/* ignode */
}
Assert.assertTrue(flushedStore.get());
}
use of org.apache.kafka.test.MockStateStore in project apache-kafka-on-k8s by banzaicloud.
the class ProcessorStateManagerTest method shouldThrowProcessorStateExceptionOnFlushIfStoreThrowsAnException.
@Test
public void shouldThrowProcessorStateExceptionOnFlushIfStoreThrowsAnException() throws IOException {
final ProcessorStateManager stateManager = new ProcessorStateManager(taskId, Collections.singleton(changelogTopicPartition), false, stateDirectory, Collections.singletonMap(storeName, changelogTopic), changelogReader, false, logContext);
final MockStateStore stateStore = new MockStateStore(storeName, true) {
@Override
public void flush() {
throw new RuntimeException("KABOOM!");
}
};
stateManager.register(stateStore, stateStore.stateRestoreCallback);
try {
stateManager.flush();
fail("Should throw ProcessorStateException if store flush throws exception");
} catch (final ProcessorStateException e) {
// pass
}
}
use of org.apache.kafka.test.MockStateStore in project apache-kafka-on-k8s by banzaicloud.
the class ProcessorStateManagerTest method shouldNotChangeOffsetsIfAckedOffsetsIsNull.
@Test
public void shouldNotChangeOffsetsIfAckedOffsetsIsNull() throws IOException {
final Map<TopicPartition, Long> offsets = Collections.singletonMap(persistentStorePartition, 99L);
checkpoint.write(offsets);
final MockStateStore persistentStore = new MockStateStore(persistentStoreName, true);
final ProcessorStateManager stateMgr = new ProcessorStateManager(taskId, noPartitions, false, stateDirectory, Collections.<String, String>emptyMap(), changelogReader, false, logContext);
stateMgr.register(persistentStore, persistentStore.stateRestoreCallback);
stateMgr.close(null);
final Map<TopicPartition, Long> read = checkpoint.read();
assertThat(read, equalTo(offsets));
}
use of org.apache.kafka.test.MockStateStore in project apache-kafka-on-k8s by banzaicloud.
the class ProcessorStateManagerTest method shouldRestoreStoreWithSinglePutRestoreSpecification.
@Test
public void shouldRestoreStoreWithSinglePutRestoreSpecification() throws Exception {
final TaskId taskId = new TaskId(0, 2);
final Integer intKey = 1;
final MockStateStore persistentStore = getPersistentStore();
final ProcessorStateManager stateMgr = getStandByStateManager(taskId);
try {
stateMgr.register(persistentStore, persistentStore.stateRestoreCallback);
stateMgr.updateStandbyStates(persistentStorePartition, Collections.singletonList(consumerRecord));
assertThat(persistentStore.keys.size(), is(1));
assertTrue(persistentStore.keys.contains(intKey));
} finally {
stateMgr.close(Collections.<TopicPartition, Long>emptyMap());
}
}
Aggregations