Search in sources :

Example 11 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project kafka by apache.

the class StreamsMetadataStateTest method shouldGetInstanceWithKey.

@Test
public void shouldGetInstanceWithKey() throws Exception {
    final TopicPartition tp4 = new TopicPartition("topic-three", 1);
    hostToPartitions.put(hostTwo, Utils.mkSet(topic2P0, tp4));
    discovery.onChange(hostToPartitions, cluster.withPartitions(Collections.singletonMap(tp4, new PartitionInfo("topic-three", 1, null, null, null))));
    final StreamsMetadata expected = new StreamsMetadata(hostThree, Utils.mkSet(globalTable, "table-three"), Collections.singleton(topic3P0));
    final StreamsMetadata actual = discovery.getMetadataWithKey("table-three", "the-key", Serdes.String().serializer());
    assertEquals(expected, actual);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) PartitionInfo(org.apache.kafka.common.PartitionInfo) Test(org.junit.Test)

Example 12 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project kafka by apache.

the class StreamsMetadataStateTest method shouldGetMyMetadataForGlobalStoreWithKey.

@Test
public void shouldGetMyMetadataForGlobalStoreWithKey() throws Exception {
    final StreamsMetadata metadata = discovery.getMetadataWithKey(globalTable, "key", Serdes.String().serializer());
    assertEquals(hostOne, metadata.hostInfo());
}
Also used : StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) Test(org.junit.Test)

Example 13 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project kafka by apache.

the class StreamsMetadataStateTest method shouldGetInstanceWithKeyWithMergedStreams.

@Test
public void shouldGetInstanceWithKeyWithMergedStreams() throws Exception {
    final TopicPartition topic2P2 = new TopicPartition("topic-two", 2);
    hostToPartitions.put(hostTwo, Utils.mkSet(topic2P0, topic1P1, topic2P2));
    discovery.onChange(hostToPartitions, cluster.withPartitions(Collections.singletonMap(topic2P2, new PartitionInfo("topic-two", 2, null, null, null))));
    final StreamsMetadata expected = new StreamsMetadata(hostTwo, Utils.mkSet("global-table", "table-two", "table-one", "merged-table"), Utils.mkSet(topic2P0, topic1P1, topic2P2));
    final StreamsMetadata actual = discovery.getMetadataWithKey("merged-table", "123", new StreamPartitioner<String, Object>() {

        @Override
        public Integer partition(final String key, final Object value, final int numPartitions) {
            return 2;
        }
    });
    assertEquals(expected, actual);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) PartitionInfo(org.apache.kafka.common.PartitionInfo) Test(org.junit.Test)

Example 14 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project kafka by apache.

the class StreamsMetadataStateTest method shouldHaveGlobalStoreInAllMetadata.

@Test
public void shouldHaveGlobalStoreInAllMetadata() throws Exception {
    final Collection<StreamsMetadata> metadata = discovery.getAllMetadataForStore(globalTable);
    assertEquals(3, metadata.size());
    for (StreamsMetadata streamsMetadata : metadata) {
        assertTrue(streamsMetadata.stateStoreNames().contains(globalTable));
    }
}
Also used : StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) Test(org.junit.Test)

Aggregations

StreamsMetadata (org.apache.kafka.streams.state.StreamsMetadata)14 Test (org.junit.Test)11 TopicPartition (org.apache.kafka.common.TopicPartition)7 PartitionInfo (org.apache.kafka.common.PartitionInfo)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 HostInfo (org.apache.kafka.streams.state.HostInfo)2 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Predicate (org.apache.kafka.streams.kstream.Predicate)1