Search in sources :

Example 6 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project kafka by apache.

the class TopologyBuilderTest method shouldCorrectlyMapStateStoreToInternalTopics.

@Test
public void shouldCorrectlyMapStateStoreToInternalTopics() throws Exception {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.setApplicationId("appId");
    builder.addInternalTopic("internal-topic");
    builder.addSource("source", "internal-topic");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
    builder.addStateStore(new MockStateStoreSupplier("store", false), "processor");
    final Map<String, List<String>> stateStoreNameToSourceTopic = builder.stateStoreNameToSourceTopics();
    assertEquals(1, stateStoreNameToSourceTopic.size());
    assertEquals(Collections.singletonList("appId-internal-topic"), stateStoreNameToSourceTopic.get("store"));
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) Utils.mkList(org.apache.kafka.common.utils.Utils.mkList) List(java.util.List) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) Test(org.junit.Test)

Example 7 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project kafka by apache.

the class TopologyBuilderTest method testAddProcessorWithSameName.

@Test(expected = TopologyBuilderException.class)
public void testAddProcessorWithSameName() {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.addSource("source", "topic-1");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) Test(org.junit.Test)

Example 8 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project kafka by apache.

the class TopologyBuilderTest method testBuild.

@Test
public void testBuild() {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.addSource("source-1", "topic-1", "topic-1x");
    builder.addSource("source-2", "topic-2");
    builder.addSource("source-3", "topic-3");
    builder.addSource("source-4", "topic-4");
    builder.addSource("source-5", "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");
    ProcessorTopology topology0 = builder.build(0);
    ProcessorTopology topology1 = builder.build(1);
    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 : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) Test(org.junit.Test)

Example 9 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project kafka by apache.

the class TopologyBuilderTest method shouldAssociateStateStoreNameWhenStateStoreSupplierIsExternal.

@Test
public void shouldAssociateStateStoreNameWhenStateStoreSupplierIsExternal() throws Exception {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.addSource("source", "topic");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
    builder.addStateStore(new MockStateStoreSupplier("store", false), "processor");
    final Map<String, List<String>> stateStoreNameToSourceTopic = builder.stateStoreNameToSourceTopics();
    assertEquals(1, stateStoreNameToSourceTopic.size());
    assertEquals(Collections.singletonList("topic"), stateStoreNameToSourceTopic.get("store"));
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) Utils.mkList(org.apache.kafka.common.utils.Utils.mkList) List(java.util.List) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) Test(org.junit.Test)

Example 10 with MockProcessorSupplier

use of org.apache.kafka.test.MockProcessorSupplier in project kafka by apache.

the class TopologyBuilderTest method shouldAddInternalTopicConfigWithCompactAndDeleteSetForWindowStores.

@SuppressWarnings("unchecked")
@Test
public void shouldAddInternalTopicConfigWithCompactAndDeleteSetForWindowStores() throws Exception {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.setApplicationId("appId");
    builder.addSource("source", "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, TopicsInfo> topicGroups = builder.topicGroups();
    final TopicsInfo topicsInfo = topicGroups.values().iterator().next();
    final InternalTopicConfig topicConfig = topicsInfo.stateChangelogTopics.get("appId-store-changelog");
    final Properties properties = topicConfig.toProperties(0);
    final List<String> policies = Arrays.asList(properties.getProperty(InternalTopicManager.CLEANUP_POLICY_PROP).split(","));
    assertEquals("appId-store-changelog", topicConfig.name());
    assertTrue(policies.contains("compact"));
    assertTrue(policies.contains("delete"));
    assertEquals(2, policies.size());
    assertEquals("30000", properties.getProperty(InternalTopicManager.RETENTION_MS));
    assertEquals(2, properties.size());
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) InternalTopicConfig(org.apache.kafka.streams.processor.internals.InternalTopicConfig) TopicsInfo(org.apache.kafka.streams.processor.TopologyBuilder.TopicsInfo) Properties(java.util.Properties) 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