Search in sources :

Example 66 with ProcessorTopology

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

the class KStreamImplTest method shouldUseRecordMetadataTimestampExtractorWithThrough.

@Deprecated
@Test
public void shouldUseRecordMetadataTimestampExtractorWithThrough() {
    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.through("topic-6");
    final ProcessorTopology processorTopology = TopologyWrapper.getInternalTopologyBuilder(builder.build()).setApplicationId("X").buildTopology();
    assertThat(processorTopology.source("topic-6").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 67 with ProcessorTopology

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

the class KStreamImplTest method shouldUseRecordMetadataTimestampExtractorWhenInternalRepartitioningTopicCreatedWithRetention.

@SuppressWarnings("deprecation")
@Test
public void shouldUseRecordMetadataTimestampExtractorWhenInternalRepartitioningTopicCreatedWithRetention() {
    final StreamsBuilder builder = new StreamsBuilder();
    final KStream<String, String> kStream = builder.stream("topic-1", stringConsumed);
    final ValueJoiner<String, String, String> valueJoiner = MockValueJoiner.instance(":");
    final long windowSize = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
    final KStream<String, String> stream = kStream.map((key, value) -> KeyValue.pair(value, value));
    stream.join(kStream, valueJoiner, JoinWindows.of(ofMillis(windowSize)).grace(ofMillis(3 * windowSize)), StreamJoined.with(Serdes.String(), Serdes.String(), Serdes.String())).to("output-topic", Produced.with(Serdes.String(), Serdes.String()));
    final ProcessorTopology topology = TopologyWrapper.getInternalTopologyBuilder(builder.build()).setApplicationId("X").buildTopology();
    final SourceNode<?, ?> originalSourceNode = topology.source("topic-1");
    for (final SourceNode<?, ?> sourceNode : topology.sources()) {
        if (sourceNode.name().equals(originalSourceNode.name())) {
            assertNull(sourceNode.getTimestampExtractor());
        } else {
            assertThat(sourceNode.getTimestampExtractor(), instanceOf(FailOnInvalidTimestamp.class));
        }
    }
}
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 68 with ProcessorTopology

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

the class InternalStreamsBuilderTest method doBuildGlobalTopologyWithAllGlobalTables.

private void doBuildGlobalTopologyWithAllGlobalTables() {
    final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(StreamsTestUtils.getStreamsConfig(APP_ID))).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) StreamsConfig(org.apache.kafka.streams.StreamsConfig)

Example 69 with ProcessorTopology

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

the class InternalStreamsBuilderTest method shouldUseProvidedTimestampExtractor.

@Test
public void shouldUseProvidedTimestampExtractor() {
    final ConsumedInternal<String, String> consumed = new ConsumedInternal<>(Consumed.with(new MockTimestampExtractor()));
    builder.stream(Collections.singleton("topic"), consumed);
    builder.buildAndOptimizeTopology();
    final ProcessorTopology processorTopology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(StreamsTestUtils.getStreamsConfig(APP_ID))).buildTopology();
    assertThat(processorTopology.source("topic").getTimestampExtractor(), instanceOf(MockTimestampExtractor.class));
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) MockTimestampExtractor(org.apache.kafka.test.MockTimestampExtractor) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 70 with ProcessorTopology

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

the class InternalStreamsBuilderTest method ktableShouldUseProvidedTimestampExtractor.

@Test
public void ktableShouldUseProvidedTimestampExtractor() {
    final ConsumedInternal<String, String> consumed = new ConsumedInternal<>(Consumed.with(new MockTimestampExtractor()));
    builder.table("topic", consumed, materialized);
    builder.buildAndOptimizeTopology();
    final ProcessorTopology processorTopology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(StreamsTestUtils.getStreamsConfig(APP_ID))).buildTopology();
    assertThat(processorTopology.source("topic").getTimestampExtractor(), instanceOf(MockTimestampExtractor.class));
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) MockTimestampExtractor(org.apache.kafka.test.MockTimestampExtractor) StreamsConfig(org.apache.kafka.streams.StreamsConfig) 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