Search in sources :

Example 36 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method testBuild.

@Test
public void testBuild() {
    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 MockProcessorSupplier(), "source-1");
    builder.addProcessor("processor-2", new MockProcessorSupplier(), "source-2", "processor-1");
    builder.addProcessor("processor-3", new MockProcessorSupplier(), "source-3", "source-4");
    builder.setApplicationId("X");
    final ProcessorTopology topology0 = builder.build(0);
    final ProcessorTopology topology1 = builder.build(1);
    final ProcessorTopology topology2 = builder.build(2);
    assertEquals(mkSet("source-1", "source-2", "processor-1", "processor-2"), nodeNames(topology0.processors()));
    assertEquals(mkSet("source-3", "source-4", "processor-3"), nodeNames(topology1.processors()));
    assertEquals(mkSet("source-5"), nodeNames(topology2.processors()));
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) Test(org.junit.Test)

Example 37 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method testAddProcessorWithSameName.

@Test
public void testAddProcessorWithSameName() {
    builder.addSource(null, "source", null, null, null, "topic-1");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
    try {
        builder.addProcessor("processor", new MockProcessorSupplier(), "source");
        fail("Should throw TopologyException with processor name conflict");
    } catch (final TopologyException expected) {
    /* ok */
    }
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) TopologyException(org.apache.kafka.streams.errors.TopologyException) Test(org.junit.Test)

Example 38 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method testTopicGroups.

@Test
public void testTopicGroups() {
    builder.setApplicationId("X");
    builder.addInternalTopic("topic-1x");
    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 MockProcessorSupplier(), "source-1");
    builder.addProcessor("processor-2", new MockProcessorSupplier(), "source-2", "processor-1");
    builder.copartitionSources(mkList("source-1", "source-2"));
    builder.addProcessor("processor-3", new MockProcessorSupplier(), "source-3", "source-4");
    final Map<Integer, InternalTopologyBuilder.TopicsInfo> topicGroups = builder.topicGroups();
    final Map<Integer, InternalTopologyBuilder.TopicsInfo> expectedTopicGroups = new HashMap<>();
    expectedTopicGroups.put(0, new InternalTopologyBuilder.TopicsInfo(Collections.<String>emptySet(), mkSet("topic-1", "X-topic-1x", "topic-2"), Collections.<String, InternalTopicConfig>emptyMap(), Collections.<String, InternalTopicConfig>emptyMap()));
    expectedTopicGroups.put(1, new InternalTopologyBuilder.TopicsInfo(Collections.<String>emptySet(), mkSet("topic-3", "topic-4"), Collections.<String, InternalTopicConfig>emptyMap(), Collections.<String, InternalTopicConfig>emptyMap()));
    expectedTopicGroups.put(2, new InternalTopologyBuilder.TopicsInfo(Collections.<String>emptySet(), mkSet("topic-5"), Collections.<String, InternalTopicConfig>emptyMap(), Collections.<String, InternalTopicConfig>emptyMap()));
    assertEquals(3, topicGroups.size());
    assertEquals(expectedTopicGroups, topicGroups);
    final Collection<Set<String>> copartitionGroups = builder.copartitionGroups();
    assertEquals(mkSet(mkSet("topic-1", "X-topic-1x", "topic-2")), new HashSet<>(copartitionGroups));
}
Also used : HashSet(java.util.HashSet) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 39 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method testTopicGroupsByStateStore.

