Search in sources :

Example 81 with ProcessorTopology

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

the class StreamsBuilderTest method shouldUseGeneratedNameForJoinOperationBetweenKStreamAndKStream.

@SuppressWarnings("deprecation")
@Test
public void shouldUseGeneratedNameForJoinOperationBetweenKStreamAndKStream() {
    final KStream<String, String> streamOne = builder.stream(STREAM_TOPIC);
    final KStream<String, String> streamTwo = builder.stream(STREAM_TOPIC_TWO);
    streamOne.join(streamTwo, (value1, value2) -> value1, JoinWindows.of(Duration.ofHours(1)), StreamJoined.with(Serdes.String(), Serdes.String(), Serdes.String()).withName(STREAM_OPERATION_NAME));
    builder.build();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertNamesForStateStore(topology.stateStores(), "KSTREAM-JOINTHIS-0000000004-store", "KSTREAM-JOINOTHER-0000000005-store");
    assertNamesForOperation(topology, "KSTREAM-SOURCE-0000000000", "KSTREAM-SOURCE-0000000001", STREAM_OPERATION_NAME + "-this-windowed", STREAM_OPERATION_NAME + "-other-windowed", STREAM_OPERATION_NAME + "-this-join", STREAM_OPERATION_NAME + "-other-join", STREAM_OPERATION_NAME + "-merge");
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Example 82 with ProcessorTopology

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

the class StreamsBuilderTest method shouldUseSpecifiedNameForTableSourceProcessor.

@Test
public void shouldUseSpecifiedNameForTableSourceProcessor() {
    final String expected = "source-node";
    builder.table(STREAM_TOPIC, Consumed.as(expected));
    builder.table(STREAM_TOPIC_TWO);
    builder.build();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertNamesForOperation(topology, expected + "-source", expected, "KSTREAM-SOURCE-0000000004", "KTABLE-SOURCE-0000000005");
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Example 83 with ProcessorTopology

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

the class StreamsBuilderTest method shouldAllowJoinMaterializedJoinedKTable.

@Test
public void shouldAllowJoinMaterializedJoinedKTable() {
    final KTable<Bytes, String> table1 = builder.table("table-topic1");
    final KTable<Bytes, String> table2 = builder.table("table-topic2");
    builder.<Bytes, String>stream(STREAM_TOPIC).join(table1.join(table2, MockValueJoiner.TOSTRING_JOINER, Materialized.as("store")), MockValueJoiner.TOSTRING_JOINER);
    builder.build();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertThat(topology.stateStores().size(), equalTo(3));
    assertThat(topology.processorConnectedStateStores("KSTREAM-JOIN-0000000010"), equalTo(Collections.singleton("store")));
    assertThat(topology.processorConnectedStateStores("KTABLE-MERGE-0000000007"), equalTo(Collections.singleton("store")));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Example 84 with ProcessorTopology

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

the class StreamsBuilderTest method shouldAllowJoinMaterializedSourceKTable.

@Test
public void shouldAllowJoinMaterializedSourceKTable() {
    final KTable<Bytes, String> table = builder.table(TABLE_TOPIC);
    builder.<Bytes, String>stream(STREAM_TOPIC).join(table, MockValueJoiner.TOSTRING_JOINER);
    builder.build();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertThat(topology.stateStores().size(), equalTo(1));
    assertThat(topology.processorConnectedStateStores("KTABLE-SOURCE-0000000002"), equalTo(Collections.singleton(topology.stateStores().get(0).name())));
    assertThat(topology.processorConnectedStateStores("KSTREAM-JOIN-0000000004"), equalTo(Collections.singleton(topology.stateStores().get(0).name())));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Example 85 with ProcessorTopology

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

the class StreamsBuilderTest method shouldAllowJoinUnmaterializedMapValuedKTable.

@Test
public void shouldAllowJoinUnmaterializedMapValuedKTable() {
    final KTable<Bytes, String> mappedKTable = builder.<Bytes, String>table(TABLE_TOPIC).mapValues(MockMapper.noOpValueMapper());
    builder.<Bytes, String>stream(STREAM_TOPIC).join(mappedKTable, MockValueJoiner.TOSTRING_JOINER);
    builder.build();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertThat(topology.stateStores().size(), equalTo(1));
    assertThat(topology.processorConnectedStateStores("KSTREAM-JOIN-0000000005"), equalTo(Collections.singleton(topology.stateStores().get(0).name())));
    assertTrue(topology.processorConnectedStateStores("KTABLE-MAPVALUES-0000000003").isEmpty());
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Aggregations

ProcessorTopology (org.apache.kafka.streams.processor.internals.ProcessorTopology)95 Test (org.junit.Test)89 Bytes (org.apache.kafka.common.utils.Bytes)17 MockTimestampExtractor (org.apache.kafka.test.MockTimestampExtractor)14 StateStore (org.apache.kafka.streams.processor.StateStore)13 StreamsConfig (org.apache.kafka.streams.StreamsConfig)10 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)8 FailOnInvalidTimestamp (org.apache.kafka.streams.processor.FailOnInvalidTimestamp)6 Pattern (java.util.regex.Pattern)5 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)5 HashSet (java.util.HashSet)4 Properties (java.util.Properties)4 Set (java.util.Set)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 List (java.util.List)3 KTable (org.apache.kafka.streams.kstream.KTable)3 InternalTopologyBuilder (org.apache.kafka.streams.processor.internals.InternalTopologyBuilder)3 SourceNode (org.apache.kafka.streams.processor.internals.SourceNode)3 Arrays.asList (java.util.Arrays.asList)2 Collections (java.util.Collections)2