Search in sources :

Example 26 with ProcessorTopology

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

the class KStreamImplTest method shouldUseRecordMetadataTimestampExtractorWithRepartition.

@Test
public void shouldUseRecordMetadataTimestampExtractorWithRepartition() {
    final StreamsBuilder builder = new StreamsBuilder();
    final KStream<String, String> stream1 = builder.stream(Arrays.asList("topic-1", "topic-2"), stringConsumed);
    final KStream<String, String> stream2 = builder.stream(Arrays.asList("topic-3", "topic-4"), stringConsumed);
    stream1.to("topic-5");
    stream2.repartition(Repartitioned.as("topic-6"));
    final ProcessorTopology processorTopology = TopologyWrapper.getInternalTopologyBuilder(builder.build()).setApplicationId("X").buildTopology();
    assertThat(processorTopology.source("X-topic-6-repartition").getTimestampExtractor(), instanceOf(FailOnInvalidTimestamp.class));
    assertNull(processorTopology.source("topic-4").getTimestampExtractor());
    assertNull(processorTopology.source("topic-3").getTimestampExtractor());
    assertNull(processorTopology.source("topic-2").getTimestampExtractor());
    assertNull(processorTopology.source("topic-1").getTimestampExtractor());
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) FailOnInvalidTimestamp(org.apache.kafka.streams.processor.FailOnInvalidTimestamp) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 27 with ProcessorTopology

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

the class InternalStreamsBuilderTest method shouldNotMaterializeSourceKTableIfNotRequired.

@Test
public void shouldNotMaterializeSourceKTableIfNotRequired() {
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materializedInternal = new MaterializedInternal<>(Materialized.with(null, null), builder, storePrefix);
    final KTable<String, String> table1 = builder.table("topic2", consumed, materializedInternal);
    builder.buildAndOptimizeTopology();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(StreamsTestUtils.getStreamsConfig(APP_ID))).buildTopology();
    assertEquals(0, topology.stateStores().size());
    assertEquals(0, topology.storeToChangelogTopic().size());
    assertNull(table1.queryableStoreName());
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 28 with ProcessorTopology

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

the class InternalStreamsBuilderTest method shouldHaveNullTimestampExtractorWhenNoneSupplied.

@Test
public void shouldHaveNullTimestampExtractorWhenNoneSupplied() {
    builder.stream(Collections.singleton("topic"), consumed);
    builder.buildAndOptimizeTopology();
    builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(StreamsTestUtils.getStreamsConfig(APP_ID)));
    final ProcessorTopology processorTopology = builder.internalTopologyBuilder.buildTopology();
    assertNull(processorTopology.source("topic").getTimestampExtractor());
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 29 with ProcessorTopology

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

the class StreamsBuilderTest method shouldUseSpecifiedNameForSinkProcessor.

@Test
public void shouldUseSpecifiedNameForSinkProcessor() {
    final String expected = "sink-processor";
    final KStream<Object, Object> stream = builder.stream(STREAM_TOPIC);
    stream.to(STREAM_TOPIC_TWO, Produced.as(expected));
    stream.to(STREAM_TOPIC_TWO);
    builder.build();
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertNamesForOperation(topology, "KSTREAM-SOURCE-0000000000", expected, "KSTREAM-SINK-0000000002");
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Test(org.junit.Test)

Example 30 with ProcessorTopology

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

the class StreamsBuilderTest method shouldNotMaterializeStoresIfNotRequired.

@Test
public void shouldNotMaterializeStoresIfNotRequired() {
    final String topic = "topic";
    builder.table(topic, Materialized.with(Serdes.Long(), Serdes.String()));
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
    assertThat(topology.stateStores().size(), equalTo(0));
}
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