Search in sources :

Example 16 with KeyQueryMetadata

use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.

the class StreamsMetadataStateTest method shouldGetInstanceWithKey.

@Test
public void shouldGetInstanceWithKey() {
    final TopicPartition tp4 = new TopicPartition("topic-three", 1);
    hostToActivePartitions.put(hostTwo, mkSet(topic2P0, tp4));
    metadataState.onChange(hostToActivePartitions, hostToStandbyPartitions, cluster.withPartitions(Collections.singletonMap(tp4, new PartitionInfo("topic-three", 1, null, null, null))));
    final KeyQueryMetadata expected = new KeyQueryMetadata(hostThree, mkSet(hostTwo), 0);
    final KeyQueryMetadata actual = metadataState.getKeyQueryMetadataForKey("table-three", "the-key", Serdes.String().serializer());
    assertEquals(expected, actual);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) PartitionInfo(org.apache.kafka.common.PartitionInfo) KeyQueryMetadata(org.apache.kafka.streams.KeyQueryMetadata) Test(org.junit.Test)

Example 17 with KeyQueryMetadata

use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.

the class StreamsMetadataStateTest method shouldGetInstanceWithKeyWithMergedStreams.

@Test
public void shouldGetInstanceWithKeyWithMergedStreams() {
    final TopicPartition topic2P2 = new TopicPartition("topic-two", 2);
    hostToActivePartitions.put(hostTwo, mkSet(topic2P0, topic1P1, topic2P2));
    hostToStandbyPartitions.put(hostOne, mkSet(topic2P0, topic1P1, topic2P2));
    metadataState.onChange(hostToActivePartitions, hostToStandbyPartitions, cluster.withPartitions(Collections.singletonMap(topic2P2, new PartitionInfo("topic-two", 2, null, null, null))));
    final KeyQueryMetadata expected = new KeyQueryMetadata(hostTwo, mkSet(hostOne), 2);
    final KeyQueryMetadata actual = metadataState.getKeyQueryMetadataForKey("merged-table", "the-key", (topic, key, value, numPartitions) -> 2);
    assertEquals(expected, actual);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) PartitionInfo(org.apache.kafka.common.PartitionInfo) KeyQueryMetadata(org.apache.kafka.streams.KeyQueryMetadata) Test(org.junit.Test)

Aggregations

KeyQueryMetadata (org.apache.kafka.streams.KeyQueryMetadata)17 Test (org.junit.Test)14 KafkaStreams (org.apache.kafka.streams.KafkaStreams)8 ReadOnlyKeyValueStore (org.apache.kafka.streams.state.ReadOnlyKeyValueStore)7 Semaphore (java.util.concurrent.Semaphore)6 IntegrationTest (org.apache.kafka.test.IntegrationTest)6 TopicPartition (org.apache.kafka.common.TopicPartition)5 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)5 InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)4 Properties (java.util.Properties)3 PartitionInfo (org.apache.kafka.common.PartitionInfo)3 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)2 StreamsMetadata (org.apache.kafka.streams.StreamsMetadata)2 KafkaStreamsNamedTopologyWrapper (org.apache.kafka.streams.processor.internals.namedtopology.KafkaStreamsNamedTopologyWrapper)2 NamedTopologyBuilder (org.apache.kafka.streams.processor.internals.namedtopology.NamedTopologyBuilder)2 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)2