Search in sources :

Example 6 with StreamsMetadata

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

the class StreamsMetadataStateTest method shouldGetAllStreamsInstancesWithNoStores.

@Test
public void shouldGetAllStreamsInstancesWithNoStores() throws Exception {
    builder.stream("topic-five").filter(new Predicate<Object, Object>() {

        @Override
        public boolean test(final Object key, final Object value) {
            return true;
        }
    }).to("some-other-topic");
    final TopicPartition tp5 = new TopicPartition("topic-five", 1);
    final HostInfo hostFour = new HostInfo("host-four", 8080);
    hostToPartitions.put(hostFour, Utils.mkSet(tp5));
    discovery.onChange(hostToPartitions, cluster.withPartitions(Collections.singletonMap(tp5, new PartitionInfo("topic-five", 1, null, null, null))));
    final StreamsMetadata expected = new StreamsMetadata(hostFour, Collections.singleton(globalTable), Collections.singleton(tp5));
    final Collection<StreamsMetadata> actual = discovery.getAllMetadata();
    assertTrue("expected " + actual + " to contain " + expected, actual.contains(expected));
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsMetadata(org.apache.kafka.streams.state.StreamsMetadata) PartitionInfo(org.apache.kafka.common.PartitionInfo) HostInfo(org.apache.kafka.streams.state.HostInfo) Predicate(org.apache.kafka.streams.kstream.Predicate) Test(org.junit.Test)

Example 7 with StreamsMetadata

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

the class StreamsMetadataStateTest method shouldReturnNotAvailableWhenClusterIsEmpty.

@Test
public void shouldReturnNotAvailableWhenClusterIsEmpty() throws Exception {
    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) Test(org.junit.Test)

Example 8 with StreamsMetadata

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

the class StreamsMetadataStateTest method shouldGetInstanceWithKeyAndCustomPartitioner.

@Test
public void shouldGetInstanceWithKeyAndCustomPartitioner() 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(hostTwo, Utils.mkSet(globalTable, "table-two", "table-three", "merged-table"), Utils.mkSet(topic2P0, tp4));
    StreamsMetadata actual = discovery.getMetadataWithKey("table-three", "the-key", partitioner);
    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 9 with StreamsMetadata

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

the class StreamsMetadataStateTest method shouldReturnNullOnGetWithKeyWhenStoreDoesntExist.

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

Example 10 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)

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