Search in sources :

Example 6 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology 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 7 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology in project kafka by apache.

the class StreamThreadStateStoreProviderTest method before.

@Before
public void before() throws IOException {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.addSource("the-source", "the-source");
    builder.addProcessor("the-processor", new MockProcessorSupplier(), "the-source");
    builder.addStateStore(Stores.create("kv-store").withStringKeys().withStringValues().inMemory().build(), "the-processor");
    builder.addStateStore(Stores.create("window-store").withStringKeys().withStringValues().persistent().windowed(10, 10, 2, false).build(), "the-processor");
    final Properties properties = new Properties();
    final String applicationId = "applicationId";
    properties.put(StreamsConfig.APPLICATION_ID_CONFIG, applicationId);
    properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    stateDir = TestUtils.tempDirectory();
    final String stateConfigDir = stateDir.getPath();
    properties.put(StreamsConfig.STATE_DIR_CONFIG, stateConfigDir);
    final StreamsConfig streamsConfig = new StreamsConfig(properties);
    final MockClientSupplier clientSupplier = new MockClientSupplier();
    configureRestoreConsumer(clientSupplier, "applicationId-kv-store-changelog");
    configureRestoreConsumer(clientSupplier, "applicationId-window-store-changelog");
    builder.setApplicationId(applicationId);
    final ProcessorTopology topology = builder.build(null);
    final Map<TaskId, StreamTask> tasks = new HashMap<>();
    stateDirectory = new StateDirectory(applicationId, stateConfigDir, new MockTime());
    taskOne = createStreamsTask(applicationId, streamsConfig, clientSupplier, topology, new TaskId(0, 0));
    tasks.put(new TaskId(0, 0), taskOne);
    taskTwo = createStreamsTask(applicationId, streamsConfig, clientSupplier, topology, new TaskId(0, 1));
    tasks.put(new TaskId(0, 1), taskTwo);
    storesAvailable = true;
    thread = new StreamThread(builder, streamsConfig, clientSupplier, applicationId, "clientId", UUID.randomUUID(), new Metrics(), Time.SYSTEM, new StreamsMetadataState(builder, StreamsMetadataState.UNKNOWN_HOST), 0) {

        @Override
        public Map<TaskId, StreamTask> tasks() {
            return tasks;
        }

        @Override
        public boolean isInitialized() {
            return storesAvailable;
        }
    };
    provider = new StreamThreadStateStoreProvider(thread);
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) TaskId(org.apache.kafka.streams.processor.TaskId) TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) HashMap(java.util.HashMap) StreamThread(org.apache.kafka.streams.processor.internals.StreamThread) Properties(java.util.Properties) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) StreamsMetadataState(org.apache.kafka.streams.processor.internals.StreamsMetadataState) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) MockClientSupplier(org.apache.kafka.test.MockClientSupplier) HashMap(java.util.HashMap) Map(java.util.Map) StreamTask(org.apache.kafka.streams.processor.internals.StreamTask) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig) StateDirectory(org.apache.kafka.streams.processor.internals.StateDirectory) Before(org.junit.Before)

Aggregations

ProcessorTopology (org.apache.kafka.streams.processor.internals.ProcessorTopology)7 Test (org.junit.Test)5 StateStore (org.apache.kafka.streams.processor.StateStore)3 HashMap (java.util.HashMap)2 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 MockTime (org.apache.kafka.common.utils.MockTime)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 TopologyBuilderException (org.apache.kafka.streams.errors.TopologyBuilderException)1 TaskId (org.apache.kafka.streams.processor.TaskId)1 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)1 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)1 ProcessorNode (org.apache.kafka.streams.processor.internals.ProcessorNode)1