use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowProcessorStateExceptionOnFlushIfStoreThrowsAnException.
@Test
public void shouldThrowProcessorStateExceptionOnFlushIfStoreThrowsAnException() {
final RuntimeException exception = new RuntimeException("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 ProcessorStateException thrown = assertThrows(ProcessorStateException.class, stateManager::flush);
assertEquals(exception, thrown.getCause());
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowProcessorStateExceptionOnCloseIfStoreThrowsAnException.
@Test
public void shouldThrowProcessorStateExceptionOnCloseIfStoreThrowsAnException() {
final RuntimeException exception = new RuntimeException("KABOOM!");
final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
final MockKeyValueStore stateStore = new MockKeyValueStore(persistentStoreName, true) {
@Override
public void close() {
throw exception;
}
};
stateManager.registerStore(stateStore, stateStore.stateRestoreCallback, null);
final ProcessorStateException thrown = assertThrows(ProcessorStateException.class, stateManager::close);
assertEquals(exception, thrown.getCause());
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldFlushGoodStoresEvenSomeThrowsException.
@Test
public void shouldFlushGoodStoresEvenSomeThrowsException() {
final AtomicBoolean flushedStore = new AtomicBoolean(false);
final MockKeyValueStore stateStore1 = new MockKeyValueStore(persistentStoreName, true) {
@Override
public void flush() {
throw new RuntimeException("KABOOM!");
}
};
final MockKeyValueStore stateStore2 = new MockKeyValueStore(persistentStoreTwoName, true) {
@Override
public void flush() {
flushedStore.set(true);
}
};
final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
stateManager.registerStore(stateStore1, stateStore1.stateRestoreCallback, null);
stateManager.registerStore(stateStore2, stateStore2.stateRestoreCallback, null);
try {
stateManager.flush();
} catch (final ProcessorStateException expected) {
/* ignore */
}
Assert.assertTrue(flushedStore.get());
}
use of org.apache.kafka.test.MockKeyValueStore 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.test.MockKeyValueStore in project kafka by apache.
the class ProcessorStateManagerTest method shouldPreserveStreamsExceptionOnCloseIfStoreThrows.
@Test
public void shouldPreserveStreamsExceptionOnCloseIfStoreThrows() {
final StreamsException exception = new StreamsException("KABOOM!");
final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
final MockKeyValueStore stateStore = new MockKeyValueStore(persistentStoreName, true) {
@Override
public void close() {
throw exception;
}
};
stateManager.registerStore(stateStore, stateStore.stateRestoreCallback, null);
final StreamsException thrown = assertThrows(StreamsException.class, stateManager::close);
assertEquals(exception, thrown);
}
Aggregations