Search in sources :

Example 6 with JoinWindows

use of org.apache.kafka.streams.kstream.JoinWindows in project kafka by apache.

the class KStreamKStreamJoinTest method shouldEnableLoggingWithCustomConfigOnStreamJoined.

@Test
public void shouldEnableLoggingWithCustomConfigOnStreamJoined() {
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceAndGrace(ofMillis(100), Duration.ofMillis(50));
    final StreamJoined<String, Integer, Integer> streamJoined = StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer()).withStoreName("store").withLoggingEnabled(Collections.singletonMap("test", "property"));
    final StreamsBuilder builder = new StreamsBuilder();
    final KStream<String, Integer> left = builder.stream("left", Consumed.with(Serdes.String(), Serdes.Integer()));
    final KStream<String, Integer> right = builder.stream("right", Consumed.with(Serdes.String(), Serdes.Integer()));
    left.join(right, Integer::sum, joinWindows, streamJoined);
    final Topology topology = builder.build();
    final InternalTopologyBuilder internalTopologyBuilder = TopologyWrapper.getInternalTopologyBuilder(topology);
    internalTopologyBuilder.buildSubtopology(0);
    assertThat(internalTopologyBuilder.stateStores().get("store-this-join-store").loggingEnabled(), equalTo(true));
    assertThat(internalTopologyBuilder.stateStores().get("store-other-join-store").loggingEnabled(), equalTo(true));
    assertThat(internalTopologyBuilder.subtopologyToTopicsInfo().get(SUBTOPOLOGY_0).stateChangelogTopics.size(), equalTo(2));
    for (final InternalTopicConfig config : internalTopologyBuilder.subtopologyToTopicsInfo().get(SUBTOPOLOGY_0).stateChangelogTopics.values()) {
        assertThat(config.getProperties(Collections.emptyMap(), 0).get("test"), equalTo("property"));
    }
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Topology(org.apache.kafka.streams.Topology) InternalTopicConfig(org.apache.kafka.streams.processor.internals.InternalTopicConfig) InternalTopologyBuilder(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder) Test(org.junit.Test)

Example 7 with JoinWindows

use of org.apache.kafka.streams.kstream.JoinWindows in project kafka by apache.

the class KStreamKStreamJoinTest method shouldDisableLoggingOnStreamJoined.

@Test
public void shouldDisableLoggingOnStreamJoined() {
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceAndGrace(ofMillis(100), Duration.ofMillis(50));
    final StreamJoined<String, Integer, Integer> streamJoined = StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer()).withStoreName("store").withLoggingDisabled();
    final StreamsBuilder builder = new StreamsBuilder();
    final KStream<String, Integer> left = builder.stream("left", Consumed.with(Serdes.String(), Serdes.Integer()));
    final KStream<String, Integer> right = builder.stream("right", Consumed.with(Serdes.String(), Serdes.Integer()));
    left.join(right, Integer::sum, joinWindows, streamJoined);
    final Topology topology = builder.build();
    final InternalTopologyBuilder internalTopologyBuilder = TopologyWrapper.getInternalTopologyBuilder(topology);
    assertThat(internalTopologyBuilder.stateStores().get("store-this-join-store").loggingEnabled(), equalTo(false));
    assertThat(internalTopologyBuilder.stateStores().get("store-other-join-store").loggingEnabled(), equalTo(false));
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Topology(org.apache.kafka.streams.Topology) InternalTopologyBuilder(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder) Test(org.junit.Test)

Example 8 with JoinWindows

use of org.apache.kafka.streams.kstream.JoinWindows in project kafka by apache.

the class KStreamKStreamJoinTest method shouldJoinWithCustomStoreSuppliers.