@SuppressWarnings("deprecation")
@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 MockProcessorSupplier(), "source-1");
    builder.addProcessor("processor-2", new MockProcessorSupplier(), "source-2");
    builder.addStateStore(new MockStateStoreSupplier("store-1", false), "processor-1", "processor-2");
    builder.addProcessor("processor-3", new MockProcessorSupplier(), "source-3");
    builder.addProcessor("processor-4", new MockProcessorSupplier(), "source-4");
    builder.addStateStore(new MockStateStoreSupplier("store-2", false), "processor-3", "processor-4");
    builder.addProcessor("processor-5", new MockProcessorSupplier(), "source-5");
    final StateStoreSupplier supplier = new MockStateStoreSupplier("store-3", false);
    builder.addStateStore(supplier);
    builder.connectProcessorAndStateStores("processor-5", "store-3");
    final Map<Integer, InternalTopologyBuilder.TopicsInfo> topicGroups = builder.topicGroups();
    final Map<Integer, InternalTopologyBuilder.TopicsInfo> expectedTopicGroups = new HashMap<>();
    final String store1 = ProcessorStateManager.storeChangelogTopic("X", "store-1");
    final String store2 = ProcessorStateManager.storeChangelogTopic("X", "store-2");
    final String store3 = ProcessorStateManager.storeChangelogTopic("X", "store-3");
    expectedTopicGroups.put(0, new InternalTopologyBuilder.TopicsInfo(Collections.<String>emptySet(), mkSet("topic-1", "topic-1x", "topic-2"), Collections.<String, InternalTopicConfig>emptyMap(), Collections.singletonMap(store1, (InternalTopicConfig) new UnwindowedChangelogTopicConfig(store1, Collections.<String, String>emptyMap()))));
    expectedTopicGroups.put(1, new InternalTopologyBuilder.TopicsInfo(Collections.<String>emptySet(), mkSet("topic-3", "topic-4"), Collections.<String, InternalTopicConfig>emptyMap(), Collections.singletonMap(store2, (InternalTopicConfig) new UnwindowedChangelogTopicConfig(store2, Collections.<String, String>emptyMap()))));
    expectedTopicGroups.put(2, new InternalTopologyBuilder.TopicsInfo(Collections.<String>emptySet(), mkSet("topic-5"), Collections.<String, InternalTopicConfig>emptyMap(), Collections.singletonMap(store3, (InternalTopicConfig) new UnwindowedChangelogTopicConfig(store3, Collections.<String, String>emptyMap()))));
    assertEquals(3, topicGroups.size());
    assertEquals(expectedTopicGroups, topicGroups);
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) HashMap(java.util.HashMap) StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) Test(org.junit.Test)

Example 40 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method shouldAddInternalTopicConfigForWindowStores.

@SuppressWarnings("unchecked")
@Test
public void shouldAddInternalTopicConfigForWindowStores() throws Exception {
    builder.setApplicationId("appId");
    builder.addSource(null, "source", null, null, null, "topic");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
    builder.addStateStore(new RocksDBWindowStoreSupplier("store", 30000, 3, false, null, null, 10000, true, Collections.<String, String>emptyMap(), false), "processor");
    final Map<Integer, InternalTopologyBuilder.TopicsInfo> topicGroups = builder.topicGroups();
    final InternalTopologyBuilder.TopicsInfo topicsInfo = topicGroups.values().iterator().next();
    final InternalTopicConfig topicConfig = topicsInfo.stateChangelogTopics.get("appId-store-changelog");
    final Map<String, String> properties = topicConfig.getProperties(Collections.<String, String>emptyMap(), 10000);
    assertEquals(2, properties.size());
    assertEquals(TopicConfig.CLEANUP_POLICY_COMPACT + "," + TopicConfig.CLEANUP_POLICY_DELETE, properties.get(TopicConfig.CLEANUP_POLICY_CONFIG));
    assertEquals("40000", properties.get(TopicConfig.RETENTION_MS_CONFIG));
    assertEquals("appId-store-changelog", topicConfig.name());
    assertTrue(topicConfig instanceof WindowedChangelogTopicConfig);
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) RocksDBWindowStoreSupplier(org.apache.kafka.streams.state.internals.RocksDBWindowStoreSupplier) Test(org.junit.Test)

Aggregations

MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)112 Test (org.junit.Test)109 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)34 HashMap (java.util.HashMap)29 MockStateStoreSupplier (org.apache.kafka.test.MockStateStoreSupplier)27 UUID (java.util.UUID)24 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)24 TaskId (org.apache.kafka.streams.processor.TaskId)24 SubscriptionInfo (org.apache.kafka.streams.processor.internals.assignment.SubscriptionInfo)23 HashSet (java.util.HashSet)21 MockInternalTopicManager (org.apache.kafka.test.MockInternalTopicManager)17 AssignmentInfo (org.apache.kafka.streams.processor.internals.assignment.AssignmentInfo)16 List (java.util.List)14 StreamsBuilderTest (org.apache.kafka.streams.StreamsBuilderTest)14 Metrics (org.apache.kafka.common.metrics.Metrics)13 Utils.mkList (org.apache.kafka.common.utils.Utils.mkList)11 Properties (java.util.Properties)9 TopicsInfo (org.apache.kafka.streams.processor.TopologyBuilder.TopicsInfo)8 InternalTopicConfig (org.apache.kafka.streams.processor.internals.InternalTopicConfig)8 KStreamTestDriver (org.apache.kafka.test.KStreamTestDriver)8