Search in sources :

Example 1 with WriteTxnMarkersRequest

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

the class KafkaAdminClientTest method testAbortTransaction.

@Test
public void testAbortTransaction() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        TopicPartition topicPartition = new TopicPartition("foo", 13);
        AbortTransactionSpec abortSpec = new AbortTransactionSpec(topicPartition, 12345L, (short) 15, 200);
        Node leader = env.cluster().nodes().iterator().next();
        expectMetadataRequest(env, topicPartition, leader);
        env.kafkaClient().prepareResponseFrom(request -> request instanceof WriteTxnMarkersRequest, writeTxnMarkersResponse(abortSpec, Errors.NONE), leader);
        AbortTransactionResult result = env.adminClient().abortTransaction(abortSpec);
        assertNull(result.all().get());
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) WriteTxnMarkersRequest(org.apache.kafka.common.requests.WriteTxnMarkersRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with WriteTxnMarkersRequest

use of org.apache.kafka.common.requests.WriteTxnMarkersRequest 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)

Aggregations

Node (org.apache.kafka.common.Node)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 WriteTxnMarkersRequest (org.apache.kafka.common.requests.WriteTxnMarkersRequest)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Cluster (org.apache.kafka.common.Cluster)1 WriteTxnMarkersResponse (org.apache.kafka.common.requests.WriteTxnMarkersResponse)1 MockTime (org.apache.kafka.common.utils.MockTime)1