Search in sources :

Example 1 with JoinWindows

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

the class KStreamKStreamJoinTest method shouldExceptionWhenJoinStoresDoNotHaveUniqueNames.

@Test
public void shouldExceptionWhenJoinStoresDoNotHaveUniqueNames() {
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceAndGrace(ofMillis(100L), Duration.ofMillis(50L));
    final StreamJoined<String, Integer, Integer> streamJoined = StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
    final WindowBytesStoreSupplier thisStoreSupplier = buildWindowBytesStoreSupplier("in-memory-join-store", 150L, 100L, true);
    final WindowBytesStoreSupplier otherStoreSupplier = buildWindowBytesStoreSupplier("in-memory-join-store", 150L, 100L, true);
    buildStreamsJoinThatShouldThrow(streamJoined.withThisStoreSupplier(thisStoreSupplier).withOtherStoreSupplier(otherStoreSupplier), joinWindows, "Both StoreSuppliers have the same name.  StoreSuppliers must provide unique names");
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Test(org.junit.Test)

Example 2 with JoinWindows

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

the class KStreamKStreamLeftJoinTest method testLeftJoinWithInMemoryCustomSuppliers.

@Test
public void testLeftJoinWithInMemoryCustomSuppliers() {
    final JoinWindows joinWindows = JoinWindows.ofTimeDifferenceAndGrace(ofMillis(100L), ofMillis(0L));
    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<Integer, String, String> streamJoined = StreamJoined.with(Serdes.Integer(), Serdes.String(), Serdes.String());
    runLeftJoin(streamJoined.withThisStoreSupplier(thisStoreSupplier).withOtherStoreSupplier(otherStoreSupplier), joinWindows);
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Test(org.junit.Test)

Example 3 with JoinWindows

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

the class KStreamKStreamOuterJoinTest method testOuterJoinWithInMemoryCustomSuppliers.

@Test
public void testOuterJoinWithInMemoryCustomSuppliers() {
    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<Integer, String, String> streamJoined = StreamJoined.with(Serdes.Integer(), Serdes.String(), Serdes.String());
    runOuterJoin(streamJoined.withThisStoreSupplier(thisStoreSupplier).withOtherStoreSupplier(otherStoreSupplier), joinWindows);
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) Test(org.junit.Test)

Example 4 with JoinWindows

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

the class KStreamKStreamOuterJoinTest method testOuterJoinWithDefaultSuppliers.

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

Example 5 with JoinWindows

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

the class TopologyTest method streamStreamJoinTopologyWithCustomStoresSuppliers.

@Test
public void streamStreamJoinTopologyWithCustomStoresSuppliers() {
    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.of(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.join(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-JOINOTHER-0000000005\n" + "      <-- KSTREAM-SOURCE-0000000001\n" + "    Processor: KSTREAM-JOINOTHER-0000000005 (stores: [in-memory-join-store])\n" + "      --> KSTREAM-MERGE-0000000006\n" + "      <-- KSTREAM-WINDOWED-0000000003\n" + "    Processor: KSTREAM-JOINTHIS-0000000004 (stores: [in-memory-join-store-other])\n" + "      --> KSTREAM-MERGE-0000000006\n" + "      <-- KSTREAM-WINDOWED-0000000002\n" + "    Processor: KSTREAM-MERGE-0000000006 (stores: [])\n" + "      --> none\n" + "      <-- KSTREAM-JOINTHIS-0000000004, KSTREAM-JOINOTHER-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)11 Test (org.junit.Test)11 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 InternalTopicConfig (org.apache.kafka.streams.processor.internals.InternalTopicConfig)1