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;
}
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());
}
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);
}
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);
}
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));
}
Aggregations