Search in sources :

Example 1 with StreamsMetadata

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

the class StreamsMetadataState method getStreamsMetadataForKey.

private <K> StreamsMetadata getStreamsMetadataForKey(final String storeName, final K key, final StreamPartitioner<? super K, ?> partitioner, final SourceTopicsInfo sourceTopicsInfo) {
    final Integer partition = partitioner.partition(key, null, sourceTopicsInfo.maxPartitions);
    final Set<TopicPartition> matchingPartitions = new HashSet<>();
    for (String sourceTopic : sourceTopicsInfo.sourceTopics) {
        matchingPartitions.add(new TopicPartition(sourceTopic, partition));
    }
    for (StreamsMetadata streamsMetadata : allMetadata) {
        final Set<String> stateStoreNames = streamsMetadata.stateStoreNames();
        final Set<TopicPartition> topicPartitions = new HashSet<>(streamsMetadata.topicPartitions());
        topicPartitions.retainAll(matchingPartitions);
        if (stateStoreNames.contains(storeName) && !topicPartitions.isEmpty()) {
            return streamsMetadata;
        }
    }
    return null;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) HashSet(java.util.HashSet)

Example 2 with StreamsMetadata

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

the class StreamsMetadataStateTest method shouldGetMyMetadataForGlobalStoreWithKeyAndPartitioner.

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

Example 3 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project apache-kafka-on-k8s by banzaicloud.

the class StreamsMetadataStateTest method shouldReturnNotAvailableWhenClusterIsEmpty.

@Test
public void shouldReturnNotAvailableWhenClusterIsEmpty() {
    discovery.onChange(Collections.<HostInfo, Set<TopicPartition>>emptyMap(), Cluster.empty());
    final StreamsMetadata result = discovery.getMetadataWithKey("table-one", "a", Serdes.String().serializer());
    assertEquals(StreamsMetadata.NOT_AVAILABLE, result);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) StreamsBuilderTest(org.apache.kafka.streams.StreamsBuilderTest) Test(org.junit.Test)

Example 4 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project apache-kafka-on-k8s by banzaicloud.

the class StreamsMetadataStateTest method shouldReturnNullOnGetWithKeyWhenStoreDoesntExist.

@Test
public void shouldReturnNullOnGetWithKeyWhenStoreDoesntExist() {
    final StreamsMetadata actual = discovery.getMetadataWithKey("not-a-store", "key", Serdes.String().serializer());
    assertNull(actual);
}
Also used : StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) StreamsBuilderTest(org.apache.kafka.streams.StreamsBuilderTest) Test(org.junit.Test)

Example 5 with StreamsMetadata

use of org.apache.kafka.streams.state.StreamsMetadata in project apache-kafka-on-k8s by banzaicloud.

the class StreamsMetadataStateTest method shouldGetInstancesForStoreName.

@Test
public void shouldGetInstancesForStoreName() {
    final StreamsMetadata one = new StreamsMetadata(hostOne, Utils.mkSet(globalTable, "table-one", "table-two", "merged-table"), Utils.mkSet(topic1P0, topic2P1, topic4P0));
    final StreamsMetadata two = new StreamsMetadata(hostTwo, Utils.mkSet(globalTable, "table-two", "table-one", "merged-table"), Utils.mkSet(topic2P0, topic1P1));
    final Collection<StreamsMetadata> actual = discovery.getAllMetadataForStore("table-one");
    assertEquals(2, actual.size());
    assertTrue("expected " + actual + " to contain " + one, actual.contains(one));
    assertTrue("expected " + actual + " to contain " + two, actual.contains(two));
}
Also used : StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) StreamsBuilderTest(org.apache.kafka.streams.StreamsBuilderTest) Test(org.junit.Test)

Aggregations

StreamsMetadata (org.apache.kafka.streams.state.StreamsMetadata)18 Test (org.junit.Test)14 StreamsBuilderTest (org.apache.kafka.streams.StreamsBuilderTest)11 TopicPartition (org.apache.kafka.common.TopicPartition)8 PartitionInfo (org.apache.kafka.common.PartitionInfo)4 HashSet (java.util.HashSet)3 HostInfo (org.apache.kafka.streams.state.HostInfo)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 PlayEvent (io.confluent.examples.streams.avro.PlayEvent)1 Song (io.confluent.examples.streams.avro.Song)1 WordCountInteractiveQueriesExampleTest.randomFreeLocalPort (io.confluent.examples.streams.interactivequeries.WordCountInteractiveQueriesExampleTest.randomFreeLocalPort)1 EmbeddedSingleNodeKafkaCluster (io.confluent.examples.streams.kafka.EmbeddedSingleNodeKafkaCluster)1 AbstractKafkaAvroSerDeConfig (io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig)1 SpecificAvroSerializer (io.confluent.kafka.streams.serdes.avro.SpecificAvroSerializer)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Properties (java.util.Properties)1 Set (java.util.Set)1