Search in sources :

Example 16 with MockProcessorSupplier

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

the class StreamPartitionAssignorTest method testAssignWithInternalTopics.

@Test
public void testAssignWithInternalTopics() throws Exception {
    String applicationId = "test";
    builder.setApplicationId(applicationId);
    builder.addInternalTopic("topicX");
    builder.addSource("source1", "topic1");
    builder.addProcessor("processor1", new MockProcessorSupplier(), "source1");
    builder.addSink("sink1", "topicX", "processor1");
    builder.addSource("source2", "topicX");
    builder.addProcessor("processor2", new MockProcessorSupplier(), "source2");
    List<String> topics = Utils.mkList("topic1", "test-topicX");
    Set<TaskId> allTasks = Utils.mkSet(task0, task1, task2);
    UUID uuid1 = UUID.randomUUID();
    String client1 = "client1";
    StreamThread thread10 = new StreamThread(builder, config, mockClientSupplier, applicationId, client1, uuid1, new Metrics(), Time.SYSTEM, new StreamsMetadataState(builder, StreamsMetadataState.UNKNOWN_HOST), 0);
    partitionAssignor.configure(config.getConsumerConfigs(thread10, applicationId, client1));
    MockInternalTopicManager internalTopicManager = new MockInternalTopicManager(thread10.config, mockClientSupplier.restoreConsumer);
    partitionAssignor.setInternalTopicManager(internalTopicManager);
    Map<String, PartitionAssignor.Subscription> subscriptions = new HashMap<>();
    Set<TaskId> emptyTasks = Collections.emptySet();
    subscriptions.put("consumer10", new PartitionAssignor.Subscription(topics, new SubscriptionInfo(uuid1, emptyTasks, emptyTasks, userEndPoint).encode()));
    partitionAssignor.assign(metadata, subscriptions);
    // check prepared internal topics
    assertEquals(1, internalTopicManager.readyTopics.size());
    assertEquals(allTasks.size(), (long) internalTopicManager.readyTopics.get("test-topicX"));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) HashMap(java.util.HashMap) MockInternalTopicManager(org.apache.kafka.test.MockInternalTopicManager) SubscriptionInfo(org.apache.kafka.streams.processor.internals.assignment.SubscriptionInfo) Metrics(org.apache.kafka.common.metrics.Metrics) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) PartitionAssignor(org.apache.kafka.clients.consumer.internals.PartitionAssignor) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with MockProcessorSupplier

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

the class TopologyTest method addProcessorWithStore.

private TopologyDescription.Processor addProcessorWithStore(final String processorName, final String[] storeNames, final boolean newStores, final TopologyDescription.Node... parents) {
    final String[] parentNames = new String[parents.length];
    for (int i = 0; i < parents.length; ++i) {
        parentNames[i] = parents[i].name();
    }
    topology.addProcessor(processorName, new MockProcessorSupplier(), parentNames);
    if (newStores) {
        for (final String store : storeNames) {
            final StoreBuilder storeBuilder = EasyMock.createNiceMock(StoreBuilder.class);
            EasyMock.expect(storeBuilder.name()).andReturn(store).anyTimes();
            EasyMock.replay(storeBuilder);
            topology.addStateStore(storeBuilder, processorName);
        }
    } else {
        topology.connectProcessorAndStateStores(processorName, storeNames);
    }
    final TopologyDescription.Processor expectedProcessorNode = new InternalTopologyBuilder.Processor(processorName, new HashSet<>(Arrays.asList(storeNames)));
    for (final TopologyDescription.Node parent : parents) {
        ((InternalTopologyBuilder.AbstractNode) parent).addSuccessor(expectedProcessorNode);
        ((InternalTopologyBuilder.AbstractNode) expectedProcessorNode).addPredecessor(parent);
    }
    return expectedProcessorNode;
}
Also used : Processor(org.apache.kafka.streams.processor.Processor) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) KeyValueStoreBuilder(org.apache.kafka.streams.state.internals.KeyValueStoreBuilder) StoreBuilder(org.apache.kafka.streams.state.StoreBuilder)

Example 18 with MockProcessorSupplier

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

the class TopologyTest method addGlobalStoreToTopologyAndExpectedDescription.

private void addGlobalStoreToTopologyAndExpectedDescription(final String globalStoreName, final String sourceName, final String globalTopicName, final String processorName, final int id) {
    final KeyValueStoreBuilder globalStoreBuilder = EasyMock.createNiceMock(KeyValueStoreBuilder.class);
    EasyMock.expect(globalStoreBuilder.name()).andReturn(globalStoreName).anyTimes();
    EasyMock.replay(globalStoreBuilder);
    topology.addGlobalStore(globalStoreBuilder, sourceName, null, null, null, globalTopicName, processorName, new MockProcessorSupplier());
    final TopologyDescription.GlobalStore expectedGlobalStore = new InternalTopologyBuilder.GlobalStore(sourceName, processorName, globalStoreName, globalTopicName, id);
    expectedDescription.addGlobalStore(expectedGlobalStore);
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) KeyValueStoreBuilder(org.apache.kafka.streams.state.internals.KeyValueStoreBuilder)

Example 19 with MockProcessorSupplier

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

the class TopologyTest method shouldNotAllowToAddProcessorWithSameName.

@Test
public void shouldNotAllowToAddProcessorWithSameName() {
    topology.addSource("source", "topic-1");
    topology.addProcessor("processor", new MockProcessorSupplier(), "source");
    try {
        topology.addProcessor("processor", new MockProcessorSupplier(), "source");
        fail("Should throw TopologyException for duplicate processor name");
    } catch (TopologyException expected) {
    }
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) TopologyException(org.apache.kafka.streams.errors.TopologyException) Test(org.junit.Test)

Example 20 with MockProcessorSupplier

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

the class TopologyTest method shouldNotAllowToAddGlobalStoreWithSourceNameEqualsProcessorName.

@Test(expected = TopologyException.class)
public void shouldNotAllowToAddGlobalStoreWithSourceNameEqualsProcessorName() {
    EasyMock.expect(globalStoreBuilder.name()).andReturn("anyName").anyTimes();
    EasyMock.replay(globalStoreBuilder);
    topology.addGlobalStore(globalStoreBuilder, "sameName", null, null, "anyTopicName", "sameName", new MockProcessorSupplier());
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) 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