Search in sources :

Example 36 with Cluster

use of org.apache.kafka.common.Cluster in project kafka by apache.

the class StreamPartitionAssignorTest method shouldReturnEmptyClusterMetadataIfItHasntBeenBuilt.

@Test
public void shouldReturnEmptyClusterMetadataIfItHasntBeenBuilt() throws Exception {
    final Cluster cluster = partitionAssignor.clusterMetadata();
    assertNotNull(cluster);
}
Also used : Cluster(org.apache.kafka.common.Cluster) Test(org.junit.Test)

Example 37 with Cluster

use of org.apache.kafka.common.Cluster in project kafka by apache.

the class StreamsMetadataStateTest method before.

@Before
public void before() {
    builder = new KStreamBuilder();
    final KStream<Object, Object> one = builder.stream("topic-one");
    one.groupByKey().count("table-one");
    final KStream<Object, Object> two = builder.stream("topic-two");
    two.groupByKey().count("table-two");
    builder.stream("topic-three").groupByKey().count("table-three");
    builder.merge(one, two).groupByKey().count("merged-table");
    builder.stream("topic-four").mapValues(new ValueMapper<Object, Object>() {

        @Override
        public Object apply(final Object value) {
            return value;
        }
    });
    builder.globalTable("global-topic", "global-table");
    builder.setApplicationId("appId");
    topic1P0 = new TopicPartition("topic-one", 0);
    topic1P1 = new TopicPartition("topic-one", 1);
    topic2P0 = new TopicPartition("topic-two", 0);
    topic2P1 = new TopicPartition("topic-two", 1);
    topic3P0 = new TopicPartition("topic-three", 0);
    topic4P0 = new TopicPartition("topic-four", 0);
    hostOne = new HostInfo("host-one", 8080);
    hostTwo = new HostInfo("host-two", 9090);
    hostThree = new HostInfo("host-three", 7070);
    hostToPartitions = new HashMap<>();
    hostToPartitions.put(hostOne, Utils.mkSet(topic1P0, topic2P1, topic4P0));
    hostToPartitions.put(hostTwo, Utils.mkSet(topic2P0, topic1P1));
    hostToPartitions.put(hostThree, Collections.singleton(topic3P0));
    partitionInfos = Arrays.asList(new PartitionInfo("topic-one", 0, null, null, null), new PartitionInfo("topic-one", 1, null, null, null), new PartitionInfo("topic-two", 0, null, null, null), new PartitionInfo("topic-two", 1, null, null, null), new PartitionInfo("topic-three", 0, null, null, null), new PartitionInfo("topic-four", 0, null, null, null));
    cluster = new Cluster(null, Collections.<Node>emptyList(), partitionInfos, Collections.<String>emptySet(), Collections.<String>emptySet());
    discovery = new StreamsMetadataState(builder, hostOne);
    discovery.onChange(hostToPartitions, cluster);
    partitioner = new StreamPartitioner<String, Object>() {

        @Override
        public Integer partition(final String key, final Object value, final int numPartitions) {
            return 1;
        }
    };
}
Also used : KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) Node(org.apache.kafka.common.Node) Cluster(org.apache.kafka.common.Cluster) TopicPartition(org.apache.kafka.common.TopicPartition) PartitionInfo(org.apache.kafka.common.PartitionInfo) HostInfo(org.apache.kafka.streams.state.HostInfo) Before(org.junit.Before)

Aggregations

Cluster (org.apache.kafka.common.Cluster)37 Node (org.apache.kafka.common.Node)28 Test (org.junit.Test)27 Metadata (org.apache.kafka.clients.Metadata)19 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)18 MockClient (org.apache.kafka.clients.MockClient)17 MockTime (org.apache.kafka.common.utils.MockTime)17 Time (org.apache.kafka.common.utils.Time)16 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)12 PartitionInfo (org.apache.kafka.common.PartitionInfo)11 TopicPartition (org.apache.kafka.common.TopicPartition)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 KafkaException (org.apache.kafka.common.KafkaException)5 HashSet (java.util.HashSet)4 GroupCoordinatorResponse (org.apache.kafka.common.requests.GroupCoordinatorResponse)4 List (java.util.List)3 TimeoutException (org.apache.kafka.common.errors.TimeoutException)3 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)3 Metrics (org.apache.kafka.common.metrics.Metrics)3