Search in sources :

Example 1 with InitProducerIdRequest

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

the class TransactionManagerTest method testUnsupportedInitTransactions.

@Test
public void testUnsupportedInitTransactions() {
    transactionManager.initializeTransactions();
    prepareFindCoordinatorResponse(Errors.NONE, false, CoordinatorType.TRANSACTION, transactionalId);
    runUntil(() -> transactionManager.coordinator(CoordinatorType.TRANSACTION) != null);
    assertFalse(transactionManager.hasError());
    client.prepareUnsupportedVersionResponse(body -> {
        InitProducerIdRequest initProducerIdRequest = (InitProducerIdRequest) body;
        assertEquals(initProducerIdRequest.data().transactionalId(), transactionalId);
        assertEquals(initProducerIdRequest.data().transactionTimeoutMs(), transactionTimeoutMs);
        return true;
    });
    runUntil(transactionManager::hasFatalError);
    assertTrue(transactionManager.hasFatalError());
    assertTrue(transactionManager.lastError() instanceof UnsupportedVersionException);
}
Also used : InitProducerIdRequest(org.apache.kafka.common.requests.InitProducerIdRequest) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Test(org.junit.jupiter.api.Test)

Example 2 with InitProducerIdRequest

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

the class TransactionManagerTest method prepareInitPidResponse.

private void prepareInitPidResponse(Errors error, boolean shouldDisconnect, long producerId, short producerEpoch) {
    InitProducerIdResponseData responseData = new InitProducerIdResponseData().setErrorCode(error.code()).setProducerEpoch(producerEpoch).setProducerId(producerId).setThrottleTimeMs(0);
    client.prepareResponse(body -> {
        InitProducerIdRequest initProducerIdRequest = (InitProducerIdRequest) body;
        assertEquals(transactionalId, initProducerIdRequest.data().transactionalId());
        assertEquals(transactionTimeoutMs, initProducerIdRequest.data().transactionTimeoutMs());
        return true;
    }, new InitProducerIdResponse(responseData), shouldDisconnect);
}
Also used : InitProducerIdResponseData(org.apache.kafka.common.message.InitProducerIdResponseData) InitProducerIdRequest(org.apache.kafka.common.requests.InitProducerIdRequest) InitProducerIdResponse(org.apache.kafka.common.requests.InitProducerIdResponse)

Example 3 with InitProducerIdRequest

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

the class TransactionManagerTest method initializeIdempotentProducerId.

private void initializeIdempotentProducerId(long producerId, short epoch) {
    InitProducerIdResponseData responseData = new InitProducerIdResponseData().setErrorCode(Errors.NONE.code()).setProducerEpoch(epoch).setProducerId(producerId).setThrottleTimeMs(0);
    client.prepareResponse(body -> {
        InitProducerIdRequest initProducerIdRequest = (InitProducerIdRequest) body;
        assertNull(initProducerIdRequest.data().transactionalId());
        return true;
    }, new InitProducerIdResponse(responseData), false);
    runUntil(transactionManager::hasProducerId);
}
Also used : InitProducerIdResponseData(org.apache.kafka.common.message.InitProducerIdResponseData) InitProducerIdRequest(org.apache.kafka.common.requests.InitProducerIdRequest) InitProducerIdResponse(org.apache.kafka.common.requests.InitProducerIdResponse)

Example 4 with InitProducerIdRequest

use of org.apache.kafka.common.requests.InitProducerIdRequest in project apache-kafka-on-k8s by banzaicloud.

the class SenderTest method prepareAndReceiveInitProducerId.

private void prepareAndReceiveInitProducerId(long producerId, Errors error) {
    short producerEpoch = 0;
    if (error != Errors.NONE)
        producerEpoch = RecordBatch.NO_PRODUCER_EPOCH;
    client.prepareResponse(new MockClient.RequestMatcher() {

        @Override
        public boolean matches(AbstractRequest body) {
            return body instanceof InitProducerIdRequest && ((InitProducerIdRequest) body).transactionalId() == null;
        }
    }, new InitProducerIdResponse(0, error, producerId, producerEpoch));
    sender.run(time.milliseconds());
}
Also used : AbstractRequest(org.apache.kafka.common.requests.AbstractRequest) InitProducerIdRequest(org.apache.kafka.common.requests.InitProducerIdRequest) InitProducerIdResponse(org.apache.kafka.common.requests.InitProducerIdResponse) MockClient(org.apache.kafka.clients.MockClient)

Aggregations

InitProducerIdRequest (org.apache.kafka.common.requests.InitProducerIdRequest)4 InitProducerIdResponse (org.apache.kafka.common.requests.InitProducerIdResponse)3 InitProducerIdResponseData (org.apache.kafka.common.message.InitProducerIdResponseData)2 MockClient (org.apache.kafka.clients.MockClient)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)1 Test (org.junit.jupiter.api.Test)1