Search in sources :

Example 1 with DescribeProducersOptions

use of org.apache.kafka.clients.admin.DescribeProducersOptions in project kafka by apache.

the class DescribeProducersHandlerTest method testCompletedResult.

@Test
public void testCompletedResult() {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    DescribeProducersOptions options = new DescribeProducersOptions().brokerId(1);
    DescribeProducersHandler handler = newHandler(options);
    PartitionResponse partitionResponse = sampleProducerState(topicPartition);
    DescribeProducersResponse response = describeProducersResponse(singletonMap(topicPartition, partitionResponse));
    Node node = new Node(3, "host", 1);
    ApiResult<TopicPartition, PartitionProducerState> result = handler.handleResponse(node, mkSet(topicPartition), response);
    assertEquals(mkSet(topicPartition), result.completedKeys.keySet());
    assertEquals(emptyMap(), result.failedKeys);
    assertEquals(emptyList(), result.unmappedKeys);
    PartitionProducerState producerState = result.completedKeys.get(topicPartition);
    assertMatchingProducers(partitionResponse, producerState);
}
Also used : PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse) Test(org.junit.jupiter.api.Test)

Example 2 with DescribeProducersOptions

use of org.apache.kafka.clients.admin.DescribeProducersOptions in project kafka by apache.

the class DescribeProducersHandlerTest method testBuildRequest.

@Test
public void testBuildRequest() {
    Set<TopicPartition> topicPartitions = mkSet(new TopicPartition("foo", 5), new TopicPartition("bar", 3), new TopicPartition("foo", 4));
    DescribeProducersHandler handler = newHandler(new DescribeProducersOptions());
    int brokerId = 3;
    DescribeProducersRequest.Builder request = handler.buildRequest(brokerId, topicPartitions);
    List<DescribeProducersRequestData.TopicRequest> topics = request.data.topics();
    assertEquals(mkSet("foo", "bar"), topics.stream().map(DescribeProducersRequestData.TopicRequest::name).collect(Collectors.toSet()));
    topics.forEach(topic -> {
        Set<Integer> expectedTopicPartitions = "foo".equals(topic.name()) ? mkSet(4, 5) : mkSet(3);
        assertEquals(expectedTopicPartitions, new HashSet<>(topic.partitionIndexes()));
    });
}
Also used : DescribeProducersRequest(org.apache.kafka.common.requests.DescribeProducersRequest) TopicPartition(org.apache.kafka.common.TopicPartition) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test)

Example 3 with DescribeProducersOptions

use of org.apache.kafka.clients.admin.DescribeProducersOptions in project kafka by apache.

the class DescribeProducersHandlerTest method assertFatalError.

private Throwable assertFatalError(TopicPartition topicPartition, Errors error) {
    ApiResult<TopicPartition, PartitionProducerState> result = handleResponseWithError(new DescribeProducersOptions(), topicPartition, error);
    assertEquals(emptyMap(), result.completedKeys);
    assertEquals(emptyList(), result.unmappedKeys);
    assertEquals(mkSet(topicPartition), result.failedKeys.keySet());
    return result.failedKeys.get(topicPartition);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions)

Example 4 with DescribeProducersOptions

use of org.apache.kafka.clients.admin.DescribeProducersOptions in project kafka by apache.

the class DescribeProducersHandlerTest method testFatalNotLeaderErrorIfStaticMapped.

@Test
public void testFatalNotLeaderErrorIfStaticMapped() {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    DescribeProducersOptions options = new DescribeProducersOptions().brokerId(1);
    ApiResult<TopicPartition, PartitionProducerState> result = handleResponseWithError(options, topicPartition, Errors.NOT_LEADER_OR_FOLLOWER);
    assertEquals(emptyMap(), result.completedKeys);
    assertEquals(emptyList(), result.unmappedKeys);
    assertEquals(mkSet(topicPartition), result.failedKeys.keySet());
    Throwable exception = result.failedKeys.get(topicPartition);
    assertTrue(exception instanceof NotLeaderOrFollowerException);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) NotLeaderOrFollowerException(org.apache.kafka.common.errors.NotLeaderOrFollowerException) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test)

Example 5 with DescribeProducersOptions

use of org.apache.kafka.clients.admin.DescribeProducersOptions in project kafka by apache.

the class TransactionsCommandTest method testFindHangingLookupTopicAndBrokerId.

@Test
public void testFindHangingLookupTopicAndBrokerId() throws Exception {
    int brokerId = 5;
    String topic = "foo";
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--broker-id", String.valueOf(brokerId), "--topic", topic };
    Node node0 = new Node(0, "localhost", 9092);
    Node node1 = new Node(1, "localhost", 9093);
    Node node5 = new Node(5, "localhost", 9097);
    TopicPartitionInfo partition0 = new TopicPartitionInfo(0, node0, Arrays.asList(node0, node1), Arrays.asList(node0, node1));
    TopicPartitionInfo partition1 = new TopicPartitionInfo(1, node1, Arrays.asList(node1, node5), Arrays.asList(node1, node5));
    TopicDescription description = new TopicDescription(topic, false, Arrays.asList(partition0, partition1));
    expectDescribeTopics(singletonMap(topic, description));
    DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
    Mockito.when(result.all()).thenReturn(completedFuture(emptyMap()));
    Mockito.when(admin.describeProducers(Collections.singletonList(new TopicPartition(topic, 1)), new DescribeProducersOptions().brokerId(brokerId))).thenReturn(result);
    execute(args);
    assertNormalExit();
    assertNoHangingTransactions();
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DescribeProducersOptions (org.apache.kafka.clients.admin.DescribeProducersOptions)14 TopicPartition (org.apache.kafka.common.TopicPartition)13 Test (org.junit.jupiter.api.Test)11 PartitionProducerState (org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 DescribeProducersResult (org.apache.kafka.clients.admin.DescribeProducersResult)4 Node (org.apache.kafka.common.Node)4 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)3 TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)3 ProducerState (org.apache.kafka.clients.admin.ProducerState)1 NotLeaderOrFollowerException (org.apache.kafka.common.errors.NotLeaderOrFollowerException)1 PartitionResponse (org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse)1 DescribeProducersRequest (org.apache.kafka.common.requests.DescribeProducersRequest)1 DescribeProducersResponse (org.apache.kafka.common.requests.DescribeProducersResponse)1