use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class EosIntegrationTest method verifyStateIsInStoreAndOffsetsAreInCheckpoint.
private void verifyStateIsInStoreAndOffsetsAreInCheckpoint(final int partition, final Set<KeyValue<Long, Long>> expectedState) throws IOException {
final String stateStoreDir = stateTmpDir + File.separator + "appDir" + File.separator + applicationId + File.separator + "0_" + partition + File.separator;
// Verify that the data in the state store on disk is fully up-to-date
final StateStoreContext context = new MockInternalProcessorContext(new Properties(), new TaskId(0, 0), new File(stateStoreDir));
final MockKeyValueStore stateStore = new MockKeyValueStore("store", false);
final RocksDBStore store = (RocksDBStore) new RocksDbKeyValueBytesStoreSupplier(storeName, false).get();
store.init(context, stateStore);
store.all().forEachRemaining(kv -> {
final KeyValue<Long, Long> kv2 = new KeyValue<>(new BigInteger(kv.key.get()).longValue(), new BigInteger(kv.value).longValue());
expectedState.remove(kv2);
});
// Verify that the checkpointed offsets match exactly with max offset of the records in the changelog
final OffsetCheckpoint checkpoint = new OffsetCheckpoint(new File(stateStoreDir + ".checkpoint"));
final Map<TopicPartition, Long> checkpointedOffsets = checkpoint.read();
checkpointedOffsets.forEach(this::verifyChangelogMaxRecordOffsetMatchesCheckpointedOffset);
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class TopologyTest method shouldThrowOnUnassignedStateStoreAccess.
@Test
public void shouldThrowOnUnassignedStateStoreAccess() {
final String sourceNodeName = "source";
final String goodNodeName = "goodGuy";
final String badNodeName = "badGuy";
mockStoreBuilder();
EasyMock.expect(storeBuilder.build()).andReturn(new MockKeyValueStore("store", false));
EasyMock.replay(storeBuilder);
topology.addSource(sourceNodeName, "topic").addProcessor(goodNodeName, new LocalMockProcessorSupplier(), sourceNodeName).addStateStore(storeBuilder, goodNodeName).addProcessor(badNodeName, new LocalMockProcessorSupplier(), sourceNodeName);
final Properties config = new Properties();
config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class);
config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class);
try {
new TopologyTestDriver(topology, config);
fail("Should have thrown StreamsException");
} catch (final StreamsException e) {
final String error = e.toString();
final String expectedMessage = "org.apache.kafka.streams.errors.StreamsException: failed to initialize processor " + badNodeName;
assertThat(error, equalTo(expectedMessage));
}
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class StateManagerUtilTest method testRegisterStateStores.
@Test
public void testRegisterStateStores() {
final MockKeyValueStore store1 = new MockKeyValueStore("store1", false);
final MockKeyValueStore store2 = new MockKeyValueStore("store2", false);
final List<StateStore> stateStores = Arrays.asList(store1, store2);
expect(topology.stateStores()).andReturn(stateStores);
expect(stateManager.taskId()).andReturn(taskId);
expect(stateDirectory.lock(taskId)).andReturn(true);
expect(stateDirectory.directoryForTaskIsEmpty(taskId)).andReturn(true);
expect(topology.stateStores()).andReturn(stateStores);
stateManager.registerStateStores(stateStores, processorContext);
stateManager.initializeStoreOffsetsFromCheckpoint(true);
expectLastCall();
ctrl.checkOrder(true);
ctrl.replay();
StateManagerUtil.registerStateStores(logger, "logPrefix:", topology, stateManager, stateDirectory, processorContext);
ctrl.verify();
}
use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.
the class StreamTaskTest method createDisconnectedTask.
private StreamTask createDisconnectedTask(final StreamsConfig config) {
final MockKeyValueStore stateStore = new MockKeyValueStore(storeName, false);
final ProcessorTopology topology = ProcessorTopologyFactories.with(asList(source1, source2), mkMap(mkEntry(topic1, source1), mkEntry(topic2, source2)), singletonList(stateStore), emptyMap());
final MockConsumer<byte[], byte[]> consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {
@Override
public Map<TopicPartition, OffsetAndMetadata> committed(final Set<TopicPartition> partitions) {
throw new TimeoutException("KABOOM!");
}
};
final InternalProcessorContext context = new ProcessorContextImpl(taskId, config, stateManager, streamsMetrics, null);
return new StreamTask(taskId, partitions, 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 StreamTaskTest method createStatefulTask.
private StreamTask createStatefulTask(final StreamsConfig config, final boolean logged, final ProcessorStateManager stateManager) {
final MockKeyValueStore stateStore = new MockKeyValueStore(storeName, logged);
final ProcessorTopology topology = ProcessorTopologyFactories.with(asList(source1, source2), mkMap(mkEntry(topic1, source1), mkEntry(topic2, source2)), singletonList(stateStore), logged ? Collections.singletonMap(storeName, storeName + "-changelog") : Collections.emptyMap());
final InternalProcessorContext context = new ProcessorContextImpl(taskId, config, stateManager, streamsMetrics, null);
return new StreamTask(taskId, partitions, topology, consumer, new TopologyConfig(null, config, new Properties()).getTaskConfig(), streamsMetrics, stateDirectory, cache, time, stateManager, recordCollector, context, logContext);
}
Aggregations