Search in sources :

Example 6 with PartitionProducerState

use of org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState 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 7 with PartitionProducerState

use of org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState in project kafka by apache.

the class DescribeProducersHandlerTest method assertMatchingProducers.

private void assertMatchingProducers(PartitionResponse expected, PartitionProducerState actual) {
    List<ProducerState> expectedProducers = expected.activeProducers();
    List<org.apache.kafka.clients.admin.ProducerState> actualProducers = actual.activeProducers();
    assertEquals(expectedProducers.size(), actualProducers.size());
    Map<Long, ProducerState> expectedByProducerId = expectedProducers.stream().collect(Collectors.toMap(ProducerState::producerId, Function.identity()));
    for (org.apache.kafka.clients.admin.ProducerState actualProducerState : actualProducers) {
        ProducerState expectedProducerState = expectedByProducerId.get(actualProducerState.producerId());
        assertNotNull(expectedProducerState);
        assertEquals(expectedProducerState.producerEpoch(), actualProducerState.producerEpoch());
        assertEquals(expectedProducerState.lastSequence(), actualProducerState.lastSequence());
        assertEquals(expectedProducerState.lastTimestamp(), actualProducerState.lastTimestamp());
        assertEquals(expectedProducerState.currentTxnStartOffset(), actualProducerState.currentTransactionStartOffset().orElse(-1L));
    }
}
Also used : ProducerState(org.apache.kafka.common.message.DescribeProducersResponseData.ProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)

Example 8 with PartitionProducerState

use of org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState in project kafka by apache.

the class DescribeProducersHandlerTest method assertRetriableError.

private void assertRetriableError(TopicPartition topicPartition, Errors error) {
    ApiResult<TopicPartition, PartitionProducerState> result = handleResponseWithError(new DescribeProducersOptions(), topicPartition, error);
    assertEquals(emptyMap(), result.failedKeys);
    assertEquals(emptyMap(), result.completedKeys);
    assertEquals(emptyList(), 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)

Example 9 with PartitionProducerState

use of org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState in project kafka by apache.

the class TransactionsCommandTest method testNewBrokerAbortTransaction.

@Test
public void testNewBrokerAbortTransaction() throws Exception {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    long startOffset = 9173;
    long producerId = 12345L;
    short producerEpoch = 15;
    int coordinatorEpoch = 76;
    String[] args = new String[] { "--bootstrap-server", "localhost:9092", "abort", "--topic", topicPartition.topic(), "--partition", String.valueOf(topicPartition.partition()), "--start-offset", String.valueOf(startOffset) };
    DescribeProducersResult describeResult = Mockito.mock(DescribeProducersResult.class);
    KafkaFuture<PartitionProducerState> describeFuture = completedFuture(new PartitionProducerState(singletonList(new ProducerState(producerId, producerEpoch, 1300, 1599509565L, OptionalInt.of(coordinatorEpoch), OptionalLong.of(startOffset)))));
    AbortTransactionResult abortTransactionResult = Mockito.mock(AbortTransactionResult.class);
    KafkaFuture<Void> abortFuture = completedFuture(null);
    AbortTransactionSpec expectedAbortSpec = new AbortTransactionSpec(topicPartition, producerId, producerEpoch, coordinatorEpoch);
    Mockito.when(describeResult.partitionResult(topicPartition)).thenReturn(describeFuture);
    Mockito.when(admin.describeProducers(singleton(topicPartition))).thenReturn(describeResult);
    Mockito.when(abortTransactionResult.all()).thenReturn(abortFuture);
    Mockito.when(admin.abortTransaction(expectedAbortSpec)).thenReturn(abortTransactionResult);
    execute(args);
    assertNormalExit();
}
Also used : AbortTransactionSpec(org.apache.kafka.clients.admin.AbortTransactionSpec) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) AbortTransactionResult(org.apache.kafka.clients.admin.AbortTransactionResult) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult) TopicPartition(org.apache.kafka.common.TopicPartition) ProducerState(org.apache.kafka.clients.admin.ProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with PartitionProducerState

use of org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState in project kafka by apache.

the class TransactionsCommandTest method testDescribeProducers.

private void testDescribeProducers(TopicPartition topicPartition, String[] args, DescribeProducersOptions expectedOptions) throws Exception {
    DescribeProducersResult describeResult = Mockito.mock(DescribeProducersResult.class);
    KafkaFuture<PartitionProducerState> describeFuture = completedFuture(new PartitionProducerState(asList(new ProducerState(12345L, 15, 1300, 1599509565L, OptionalInt.of(20), OptionalLong.of(990)), new ProducerState(98765L, 30, 2300, 1599509599L, OptionalInt.empty(), OptionalLong.empty()))));
    Mockito.when(describeResult.partitionResult(topicPartition)).thenReturn(describeFuture);
    Mockito.when(admin.describeProducers(singleton(topicPartition), expectedOptions)).thenReturn(describeResult);
    execute(args);
    assertNormalExit();
    List<List<String>> table = readOutputAsTable();
    assertEquals(3, table.size());
    List<String> expectedHeaders = asList(TransactionsCommand.DescribeProducersCommand.HEADERS);
    assertEquals(expectedHeaders, table.get(0));
    Set<List<String>> expectedRows = Utils.mkSet(asList("12345", "15", "20", "1300", "1599509565", "990"), asList("98765", "30", "-1", "2300", "1599509599", "None"));
    assertEquals(expectedRows, new HashSet<>(table.subList(1, table.size())));
}
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) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DescribeProducersResult(org.apache.kafka.clients.admin.DescribeProducersResult)

Aggregations

PartitionProducerState (org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)10 DescribeProducersOptions (org.apache.kafka.clients.admin.DescribeProducersOptions)7 TopicPartition (org.apache.kafka.common.TopicPartition)7 ProducerState (org.apache.kafka.clients.admin.ProducerState)4 Test (org.junit.jupiter.api.Test)4 DescribeProducersResult (org.apache.kafka.clients.admin.DescribeProducersResult)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Node (org.apache.kafka.common.Node)2 DescribeProducersResponse (org.apache.kafka.common.requests.DescribeProducersResponse)2 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 OptionalInt (java.util.OptionalInt)1 OptionalLong (java.util.OptionalLong)1 Set (java.util.Set)1