use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method testTopicGroupsByStateStore.
@Test
public void testTopicGroupsByStateStore() {
builder.setApplicationId("X");
builder.addSource(null, "source-1", null, null, null, "topic-1", "topic-1x");
builder.addSource(null, "source-2", null, null, null, "topic-2");
builder.addSource(null, "source-3", null, null, null, "topic-3");
builder.addSource(null, "source-4", null, null, null, "topic-4");
builder.addSource(null, "source-5", null, null, null, "topic-5");
builder.addProcessor("processor-1", new MockApiProcessorSupplier<>(), "source-1");
builder.addProcessor("processor-2", new MockApiProcessorSupplier<>(), "source-2");
builder.addStateStore(new MockKeyValueStoreBuilder("store-1", false), "processor-1", "processor-2");
builder.addProcessor("processor-3", new MockApiProcessorSupplier<>(), "source-3");
builder.addProcessor("processor-4", new MockApiProcessorSupplier<>(), "source-4");
builder.addStateStore(new MockKeyValueStoreBuilder("store-2", false), "processor-3", "processor-4");
builder.addProcessor("processor-5", new MockApiProcessorSupplier<>(), "source-5");
builder.addStateStore(new MockKeyValueStoreBuilder("store-3", false));
builder.connectProcessorAndStateStores("processor-5", "store-3");
builder.buildTopology();
final Map<Subtopology, InternalTopologyBuilder.TopicsInfo> topicGroups = builder.subtopologyToTopicsInfo();
final Map<Subtopology, InternalTopologyBuilder.TopicsInfo> expectedTopicGroups = new HashMap<>();
final String store1 = ProcessorStateManager.storeChangelogTopic("X", "store-1", builder.topologyName());
final String store2 = ProcessorStateManager.storeChangelogTopic("X", "store-2", builder.topologyName());
final String store3 = ProcessorStateManager.storeChangelogTopic("X", "store-3", builder.topologyName());
expectedTopicGroups.put(SUBTOPOLOGY_0, new InternalTopologyBuilder.TopicsInfo(Collections.emptySet(), mkSet("topic-1", "topic-1x", "topic-2"), Collections.emptyMap(), Collections.singletonMap(store1, new UnwindowedChangelogTopicConfig(store1, Collections.emptyMap()))));
expectedTopicGroups.put(SUBTOPOLOGY_1, new InternalTopologyBuilder.TopicsInfo(Collections.emptySet(), mkSet("topic-3", "topic-4"), Collections.emptyMap(), Collections.singletonMap(store2, new UnwindowedChangelogTopicConfig(store2, Collections.emptyMap()))));
expectedTopicGroups.put(SUBTOPOLOGY_2, new InternalTopologyBuilder.TopicsInfo(Collections.emptySet(), mkSet("topic-5"), Collections.emptyMap(), Collections.singletonMap(store3, new UnwindowedChangelogTopicConfig(store3, Collections.emptyMap()))));
assertEquals(3, topicGroups.size());
assertEquals(expectedTopicGroups, topicGroups);
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method shouldNotAllowToAddStoresWithSameName.
@Test
public void shouldNotAllowToAddStoresWithSameName() {
final StoreBuilder<KeyValueStore<Object, Object>> otherBuilder = new MockKeyValueStoreBuilder("testStore", false);
builder.addStateStore(storeBuilder);
final TopologyException exception = assertThrows(TopologyException.class, () -> builder.addStateStore(otherBuilder));
assertThat(exception.getMessage(), equalTo("Invalid topology: A different StateStore has already been added with the name testStore"));
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method shouldAllowIncrementalBuilds.
@Test
public void shouldAllowIncrementalBuilds() {
Map<Integer, Set<String>> oldNodeGroups, newNodeGroups;
oldNodeGroups = builder.nodeGroups();
builder.addSource(null, "source-1", null, null, null, "topic-1");
builder.addSource(null, "source-2", null, null, null, "topic-2");
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addSource(null, "source-3", null, null, null, Pattern.compile(""));
builder.addSource(null, "source-4", null, null, null, Pattern.compile(""));
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addProcessor("processor-1", new MockApiProcessorSupplier<>(), "source-1");
builder.addProcessor("processor-2", new MockApiProcessorSupplier<>(), "source-2");
builder.addProcessor("processor-3", new MockApiProcessorSupplier<>(), "source-3");
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addSink("sink-1", "sink-topic", null, null, null, "processor-1");
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addSink("sink-2", (k, v, ctx) -> "sink-topic", null, null, null, "processor-2");
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addStateStore(new MockKeyValueStoreBuilder("store-1", false), "processor-1", "processor-2");
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addStateStore(new MockKeyValueStoreBuilder("store-2", false));
builder.connectProcessorAndStateStores("processor-2", "store-2");
builder.connectProcessorAndStateStores("processor-3", "store-2");
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
oldNodeGroups = newNodeGroups;
builder.addGlobalStore(new MockKeyValueStoreBuilder("global-store", false).withLoggingDisabled(), "globalSource", null, null, null, "globalTopic", "global-processor", new MockApiProcessorSupplier<>());
newNodeGroups = builder.nodeGroups();
assertNotEquals(oldNodeGroups, newNodeGroups);
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method shouldConnectGlobalStateStoreToInputTopic.
@Test
public void shouldConnectGlobalStateStoreToInputTopic() {
final String globalStoreName = "global-store";
final String globalTopic = "global-topic";
builder.setApplicationId("X");
builder.addGlobalStore(new MockKeyValueStoreBuilder(globalStoreName, false).withLoggingDisabled(), "globalSource", null, null, null, globalTopic, "global-processor", new MockApiProcessorSupplier<>());
builder.initializeSubscription();
builder.rewriteTopology(new StreamsConfig(mkProperties(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, "asdf"), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "asdf")))));
assertThat(builder.buildGlobalStateTopology().storeToChangelogTopic().get(globalStoreName), is(globalTopic));
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method testAddGlobalStoreWithBadSupplier.
@Test
public void testAddGlobalStoreWithBadSupplier() {
final org.apache.kafka.streams.processor.api.Processor<?, ?, Void, Void> processor = new MockApiProcessorSupplier<Object, Object, Void, Void>().get();
final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> builder.addGlobalStore(new MockKeyValueStoreBuilder("global-store", false).withLoggingDisabled(), "globalSource", null, null, null, "globalTopic", "global-processor", () -> processor));
assertThat(exception.getMessage(), containsString("#get() must return a new object each time it is called."));
}
Aggregations