Search in sources :

Example 6 with DescribeProducersOptions

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

the class TransactionsCommandTest method expectDescribeProducers.

private void expectDescribeProducers(TopicPartition topicPartition, long producerId, short producerEpoch, long lastTimestamp, OptionalInt coordinatorEpoch, OptionalLong txnStartOffset) {
    PartitionProducerState partitionProducerState = new PartitionProducerState(singletonList(new ProducerState(producerId, producerEpoch, 500, lastTimestamp, coordinatorEpoch, txnStartOffset)));
    DescribeProducersResult result = Mockito.mock(DescribeProducersResult.class);
    Mockito.when(result.all()).thenReturn(completedFuture(singletonMap(topicPartition, partitionProducerState)));
    Mockito.when(admin.describeProducers(Collections.singletonList(topicPartition), new DescribeProducersOptions())).thenReturn(result);
}
Also used : ProducerState(org.apache.kafka.clients.admin.ProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions)

Example 7 with DescribeProducersOptions

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

the class TransactionsCommandTest method testFindHangingLookupTopicPartitionsForBroker.

@Test
public void testFindHangingLookupTopicPartitionsForBroker() throws Exception {
    int brokerId = 5;
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "find-hanging", "--broker-id", String.valueOf(brokerId) };
    String topic = "foo";
    expectListTopics(singleton(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)

Example 8 with DescribeProducersOptions

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

the class DescribeProducersHandlerTest method testUnmappedAfterNotLeaderError.

@Test
public void testUnmappedAfterNotLeaderError() {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    ApiResult<TopicPartition, PartitionProducerState> result = handleResponseWithError(new DescribeProducersOptions(), topicPartition, Errors.NOT_LEADER_OR_FOLLOWER);
    assertEquals(emptyMap(), result.failedKeys);
    assertEquals(emptyMap(), result.completedKeys);
    assertEquals(singletonList(topicPartition), result.unmappedKeys);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test)

Example 9 with DescribeProducersOptions

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

the class DescribeProducersHandlerTest method testBrokerIdSetInOptions.

@Test
public void testBrokerIdSetInOptions() {
    int brokerId = 3;
    Set<TopicPartition> topicPartitions = mkSet(new TopicPartition("foo", 5), new TopicPartition("bar", 3), new TopicPartition("foo", 4));
    DescribeProducersHandler handler = newHandler(new DescribeProducersOptions().brokerId(brokerId));
    topicPartitions.forEach(topicPartition -> {
        ApiRequestScope scope = handler.lookupStrategy().lookupScope(topicPartition);
        assertEquals(OptionalInt.of(brokerId), scope.destinationBrokerId(), "Unexpected brokerId for " + topicPartition);
    });
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test)

Example 10 with DescribeProducersOptions

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

the class DescribeProducersHandlerTest method testBrokerIdNotSetInOptions.

@Test
public void testBrokerIdNotSetInOptions() {
    Set<TopicPartition> topicPartitions = mkSet(new TopicPartition("foo", 5), new TopicPartition("bar", 3), new TopicPartition("foo", 4));
    DescribeProducersHandler handler = newHandler(new DescribeProducersOptions());
    topicPartitions.forEach(topicPartition -> {
        ApiRequestScope scope = handler.lookupStrategy().lookupScope(topicPartition);
        assertEquals(OptionalInt.empty(), scope.destinationBrokerId(), "Unexpected brokerId for " + topicPartition);
    });
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) Test(org.junit.jupiter.api.Test)

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