Search in sources :

Example 6 with DescribeProducersResponse

use of org.apache.kafka.common.requests.DescribeProducersResponse in project kafka by apache.

the class KafkaAdminClientTest method testDescribeProducersRetryAfterDisconnect.

@Test
public void testDescribeProducersRetryAfterDisconnect() throws Exception {
    MockTime time = new MockTime();
    int retryBackoffMs = 100;
    Cluster cluster = mockCluster(3, 0);
    Map<String, Object> configOverride = newStrMap(AdminClientConfig.RETRY_BACKOFF_MS_CONFIG, "" + retryBackoffMs);
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, cluster, configOverride)) {
        TopicPartition topicPartition = new TopicPartition("foo", 0);
        Iterator<Node> nodeIterator = env.cluster().nodes().iterator();
        Node initialLeader = nodeIterator.next();
        expectMetadataRequest(env, topicPartition, initialLeader);
        List<ProducerState> expected = Arrays.asList(new ProducerState(12345L, 15, 30, env.time().milliseconds(), OptionalInt.of(99), OptionalLong.empty()), new ProducerState(12345L, 15, 30, env.time().milliseconds(), OptionalInt.empty(), OptionalLong.of(23423L)));
        DescribeProducersResponse response = buildDescribeProducersResponse(topicPartition, expected);
        env.kafkaClient().prepareResponseFrom(request -> {
            // We need a sleep here because the client will attempt to
            // backoff after the disconnect
            env.time().sleep(retryBackoffMs);
            return request instanceof DescribeProducersRequest;
        }, response, initialLeader, true);
        Node retryLeader = nodeIterator.next();
        expectMetadataRequest(env, topicPartition, retryLeader);
        env.kafkaClient().prepareResponseFrom(request -> request instanceof DescribeProducersRequest, response, retryLeader);
        DescribeProducersResult result = env.adminClient().describeProducers(singleton(topicPartition));
        KafkaFuture<DescribeProducersResult.PartitionProducerState> partitionFuture = result.partitionResult(topicPartition);
        assertEquals(new HashSet<>(expected), new HashSet<>(partitionFuture.get().activeProducers()));
    }
}
Also used : Node(org.apache.kafka.common.Node) Cluster(org.apache.kafka.common.Cluster) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse) DescribeProducersRequest(org.apache.kafka.common.requests.DescribeProducersRequest) TopicPartition(org.apache.kafka.common.TopicPartition) MockTime(org.apache.kafka.common.utils.MockTime) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 7 with DescribeProducersResponse

use of org.apache.kafka.common.requests.DescribeProducersResponse in project kafka by apache.

the class KafkaAdminClientTest method testDescribeProducers.

@Test
public void testDescribeProducers() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        TopicPartition topicPartition = new TopicPartition("foo", 0);
        Node leader = env.cluster().nodes().iterator().next();
        expectMetadataRequest(env, topicPartition, leader);
        List<ProducerState> expected = Arrays.asList(new ProducerState(12345L, 15, 30, env.time().milliseconds(), OptionalInt.of(99), OptionalLong.empty()), new ProducerState(12345L, 15, 30, env.time().milliseconds(), OptionalInt.empty(), OptionalLong.of(23423L)));
        DescribeProducersResponse response = buildDescribeProducersResponse(topicPartition, expected);
        env.kafkaClient().prepareResponseFrom(request -> request instanceof DescribeProducersRequest, response, leader);
        DescribeProducersResult result = env.adminClient().describeProducers(singleton(topicPartition));
        KafkaFuture<DescribeProducersResult.PartitionProducerState> partitionFuture = result.partitionResult(topicPartition);
        assertEquals(new HashSet<>(expected), new HashSet<>(partitionFuture.get().activeProducers()));
    }
}
Also used : DescribeProducersRequest(org.apache.kafka.common.requests.DescribeProducersRequest) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

DescribeProducersResponse (org.apache.kafka.common.requests.DescribeProducersResponse)7 Node (org.apache.kafka.common.Node)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 DescribeProducersResponseData (org.apache.kafka.common.message.DescribeProducersResponseData)3 DescribeProducersRequest (org.apache.kafka.common.requests.DescribeProducersRequest)3 Test (org.junit.jupiter.api.Test)3 Map (java.util.Map)2 DescribeProducersOptions (org.apache.kafka.clients.admin.DescribeProducersOptions)2 PartitionProducerState (org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)2 PartitionResponse (org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1