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);
}
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);
}
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);
}
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());
}
Aggregations