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);
}
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()));
});
}
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);
}
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);
}
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();
}
Aggregations