Search in sources :

Example 1 with WriteTxnMarkersResponse

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

the class KafkaAdminClientTest method writeTxnMarkersResponse.

private WriteTxnMarkersResponse writeTxnMarkersResponse(AbortTransactionSpec abortSpec, Errors error) {
    WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult partitionResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult().setPartitionIndex(abortSpec.topicPartition().partition()).setErrorCode(error.code());
    WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult topicResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult().setName(abortSpec.topicPartition().topic());
    topicResponse.partitions().add(partitionResponse);
    WriteTxnMarkersResponseData.WritableTxnMarkerResult markerResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerResult().setProducerId(abortSpec.producerId());
    markerResponse.topics().add(topicResponse);
    WriteTxnMarkersResponseData response = new WriteTxnMarkersResponseData();
    response.markers().add(markerResponse);
    return new WriteTxnMarkersResponse(response);
}
Also used : WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) WriteTxnMarkersResponseData(org.apache.kafka.common.message.WriteTxnMarkersResponseData)

Example 2 with WriteTxnMarkersResponse

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

the class AbortTransactionHandlerTest method testInvalidResponse.

@Test
public void testInvalidResponse() {
    AbortTransactionHandler handler = new AbortTransactionHandler(abortSpec, logContext);
    WriteTxnMarkersResponseData response = new WriteTxnMarkersResponseData();
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    WriteTxnMarkersResponseData.WritableTxnMarkerResult markerResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerResult();
    response.markers().add(markerResponse);
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    markerResponse.setProducerId(abortSpec.producerId());
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult topicResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult();
    markerResponse.topics().add(topicResponse);
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    topicResponse.setName(abortSpec.topicPartition().topic());
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult partitionResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult();
    topicResponse.partitions().add(partitionResponse);
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    partitionResponse.setPartitionIndex(abortSpec.topicPartition().partition());
    topicResponse.setName(abortSpec.topicPartition().topic() + "random");
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
    topicResponse.setName(abortSpec.topicPartition().topic());
    markerResponse.setProducerId(abortSpec.producerId() + 1);
    assertFailed(KafkaException.class, topicPartition, handler.handleResponse(node, singleton(topicPartition), new WriteTxnMarkersResponse(response)));
}
Also used : WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) WriteTxnMarkersResponseData(org.apache.kafka.common.message.WriteTxnMarkersResponseData) Test(org.junit.jupiter.api.Test)

Example 3 with WriteTxnMarkersResponse

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

the class AbortTransactionHandlerTest method testInvalidHandleResponseCall.

@Test
public void testInvalidHandleResponseCall() {
    AbortTransactionHandler handler = new AbortTransactionHandler(abortSpec, logContext);
    WriteTxnMarkersResponseData response = new WriteTxnMarkersResponseData();
    assertThrows(IllegalArgumentException.class, () -> handler.handleResponse(node, emptySet(), new WriteTxnMarkersResponse(response)));
    assertThrows(IllegalArgumentException.class, () -> handler.handleResponse(node, mkSet(new TopicPartition("foo", 1)), new WriteTxnMarkersResponse(response)));
    assertThrows(IllegalArgumentException.class, () -> handler.handleResponse(node, mkSet(topicPartition, new TopicPartition("foo", 1)), new WriteTxnMarkersResponse(response)));
}
Also used : WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) TopicPartition(org.apache.kafka.common.TopicPartition) WriteTxnMarkersResponseData(org.apache.kafka.common.message.WriteTxnMarkersResponseData) Test(org.junit.jupiter.api.Test)

Example 4 with WriteTxnMarkersResponse

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

the class KafkaAdminClientTest method testAbortTransactionFindLeaderAfterDisconnect.

@Test
public void testAbortTransactionFindLeaderAfterDisconnect() 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", 13);
        AbortTransactionSpec abortSpec = new AbortTransactionSpec(topicPartition, 12345L, (short) 15, 200);
        Iterator<Node> nodeIterator = env.cluster().nodes().iterator();
        Node firstLeader = nodeIterator.next();
        expectMetadataRequest(env, topicPartition, firstLeader);
        WriteTxnMarkersResponse response = writeTxnMarkersResponse(abortSpec, Errors.NONE);
        env.kafkaClient().prepareResponseFrom(request -> {
            // We need a sleep here because the client will attempt to
            // backoff after the disconnect
            time.sleep(retryBackoffMs);
            return request instanceof WriteTxnMarkersRequest;
        }, response, firstLeader, true);
        Node retryLeader = nodeIterator.next();
        expectMetadataRequest(env, topicPartition, retryLeader);
        env.kafkaClient().prepareResponseFrom(request -> request instanceof WriteTxnMarkersRequest, response, retryLeader);
        AbortTransactionResult result = env.adminClient().abortTransaction(abortSpec);
        assertNull(result.all().get());
    }
}
Also used : Node(org.apache.kafka.common.Node) WriteTxnMarkersRequest(org.apache.kafka.common.requests.WriteTxnMarkersRequest) Cluster(org.apache.kafka.common.Cluster) WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) 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 5 with WriteTxnMarkersResponse

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

the class AbortTransactionHandlerTest method handleWithError.

private AdminApiHandler.ApiResult<TopicPartition, Void> handleWithError(AbortTransactionSpec abortSpec, Errors error) {
    AbortTransactionHandler handler = new AbortTransactionHandler(abortSpec, logContext);
    WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult partitionResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerPartitionResult().setPartitionIndex(abortSpec.topicPartition().partition()).setErrorCode(error.code());
    WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult topicResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerTopicResult().setName(abortSpec.topicPartition().topic());
    topicResponse.partitions().add(partitionResponse);
    WriteTxnMarkersResponseData.WritableTxnMarkerResult markerResponse = new WriteTxnMarkersResponseData.WritableTxnMarkerResult().setProducerId(abortSpec.producerId());
    markerResponse.topics().add(topicResponse);
    WriteTxnMarkersResponseData response = new WriteTxnMarkersResponseData();
    response.markers().add(markerResponse);
    return handler.handleResponse(node, singleton(abortSpec.topicPartition()), new WriteTxnMarkersResponse(response));
}
Also used : WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) WriteTxnMarkersResponseData(org.apache.kafka.common.message.WriteTxnMarkersResponseData)

Aggregations

WriteTxnMarkersResponse (org.apache.kafka.common.requests.WriteTxnMarkersResponse)6 WriteTxnMarkersResponseData (org.apache.kafka.common.message.WriteTxnMarkersResponseData)5 Test (org.junit.jupiter.api.Test)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 Cluster (org.apache.kafka.common.Cluster)1 KafkaException (org.apache.kafka.common.KafkaException)1 Node (org.apache.kafka.common.Node)1 Errors (org.apache.kafka.common.protocol.Errors)1 WriteTxnMarkersRequest (org.apache.kafka.common.requests.WriteTxnMarkersRequest)1 MockTime (org.apache.kafka.common.utils.MockTime)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1