@Test
public void shouldJoinWithCustomStoreSuppliers() {
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceWithNoGrace(ofMillis(100L));
    final WindowBytesStoreSupplier thisStoreSupplier = Stores.inMemoryWindowStore("in-memory-join-store", Duration.ofMillis(joinWindows.size() + joinWindows.gracePeriodMs()), Duration.ofMillis(joinWindows.size()), true);
    final WindowBytesStoreSupplier otherStoreSupplier = Stores.inMemoryWindowStore("in-memory-join-store-other", Duration.ofMillis(joinWindows.size() + joinWindows.gracePeriodMs()), Duration.ofMillis(joinWindows.size()), true);
    final StreamJoined<String, Integer, Integer> streamJoined = StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
    // Case with 2 custom store suppliers
    runJoin(streamJoined.withThisStoreSupplier(thisStoreSupplier).withOtherStoreSupplier(otherStoreSupplier), joinWindows);
    // Case with this stream store supplier
    runJoin(streamJoined.withThisStoreSupplier(thisStoreSupplier), joinWindows);
    // Case with other stream store supplier
    runJoin(streamJoined.withOtherStoreSupplier(otherStoreSupplier), joinWindows);
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Test(org.junit.Test)

Example 9 with JoinWindows

use of org.apache.kafka.streams.kstream.JoinWindows in project kafka by apache.

the class KStreamKStreamLeftJoinTest method testLeftJoinWithDefaultSuppliers.

@Test
public void testLeftJoinWithDefaultSuppliers() {
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceWithNoGrace(ofMillis(100L));
    final StreamJoined<Integer, String, String> streamJoined = StreamJoined.with(Serdes.Integer(), Serdes.String(), Serdes.String());
    runLeftJoin(streamJoined, joinWindows);
}
Also used : JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Test(org.junit.Test)

Example 10 with JoinWindows

use of org.apache.kafka.streams.kstream.JoinWindows in project kafka by apache.

the class TopologyTest method streamStreamLeftJoinTopologyWithCustomStoresSuppliers.

@Test
public void streamStreamLeftJoinTopologyWithCustomStoresSuppliers() {
    final StreamsBuilder builder = new StreamsBuilder();
    final KStream<Integer, String> stream1;
    final KStream<Integer, String> stream2;
    stream1 = builder.stream("input-topic1");
    stream2 = builder.stream("input-topic2");
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceWithNoGrace(ofMillis(100));
    final WindowBytesStoreSupplier thisStoreSupplier = Stores.inMemoryWindowStore("in-memory-join-store", Duration.ofMillis(joinWindows.size() + joinWindows.gracePeriodMs()), Duration.ofMillis(joinWindows.size()), true);
    final WindowBytesStoreSupplier otherStoreSupplier = Stores.inMemoryWindowStore("in-memory-join-store-other", Duration.ofMillis(joinWindows.size() + joinWindows.gracePeriodMs()), Duration.ofMillis(joinWindows.size()), true);
    stream1.leftJoin(stream2, MockValueJoiner.TOSTRING_JOINER, joinWindows, StreamJoined.with(Serdes.Integer(), Serdes.String(), Serdes.String()).withThisStoreSupplier(thisStoreSupplier).withOtherStoreSupplier(otherStoreSupplier));
    final TopologyDescription describe = builder.build().describe();
    assertEquals("Topologies:\n" + "   Sub-topology: 0\n" + "    Source: KSTREAM-SOURCE-0000000000 (topics: [input-topic1])\n" + "      --> KSTREAM-WINDOWED-0000000002\n" + "    Source: KSTREAM-SOURCE-0000000001 (topics: [input-topic2])\n" + "      --> KSTREAM-WINDOWED-0000000003\n" + "    Processor: KSTREAM-WINDOWED-0000000002 (stores: [in-memory-join-store])\n" + "      --> KSTREAM-JOINTHIS-0000000004\n" + "      <-- KSTREAM-SOURCE-0000000000\n" + "    Processor: KSTREAM-WINDOWED-0000000003 (stores: [in-memory-join-store-other])\n" + "      --> KSTREAM-OUTEROTHER-0000000005\n" + "      <-- KSTREAM-SOURCE-0000000001\n" + "    Processor: KSTREAM-JOINTHIS-0000000004 (stores: [in-memory-join-store-other, in-memory-join-store-left-shared-join-store])\n" + "      --> KSTREAM-MERGE-0000000006\n" + "      <-- KSTREAM-WINDOWED-0000000002\n" + "    Processor: KSTREAM-OUTEROTHER-0000000005 (stores: [in-memory-join-store, in-memory-join-store-left-shared-join-store])\n" + "      --> KSTREAM-MERGE-0000000006\n" + "      <-- KSTREAM-WINDOWED-0000000003\n" + "    Processor: KSTREAM-MERGE-0000000006 (stores: [])\n" + "      --> none\n" + "      <-- KSTREAM-JOINTHIS-0000000004, KSTREAM-OUTEROTHER-0000000005\n\n", describe.toString());
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Test(org.junit.Test)

Aggregations

JoinWindows (org.apache.kafka.streams.kstream.JoinWindows)13 Test (org.junit.Test)12 WindowBytesStoreSupplier (org.apache.kafka.streams.state.WindowBytesStoreSupplier)7 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)2 Topology (org.apache.kafka.streams.Topology)2 InternalTopologyBuilder (org.apache.kafka.streams.processor.internals.InternalTopologyBuilder)2 GenericRow (io.confluent.ksql.GenericRow)1 QueryContext (io.confluent.ksql.execution.context.QueryContext)1 Formats (io.confluent.ksql.execution.plan.Formats)1 JoinType (io.confluent.ksql.execution.plan.JoinType)1 WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)1 WithinExpression (io.confluent.ksql.parser.tree.WithinExpression)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)1 Pair (io.confluent.ksql.util.Pair)1 InternalTopicConfig (org.apache.kafka.streams.processor.internals.InternalTopicConfig)1