Search in sources :

Example 21 with Metadata

use of org.apache.kafka.clients.Metadata in project kafka by apache.

the class AbstractCoordinatorTest method setupCoordinator.

@Before
public void setupCoordinator() {
    this.mockTime = new MockTime();
    this.mockClient = new MockClient(mockTime);
    Metadata metadata = new Metadata();
    this.consumerClient = new ConsumerNetworkClient(mockClient, metadata, mockTime, RETRY_BACKOFF_MS, REQUEST_TIMEOUT_MS);
    Metrics metrics = new Metrics();
    Cluster cluster = TestUtils.singletonCluster("topic", 1);
    metadata.update(cluster, Collections.<String>emptySet(), mockTime.milliseconds());
    this.node = cluster.nodes().get(0);
    mockClient.setNode(node);
    this.coordinatorNode = new Node(Integer.MAX_VALUE - node.id(), node.host(), node.port());
    this.coordinator = new DummyCoordinator(consumerClient, metrics, mockTime);
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) Node(org.apache.kafka.common.Node) Metadata(org.apache.kafka.clients.Metadata) Cluster(org.apache.kafka.common.Cluster) MockTime(org.apache.kafka.common.utils.MockTime) MockClient(org.apache.kafka.clients.MockClient) Before(org.junit.Before)

Example 22 with Metadata

use of org.apache.kafka.clients.Metadata in project kafka by apache.

the class StreamsKafkaClient method getAnyReadyBrokerId.

/**
     * @return the Id of any broker that is ready, or an exception if no broker is ready.
     */
private String getAnyReadyBrokerId() {
    final Metadata metadata = new Metadata(streamsConfig.getLong(StreamsConfig.RETRY_BACKOFF_MS_CONFIG), streamsConfig.getLong(StreamsConfig.METADATA_MAX_AGE_CONFIG));
    final List<InetSocketAddress> addresses = ClientUtils.parseAndValidateAddresses(streamsConfig.getList(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
    metadata.update(Cluster.bootstrap(addresses), Collections.<String>emptySet(), Time.SYSTEM.milliseconds());
    final List<Node> nodes = metadata.fetch().nodes();
    return ensureOneNodeIsReady(nodes);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Node(org.apache.kafka.common.Node) Metadata(org.apache.kafka.clients.Metadata)

Aggregations

Metadata (org.apache.kafka.clients.Metadata)22 Node (org.apache.kafka.common.Node)20 MockClient (org.apache.kafka.clients.MockClient)19 Cluster (org.apache.kafka.common.Cluster)19 MockTime (org.apache.kafka.common.utils.MockTime)19 Test (org.junit.Test)17 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)16 Time (org.apache.kafka.common.utils.Time)16 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TopicPartition (org.apache.kafka.common.TopicPartition)5 GroupCoordinatorResponse (org.apache.kafka.common.requests.GroupCoordinatorResponse)4 Metrics (org.apache.kafka.common.metrics.Metrics)3 Before (org.junit.Before)3 Properties (java.util.Properties)2 ClientRequest (org.apache.kafka.clients.ClientRequest)2 KafkaException (org.apache.kafka.common.KafkaException)2 PartitionInfo (org.apache.kafka.common.PartitionInfo)2 WakeupException (org.apache.kafka.common.errors.WakeupException)2