Search in sources :

Example 1 with EndTxnResponseData

use of org.apache.kafka.common.message.EndTxnResponseData in project kafka by apache.

the class EndTxnResponseTest method testConstructor.

@Test
public void testConstructor() {
    int throttleTimeMs = 10;
    EndTxnResponseData data = new EndTxnResponseData().setErrorCode(Errors.NOT_COORDINATOR.code()).setThrottleTimeMs(throttleTimeMs);
    Map<Errors, Integer> expectedErrorCounts = Collections.singletonMap(Errors.NOT_COORDINATOR, 1);
    for (short version : ApiKeys.END_TXN.allVersions()) {
        EndTxnResponse response = new EndTxnResponse(data);
        assertEquals(expectedErrorCounts, response.errorCounts());
        assertEquals(throttleTimeMs, response.throttleTimeMs());
        assertEquals(version >= 1, response.shouldClientThrottle(version));
        response = EndTxnResponse.parse(response.serialize(version), version);
        assertEquals(expectedErrorCounts, response.errorCounts());
        assertEquals(throttleTimeMs, response.throttleTimeMs());
        assertEquals(version >= 1, response.shouldClientThrottle(version));
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) EndTxnResponseData(org.apache.kafka.common.message.EndTxnResponseData) Test(org.junit.jupiter.api.Test)

Example 2 with EndTxnResponseData

use of org.apache.kafka.common.message.EndTxnResponseData in project kafka by apache.

the class SenderTest method testIncompleteTransactionAbortOnShutdown.

@Test
public void testIncompleteTransactionAbortOnShutdown() {
    // create a sender with retries = 1
    int maxRetries = 1;
    Metrics m = new Metrics();
    SenderMetricsRegistry senderMetrics = new SenderMetricsRegistry(m);
    try {
        TransactionManager txnManager = new TransactionManager(logContext, "testIncompleteTransactionAbortOnShutdown", 6000, 100, apiVersions);
        Sender sender = new Sender(logContext, client, metadata, this.accumulator, false, MAX_REQUEST_SIZE, ACKS_ALL, maxRetries, senderMetrics, time, REQUEST_TIMEOUT, RETRY_BACKOFF_MS, txnManager, apiVersions);
        ProducerIdAndEpoch producerIdAndEpoch = new ProducerIdAndEpoch(123456L, (short) 0);
        TopicPartition tp = new TopicPartition("testIncompleteTransactionAbortOnShutdown", 1);
        setupWithTransactionState(txnManager);
        doInitTransactions(txnManager, producerIdAndEpoch);
        txnManager.beginTransaction();
        txnManager.maybeAddPartition(tp);
        client.prepareResponse(new AddPartitionsToTxnResponse(0, Collections.singletonMap(tp, Errors.NONE)));
        sender.runOnce();
        sender.initiateClose();
        AssertEndTxnRequestMatcher endTxnMatcher = new AssertEndTxnRequestMatcher(TransactionResult.ABORT);
        client.prepareResponse(endTxnMatcher, new EndTxnResponse(new EndTxnResponseData().setErrorCode(Errors.NONE.code()).setThrottleTimeMs(0)));
        sender.run();
        assertTrue(endTxnMatcher.matched, "Response didn't match in test");
    } finally {
        m.close();
    }
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) EndTxnResponseData(org.apache.kafka.common.message.EndTxnResponseData) TopicPartition(org.apache.kafka.common.TopicPartition) EndTxnResponse(org.apache.kafka.common.requests.EndTxnResponse) AddPartitionsToTxnResponse(org.apache.kafka.common.requests.AddPartitionsToTxnResponse) ProducerIdAndEpoch(org.apache.kafka.common.utils.ProducerIdAndEpoch) Test(org.junit.jupiter.api.Test)

Example 3 with EndTxnResponseData

use of org.apache.kafka.common.message.EndTxnResponseData in project kafka by apache.

the class SenderTest method testTransactionalRequestsSentOnShutdown.

@Test
public void testTransactionalRequestsSentOnShutdown() {
    // create a sender with retries = 1
    int maxRetries = 1;
    Metrics m = new Metrics();
    SenderMetricsRegistry senderMetrics = new SenderMetricsRegistry(m);
    try {
        TransactionManager txnManager = new TransactionManager(logContext, "testTransactionalRequestsSentOnShutdown", 6000, 100, apiVersions);
        Sender sender = new Sender(logContext, client, metadata, this.accumulator, false, MAX_REQUEST_SIZE, ACKS_ALL, maxRetries, senderMetrics, time, REQUEST_TIMEOUT, RETRY_BACKOFF_MS, txnManager, apiVersions);
        ProducerIdAndEpoch producerIdAndEpoch = new ProducerIdAndEpoch(123456L, (short) 0);
        TopicPartition tp = new TopicPartition("testTransactionalRequestsSentOnShutdown", 1);
        setupWithTransactionState(txnManager);
        doInitTransactions(txnManager, producerIdAndEpoch);
        txnManager.beginTransaction();
        txnManager.maybeAddPartition(tp);
        client.prepareResponse(new AddPartitionsToTxnResponse(0, Collections.singletonMap(tp, Errors.NONE)));
        sender.runOnce();
        sender.initiateClose();
        txnManager.beginCommit();
        AssertEndTxnRequestMatcher endTxnMatcher = new AssertEndTxnRequestMatcher(TransactionResult.COMMIT);
        client.prepareResponse(endTxnMatcher, new EndTxnResponse(new EndTxnResponseData().setErrorCode(Errors.NONE.code()).setThrottleTimeMs(0)));
        sender.run();
        assertTrue(endTxnMatcher.matched, "Response didn't match in test");
    } finally {
        m.close();
    }
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) EndTxnResponseData(org.apache.kafka.common.message.EndTxnResponseData) TopicPartition(org.apache.kafka.common.TopicPartition) EndTxnResponse(org.apache.kafka.common.requests.EndTxnResponse) AddPartitionsToTxnResponse(org.apache.kafka.common.requests.AddPartitionsToTxnResponse) ProducerIdAndEpoch(org.apache.kafka.common.utils.ProducerIdAndEpoch) Test(org.junit.jupiter.api.Test)

Aggregations

EndTxnResponseData (org.apache.kafka.common.message.EndTxnResponseData)3 Test (org.junit.jupiter.api.Test)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 Metrics (org.apache.kafka.common.metrics.Metrics)2 AddPartitionsToTxnResponse (org.apache.kafka.common.requests.AddPartitionsToTxnResponse)2 EndTxnResponse (org.apache.kafka.common.requests.EndTxnResponse)2 ProducerIdAndEpoch (org.apache.kafka.common.utils.ProducerIdAndEpoch)2 Errors (org.apache.kafka.common.protocol.Errors)1