use of org.apache.kafka.common.message.DescribeTransactionsResponseData in project kafka by apache.
the class DescribeTransactionsRequest method getErrorResponse.
@Override
public DescribeTransactionsResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
DescribeTransactionsResponseData response = new DescribeTransactionsResponseData().setThrottleTimeMs(throttleTimeMs);
for (String transactionalId : data.transactionalIds()) {
DescribeTransactionsResponseData.TransactionState transactionState = new DescribeTransactionsResponseData.TransactionState().setTransactionalId(transactionalId).setErrorCode(error.code());
response.transactionStates().add(transactionState);
}
return new DescribeTransactionsResponse(response);
}
use of org.apache.kafka.common.message.DescribeTransactionsResponseData in project kafka by apache.
the class DescribeTransactionsHandlerTest method handleResponseError.
private ApiResult<CoordinatorKey, TransactionDescription> handleResponseError(DescribeTransactionsHandler handler, String transactionalId, Errors error) {
CoordinatorKey key = CoordinatorKey.byTransactionalId(transactionalId);
Set<CoordinatorKey> keys = mkSet(key);
DescribeTransactionsResponseData.TransactionState transactionState = new DescribeTransactionsResponseData.TransactionState().setErrorCode(error.code()).setTransactionalId(transactionalId);
DescribeTransactionsResponse response = new DescribeTransactionsResponse(new DescribeTransactionsResponseData().setTransactionStates(singletonList(transactionState)));
ApiResult<CoordinatorKey, TransactionDescription> result = handler.handleResponse(node, keys, response);
assertEquals(emptyMap(), result.completedKeys);
return result;
}
use of org.apache.kafka.common.message.DescribeTransactionsResponseData in project kafka by apache.
the class KafkaAdminClientTest method testRetryDescribeTransactionsAfterNotCoordinatorError.
@Test
public void testRetryDescribeTransactionsAfterNotCoordinatorError() 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)) {
String transactionalId = "foo";
Iterator<Node> nodeIterator = env.cluster().nodes().iterator();
Node coordinator1 = nodeIterator.next();
Node coordinator2 = nodeIterator.next();
env.kafkaClient().prepareResponse(request -> request instanceof FindCoordinatorRequest, new FindCoordinatorResponse(new FindCoordinatorResponseData().setCoordinators(Arrays.asList(new FindCoordinatorResponseData.Coordinator().setKey(transactionalId).setErrorCode(Errors.NONE.code()).setNodeId(coordinator1.id()).setHost(coordinator1.host()).setPort(coordinator1.port())))));
env.kafkaClient().prepareResponseFrom(request -> {
if (!(request instanceof DescribeTransactionsRequest)) {
return false;
} else {
// Backoff needed here for the retry of FindCoordinator
time.sleep(retryBackoffMs);
return true;
}
}, new DescribeTransactionsResponse(new DescribeTransactionsResponseData().setTransactionStates(singletonList(new DescribeTransactionsResponseData.TransactionState().setErrorCode(Errors.NOT_COORDINATOR.code()).setTransactionalId(transactionalId)))), coordinator1);
env.kafkaClient().prepareResponse(request -> request instanceof FindCoordinatorRequest, new FindCoordinatorResponse(new FindCoordinatorResponseData().setCoordinators(Arrays.asList(new FindCoordinatorResponseData.Coordinator().setKey(transactionalId).setErrorCode(Errors.NONE.code()).setNodeId(coordinator2.id()).setHost(coordinator2.host()).setPort(coordinator2.port())))));
TransactionDescription expected = new TransactionDescription(coordinator2.id(), TransactionState.COMPLETE_COMMIT, 12345L, 15, 10000L, OptionalLong.empty(), emptySet());
env.kafkaClient().prepareResponseFrom(request -> request instanceof DescribeTransactionsRequest, new DescribeTransactionsResponse(new DescribeTransactionsResponseData().setTransactionStates(singletonList(new DescribeTransactionsResponseData.TransactionState().setErrorCode(Errors.NONE.code()).setProducerEpoch((short) expected.producerEpoch()).setProducerId(expected.producerId()).setTransactionalId(transactionalId).setTransactionTimeoutMs(10000).setTransactionStartTimeMs(-1).setTransactionState(expected.state().toString())))), coordinator2);
DescribeTransactionsResult result = env.adminClient().describeTransactions(singleton(transactionalId));
KafkaFuture<TransactionDescription> future = result.description(transactionalId);
assertEquals(expected, future.get());
}
}
use of org.apache.kafka.common.message.DescribeTransactionsResponseData in project kafka by apache.
the class KafkaAdminClientTest method testDescribeTransactions.
@Test
public void testDescribeTransactions() throws Exception {
try (AdminClientUnitTestEnv env = mockClientEnv()) {
String transactionalId = "foo";
Node coordinator = env.cluster().nodes().iterator().next();
TransactionDescription expected = new TransactionDescription(coordinator.id(), TransactionState.COMPLETE_COMMIT, 12345L, 15, 10000L, OptionalLong.empty(), emptySet());
env.kafkaClient().prepareResponse(request -> request instanceof FindCoordinatorRequest, prepareFindCoordinatorResponse(Errors.NONE, transactionalId, coordinator));
env.kafkaClient().prepareResponseFrom(request -> request instanceof DescribeTransactionsRequest, new DescribeTransactionsResponse(new DescribeTransactionsResponseData().setTransactionStates(singletonList(new DescribeTransactionsResponseData.TransactionState().setErrorCode(Errors.NONE.code()).setProducerEpoch((short) expected.producerEpoch()).setProducerId(expected.producerId()).setTransactionalId(transactionalId).setTransactionTimeoutMs(10000).setTransactionStartTimeMs(-1).setTransactionState(expected.state().toString())))), coordinator);
DescribeTransactionsResult result = env.adminClient().describeTransactions(singleton(transactionalId));
KafkaFuture<TransactionDescription> future = result.description(transactionalId);
assertEquals(expected, future.get());
}
}
use of org.apache.kafka.common.message.DescribeTransactionsResponseData in project kafka by apache.
the class RequestResponseTest method createDescribeTransactionsResponse.
private DescribeTransactionsResponse createDescribeTransactionsResponse() {
DescribeTransactionsResponseData data = new DescribeTransactionsResponseData();
data.setTransactionStates(asList(new DescribeTransactionsResponseData.TransactionState().setErrorCode(Errors.NONE.code()).setTransactionalId("t1").setProducerId(12345L).setProducerEpoch((short) 15).setTransactionStartTimeMs(13490218304L).setTransactionState("Empty"), new DescribeTransactionsResponseData.TransactionState().setErrorCode(Errors.NONE.code()).setTransactionalId("t2").setProducerId(98765L).setProducerEpoch((short) 30).setTransactionStartTimeMs(13490218304L).setTransactionState("Ongoing").setTopics(new DescribeTransactionsResponseData.TopicDataCollection(asList(new DescribeTransactionsResponseData.TopicData().setTopic("foo").setPartitions(asList(1, 3, 5, 7)), new DescribeTransactionsResponseData.TopicData().setTopic("bar").setPartitions(asList(1, 3))).iterator())), new DescribeTransactionsResponseData.TransactionState().setErrorCode(Errors.NOT_COORDINATOR.code()).setTransactionalId("t3")));
return new DescribeTransactionsResponse(data);
}
Aggregations