Search in sources :

Example 81 with MockProcessorSupplier

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

the class InternalTopologyBuilderTest method testAddStateStore.

@SuppressWarnings("deprecation")
@Test
public void testAddStateStore() {
    final StateStoreSupplier supplier = new MockStateStoreSupplier("store-1", false);
    builder.addStateStore(supplier);
    builder.setApplicationId("X");
    builder.addSource(null, "source-1", null, null, null, "topic-1");
    builder.addProcessor("processor-1", new MockProcessorSupplier(), "source-1");
    assertEquals(0, builder.build(null).stateStores().size());
    builder.connectProcessorAndStateStores("processor-1", "store-1");
    final List<StateStore> suppliers = builder.build(null).stateStores();
    assertEquals(1, suppliers.size());
    assertEquals(supplier.name(), suppliers.get(0).name());
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) StateStore(org.apache.kafka.streams.processor.StateStore) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) Test(org.junit.Test)

Example 82 with MockProcessorSupplier

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

the class InternalTopologyBuilderTest method shouldAssociateStateStoreNameWhenStateStoreSupplierIsExternal.

@Test
public void shouldAssociateStateStoreNameWhenStateStoreSupplierIsExternal() throws Exception {
    builder.addSource(null, "source", null, null, null, "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 83 with MockProcessorSupplier

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

the class InternalTopologyBuilderTest method shouldAddInternalTopicConfigForNonWindowStores.

@SuppressWarnings("unchecked")
@Test
public void shouldAddInternalTopicConfigForNonWindowStores() throws Exception {
    builder.setApplicationId("appId");
    builder.addSource(null, "source", null, null, null, "topic");
    builder.addProcessor("processor", new MockProcessorSupplier(), "source");
    builder.addStateStore(new MockStateStoreSupplier("store", true), "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(1, properties.size());
    assertEquals(TopicConfig.CLEANUP_POLICY_COMPACT, properties.get(TopicConfig.CLEANUP_POLICY_CONFIG));
    assertEquals("appId-store-changelog", topicConfig.name());
    assertTrue(topicConfig instanceof UnwindowedChangelogTopicConfig);
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) Test(org.junit.Test)

Example 84 with MockProcessorSupplier

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

the class InternalTopologyBuilderTest method shouldAssociateStateStoreNameWhenStateStoreSupplierIsInternal.

@Test
public void shouldAssociateStateStoreNameWhenStateStoreSupplierIsInternal() throws Exception {
    builder.addSource(null, "source", null, null, null, "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 85 with MockProcessorSupplier

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

the class InternalTopologyBuilderTest method shouldConnectRegexMatchedTopicsToStateStore.

@Test
public void shouldConnectRegexMatchedTopicsToStateStore() throws Exception {
    builder.addSource(null, "ingest", null, null, null, Pattern.compile("topic-\\d+"));
    builder.addProcessor("my-processor", new MockProcessorSupplier(), "ingest");
    builder.addStateStore(new MockStateStoreSupplier("testStateStore", false), "my-processor");
    final InternalTopologyBuilder.SubscriptionUpdates subscriptionUpdates = new InternalTopologyBuilder.SubscriptionUpdates();
    final Field updatedTopicsField = subscriptionUpdates.getClass().getDeclaredField("updatedTopicSubscriptions");
    updatedTopicsField.setAccessible(true);
    final Set<String> updatedTopics = (Set<String>) updatedTopicsField.get(subscriptionUpdates);
    updatedTopics.add("topic-2");
    updatedTopics.add("topic-3");
    updatedTopics.add("topic-A");
    builder.updateSubscriptions(subscriptionUpdates, "test-thread");
    builder.setApplicationId("test-app");
    final Map<String, List<String>> stateStoreAndTopics = builder.stateStoreNameToSourceTopics();
    final List<String> topics = stateStoreAndTopics.get("testStateStore");
    assertTrue("Expected to contain two topics", topics.size() == 2);
    assertTrue(topics.contains("topic-2"));
    assertTrue(topics.contains("topic-3"));
    assertFalse(topics.contains("topic-A"));
}
Also used : Field(java.lang.reflect.Field) HashSet(java.util.HashSet) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) 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)

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