Search in sources :

Example 51 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology in project apache-kafka-on-k8s by banzaicloud.

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);
    driver.setUp(builder, TestUtils.tempDirectory());
    ProcessorTopology topology = builder.internalTopologyBuilder.build();
    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 52 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology in project apache-kafka-on-k8s by banzaicloud.

the class StreamsBuilderTest method shouldAllowJoinUnmaterializedFilteredKTable.

@Test
public void shouldAllowJoinUnmaterializedFilteredKTable() {
    final KTable<Bytes, String> filteredKTable = builder.<Bytes, String>table("table-topic").filter(MockPredicate.<Bytes, String>allGoodPredicate());
    builder.<Bytes, String>stream("stream-topic").join(filteredKTable, MockValueJoiner.TOSTRING_JOINER);
    driver.setUp(builder, TestUtils.tempDirectory());
    ProcessorTopology topology = builder.internalTopologyBuilder.build();
    assertThat(topology.stateStores().size(), equalTo(1));
    assertThat(topology.processorConnectedStateStores("KSTREAM-JOIN-0000000005"), equalTo(Collections.singleton(topology.stateStores().get(0).name())));
    assertThat(topology.processorConnectedStateStores("KTABLE-FILTER-0000000003").isEmpty(), is(true));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Example 53 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology in project apache-kafka-on-k8s by banzaicloud.

the class KStreamImplTest method shouldUseRecordMetadataTimestampExtractorWithThrough.

@Test
public void shouldUseRecordMetadataTimestampExtractorWithThrough() {
    final StreamsBuilder builder = new StreamsBuilder();
    final Consumed<String, String> consumed = Consumed.with(stringSerde, stringSerde);
    KStream<String, String> stream1 = builder.stream(Arrays.asList("topic-1", "topic-2"), consumed);
    KStream<String, String> stream2 = builder.stream(Arrays.asList("topic-3", "topic-4"), consumed);
    stream1.to("topic-5");
    stream2.through("topic-6");
    ProcessorTopology processorTopology = StreamsBuilderTest.internalTopologyBuilder(builder).setApplicationId("X").build(null);
    assertThat(processorTopology.source("topic-6").getTimestampExtractor(), instanceOf(FailOnInvalidTimestamp.class));
    assertEquals(processorTopology.source("topic-4").getTimestampExtractor(), null);
    assertEquals(processorTopology.source("topic-3").getTimestampExtractor(), null);
    assertEquals(processorTopology.source("topic-2").getTimestampExtractor(), null);
    assertEquals(processorTopology.source("topic-1").getTimestampExtractor(), null);
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) FailOnInvalidTimestamp(org.apache.kafka.streams.processor.FailOnInvalidTimestamp) StreamsBuilderTest(org.apache.kafka.streams.StreamsBuilderTest) Test(org.junit.Test)

Example 54 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology in project apache-kafka-on-k8s by banzaicloud.

the class KStreamBuilderTest method doBuildGlobalTopologyWithAllGlobalTables.

private void doBuildGlobalTopologyWithAllGlobalTables() {
    final ProcessorTopology topology = builder.buildGlobalStateTopology();
    final List<StateStore> stateStores = topology.globalStateStores();
    final Set<String> sourceTopics = topology.sourceTopics();
    assertEquals(Utils.mkSet("table", "table2"), sourceTopics);
    assertEquals(2, stateStores.size());
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) StateStore(org.apache.kafka.streams.processor.StateStore)

Example 55 with ProcessorTopology

use of org.apache.kafka.streams.processor.internals.ProcessorTopology in project apache-kafka-on-k8s by banzaicloud.

the class KStreamBuilderTest method shouldAddTimestampExtractorToTablePerSource.

@Test
public void shouldAddTimestampExtractorToTablePerSource() {
    builder.table("topic", "store");
    final ProcessorTopology processorTopology = builder.build(null);
    assertNull(processorTopology.source("topic").getTimestampExtractor());
}
Also used : 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