use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldPreserveStreamsExceptionOnFlushIfStoreThrows.
@Test
public void shouldPreserveStreamsExceptionOnFlushIfStoreThrows() {
final StreamsException exception = new StreamsException("KABOOM!");
final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
final MockKeyValueStore stateStore = new MockKeyValueStore(persistentStoreName, true) {
@Override
public void flush() {
throw exception;
}
};
stateManager.registerStore(stateStore, stateStore.stateRestoreCallback, null);
final StreamsException thrown = assertThrows(StreamsException.class, stateManager::flush);
assertEquals(exception, thrown);
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowIfStateStoreHasLoggingDisabled.
@Test
public void shouldThrowIfStateStoreHasLoggingDisabled() {
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
final String storeName = "store-with-logging-disabled";
final MockKeyValueStore storeWithLoggingDisabled = new MockKeyValueStore(storeName, true);
stateMgr.registerStore(storeWithLoggingDisabled, null, null);
assertThrows("Registered state store " + storeName + " does not have a registered changelog partition." + " This may happen if logging is disabled for the state store.", IllegalStateException.class, () -> stateMgr.registeredChangelogPartitionFor(storeName));
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldCloseAllStoresEvenIfStoreThrowsException.
@Test
public void shouldCloseAllStoresEvenIfStoreThrowsException() {
final AtomicBoolean closedStore = new AtomicBoolean(false);
final MockKeyValueStore stateStore1 = new MockKeyValueStore(persistentStoreName, true) {
@Override
public void close() {
throw new RuntimeException("KABOOM!");
}
};
final MockKeyValueStore stateStore2 = new MockKeyValueStore(persistentStoreTwoName, true) {
@Override
public void close() {
closedStore.set(true);
}
};
final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
stateManager.registerStore(stateStore1, stateStore1.stateRestoreCallback, null);
stateManager.registerStore(stateStore2, stateStore2.stateRestoreCallback, null);
try {
stateManager.close();
} catch (final ProcessorStateException expected) {
/* ignore */
}
Assert.assertTrue(closedStore.get());
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class StreamTaskTest method createOptimizedStatefulTask.
private StreamTask createOptimizedStatefulTask(final StreamsConfig config, final Consumer<byte[], byte[]> consumer) {
final StateStore stateStore = new MockKeyValueStore(storeName, true);
final ProcessorTopology topology = ProcessorTopologyFactories.with(singletonList(source1), mkMap(mkEntry(topic1, source1)), singletonList(stateStore), Collections.singletonMap(storeName, topic1));
final InternalProcessorContext context = new ProcessorContextImpl(taskId, config, stateManager, streamsMetrics, null);
return new StreamTask(taskId, mkSet(partition1), topology, consumer, new TopologyConfig(null, config, new Properties()).getTaskConfig(), streamsMetrics, stateDirectory, cache, time, stateManager, recordCollector, context, logContext);
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class StateManagerUtilTest method testRegisterStateStoreFailToLockStateDirectory.
@Test
public void testRegisterStateStoreFailToLockStateDirectory() {
expect(topology.stateStores()).andReturn(singletonList(new MockKeyValueStore("store", false)));
expect(stateManager.taskId()).andReturn(taskId);
expect(stateDirectory.lock(taskId)).andReturn(false);
ctrl.checkOrder(true);
ctrl.replay();
final LockException thrown = assertThrows(LockException.class, () -> StateManagerUtil.registerStateStores(logger, "logPrefix:", topology, stateManager, stateDirectory, processorContext));
assertEquals("logPrefix:Failed to lock the state directory for task 0_0", thrown.getMessage());
ctrl.verify();
}
Aggregations