Search in sources :

Example 16 with Consumed

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

the class InternalStreamsBuilderTest method shouldAddGlobalTablesToEachGroup.

@Test
public void shouldAddGlobalTablesToEachGroup() {
    final String one = "globalTable";
    final String two = "globalTable2";
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materializedInternal = new MaterializedInternal<>(Materialized.as(one), builder, storePrefix);
    final GlobalKTable<String, String> globalTable = builder.globalTable("table", consumed, materializedInternal);
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materializedInternal2 = new MaterializedInternal<>(Materialized.as(two), builder, storePrefix);
    final GlobalKTable<String, String> globalTable2 = builder.globalTable("table2", consumed, materializedInternal2);
    final MaterializedInternal<String, String, KeyValueStore<Bytes, byte[]>> materializedInternalNotGlobal = new MaterializedInternal<>(Materialized.as("not-global"), builder, storePrefix);
    builder.table("not-global", consumed, materializedInternalNotGlobal);
    final KeyValueMapper<String, String, String> kvMapper = (key, value) -> value;
    final KStream<String, String> stream = builder.stream(Collections.singleton("t1"), consumed);
    stream.leftJoin(globalTable, kvMapper, MockValueJoiner.TOSTRING_JOINER);
    final KStream<String, String> stream2 = builder.stream(Collections.singleton("t2"), consumed);
    stream2.leftJoin(globalTable2, kvMapper, MockValueJoiner.TOSTRING_JOINER);
    final Map<Integer, Set<String>> nodeGroups = builder.internalTopologyBuilder.nodeGroups();
    for (final Integer groupId : nodeGroups.keySet()) {
        final ProcessorTopology topology = builder.internalTopologyBuilder.buildSubtopology(groupId);
        final List<StateStore> stateStores = topology.globalStateStores();
        final Set<String> names = new HashSet<>();
        for (final StateStore stateStore : stateStores) {
            names.add(stateStore.name());
        }
        assertEquals(2, stateStores.size());
        assertTrue(names.contains(one));
        assertTrue(names.contains(two));
    }
}
Also used : StreamsConfig(org.apache.kafka.streams.StreamsConfig) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) KStream(org.apache.kafka.streams.kstream.KStream) AutoOffsetReset(org.apache.kafka.streams.Topology.AutoOffsetReset) OffsetResetStrategy(org.apache.kafka.clients.consumer.OffsetResetStrategy) HashSet(java.util.HashSet) Arrays.asList(java.util.Arrays.asList) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Utils(org.apache.kafka.common.utils.Utils) MockValueJoiner(org.apache.kafka.test.MockValueJoiner) MockMapper(org.apache.kafka.test.MockMapper) KTable(org.apache.kafka.streams.kstream.KTable) KeyValueMapper(org.apache.kafka.streams.kstream.KeyValueMapper) Consumed(org.apache.kafka.streams.kstream.Consumed) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Bytes(org.apache.kafka.common.utils.Bytes) MockTimestampExtractor(org.apache.kafka.test.MockTimestampExtractor) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) GlobalKTable(org.apache.kafka.streams.kstream.GlobalKTable) StateStore(org.apache.kafka.streams.processor.StateStore) Materialized(org.apache.kafka.streams.kstream.Materialized) InternalTopologyBuilder(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder) StreamsTestUtils(org.apache.kafka.test.StreamsTestUtils) Pattern(java.util.regex.Pattern) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) HashSet(java.util.HashSet) Set(java.util.Set) StateStore(org.apache.kafka.streams.processor.StateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Consumed (org.apache.kafka.streams.kstream.Consumed)16 KTable (org.apache.kafka.streams.kstream.KTable)16 Properties (java.util.Properties)15 Serdes (org.apache.kafka.common.serialization.Serdes)15 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)15 Materialized (org.apache.kafka.streams.kstream.Materialized)15 Assert.assertEquals (org.junit.Assert.assertEquals)14 Test (org.junit.Test)14 Duration (java.time.Duration)13 KeyValueTimestamp (org.apache.kafka.streams.KeyValueTimestamp)13 TestInputTopic (org.apache.kafka.streams.TestInputTopic)13 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)13 MockApiProcessor (org.apache.kafka.test.MockApiProcessor)13 MockApiProcessorSupplier (org.apache.kafka.test.MockApiProcessorSupplier)13 Instant (java.time.Instant)12 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)12 Bytes (org.apache.kafka.common.utils.Bytes)12 StreamsTestUtils (org.apache.kafka.test.StreamsTestUtils)12 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)12 Arrays.asList (java.util.Arrays.asList)11