use of org.apache.kafka.common.requests.TxnOffsetCommitResponse in project kafka by apache.
the class TransactionManagerTest method prepareTxnOffsetCommitResponse.
private void prepareTxnOffsetCommitResponse(final String consumerGroupId, final long producerId, final short producerEpoch, final String groupInstanceId, final String memberId, final int generationId, Map<TopicPartition, Errors> txnOffsetCommitResponse) {
client.prepareResponse(request -> {
TxnOffsetCommitRequest txnOffsetCommitRequest = (TxnOffsetCommitRequest) request;
assertEquals(consumerGroupId, txnOffsetCommitRequest.data().groupId());
assertEquals(producerId, txnOffsetCommitRequest.data().producerId());
assertEquals(producerEpoch, txnOffsetCommitRequest.data().producerEpoch());
assertEquals(groupInstanceId, txnOffsetCommitRequest.data().groupInstanceId());
assertEquals(memberId, txnOffsetCommitRequest.data().memberId());
assertEquals(generationId, txnOffsetCommitRequest.data().generationId());
return true;
}, new TxnOffsetCommitResponse(0, txnOffsetCommitResponse));
}
use of org.apache.kafka.common.requests.TxnOffsetCommitResponse in project kafka by apache.
the class TransactionManagerTest method testFencedInstanceIdInTxnOffsetCommitByGroupMetadata.
@Test
public void testFencedInstanceIdInTxnOffsetCommitByGroupMetadata() {
final TopicPartition tp = new TopicPartition("foo", 0);
final String fencedMemberId = "fenced_member";
doInitTransactions();
transactionManager.beginTransaction();
TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(tp, new OffsetAndMetadata(39L)), new ConsumerGroupMetadata(consumerGroupId, 5, fencedMemberId, Optional.of(groupInstanceId)));
prepareAddOffsetsToTxnResponse(Errors.NONE, consumerGroupId, producerId, epoch);
prepareFindCoordinatorResponse(Errors.NONE, false, CoordinatorType.GROUP, consumerGroupId);
runUntil(() -> transactionManager.coordinator(CoordinatorType.GROUP) != null);
client.prepareResponse(request -> {
TxnOffsetCommitRequest txnOffsetCommitRequest = (TxnOffsetCommitRequest) request;
assertEquals(consumerGroupId, txnOffsetCommitRequest.data().groupId());
assertEquals(producerId, txnOffsetCommitRequest.data().producerId());
assertEquals(epoch, txnOffsetCommitRequest.data().producerEpoch());
return txnOffsetCommitRequest.data().groupInstanceId().equals(groupInstanceId) && !txnOffsetCommitRequest.data().memberId().equals(memberId);
}, new TxnOffsetCommitResponse(0, singletonMap(tp, Errors.FENCED_INSTANCE_ID)));
runUntil(transactionManager::hasError);
assertTrue(transactionManager.lastError() instanceof FencedInstanceIdException);
assertTrue(sendOffsetsResult.isCompleted());
assertFalse(sendOffsetsResult.isSuccessful());
assertTrue(sendOffsetsResult.error() instanceof FencedInstanceIdException);
assertAbortableError(FencedInstanceIdException.class);
}
use of org.apache.kafka.common.requests.TxnOffsetCommitResponse in project kafka by apache.
the class TransactionManagerTest method testUnknownMemberIdInTxnOffsetCommitByGroupMetadata.
@Test
public void testUnknownMemberIdInTxnOffsetCommitByGroupMetadata() {
final TopicPartition tp = new TopicPartition("foo", 0);
final String unknownMemberId = "unknownMember";
doInitTransactions();
transactionManager.beginTransaction();
TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(tp, new OffsetAndMetadata(39L)), new ConsumerGroupMetadata(consumerGroupId, 5, unknownMemberId, Optional.empty()));
prepareAddOffsetsToTxnResponse(Errors.NONE, consumerGroupId, producerId, epoch);
prepareFindCoordinatorResponse(Errors.NONE, false, CoordinatorType.GROUP, consumerGroupId);
runUntil(() -> transactionManager.coordinator(CoordinatorType.GROUP) != null);
client.prepareResponse(request -> {
TxnOffsetCommitRequest txnOffsetCommitRequest = (TxnOffsetCommitRequest) request;
assertEquals(consumerGroupId, txnOffsetCommitRequest.data().groupId());
assertEquals(producerId, txnOffsetCommitRequest.data().producerId());
assertEquals(epoch, txnOffsetCommitRequest.data().producerEpoch());
return !txnOffsetCommitRequest.data().memberId().equals(memberId);
}, new TxnOffsetCommitResponse(0, singletonMap(tp, Errors.UNKNOWN_MEMBER_ID)));
runUntil(transactionManager::hasError);
assertTrue(transactionManager.lastError() instanceof CommitFailedException);
assertTrue(sendOffsetsResult.isCompleted());
assertFalse(sendOffsetsResult.isSuccessful());
assertTrue(sendOffsetsResult.error() instanceof CommitFailedException);
assertAbortableError(CommitFailedException.class);
}
use of org.apache.kafka.common.requests.TxnOffsetCommitResponse in project kafka by apache.
the class TransactionManagerTest method testIllegalGenerationInTxnOffsetCommitByGroupMetadata.
@Test
public void testIllegalGenerationInTxnOffsetCommitByGroupMetadata() {
final TopicPartition tp = new TopicPartition("foo", 0);
final int illegalGenerationId = 1;
doInitTransactions();
transactionManager.beginTransaction();
TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(tp, new OffsetAndMetadata(39L)), new ConsumerGroupMetadata(consumerGroupId, illegalGenerationId, JoinGroupRequest.UNKNOWN_MEMBER_ID, Optional.empty()));
prepareAddOffsetsToTxnResponse(Errors.NONE, consumerGroupId, producerId, epoch);
prepareFindCoordinatorResponse(Errors.NONE, false, CoordinatorType.GROUP, consumerGroupId);
runUntil(() -> transactionManager.coordinator(CoordinatorType.GROUP) != null);
prepareTxnOffsetCommitResponse(consumerGroupId, producerId, epoch, singletonMap(tp, Errors.ILLEGAL_GENERATION));
client.prepareResponse(request -> {
TxnOffsetCommitRequest txnOffsetCommitRequest = (TxnOffsetCommitRequest) request;
assertEquals(consumerGroupId, txnOffsetCommitRequest.data().groupId());
assertEquals(producerId, txnOffsetCommitRequest.data().producerId());
assertEquals(epoch, txnOffsetCommitRequest.data().producerEpoch());
return txnOffsetCommitRequest.data().generationId() != generationId;
}, new TxnOffsetCommitResponse(0, singletonMap(tp, Errors.ILLEGAL_GENERATION)));
runUntil(transactionManager::hasError);
assertTrue(transactionManager.lastError() instanceof CommitFailedException);
assertTrue(sendOffsetsResult.isCompleted());
assertFalse(sendOffsetsResult.isSuccessful());
assertTrue(sendOffsetsResult.error() instanceof CommitFailedException);
assertAbortableError(CommitFailedException.class);
}
use of org.apache.kafka.common.requests.TxnOffsetCommitResponse in project kafka by apache.
the class TransactionManagerTest method prepareTxnOffsetCommitResponse.
private void prepareTxnOffsetCommitResponse(final String consumerGroupId, final long producerId, final short producerEpoch, Map<TopicPartition, Errors> txnOffsetCommitResponse) {
client.prepareResponse(request -> {
TxnOffsetCommitRequest txnOffsetCommitRequest = (TxnOffsetCommitRequest) request;
assertEquals(consumerGroupId, txnOffsetCommitRequest.data().groupId());
assertEquals(producerId, txnOffsetCommitRequest.data().producerId());
assertEquals(producerEpoch, txnOffsetCommitRequest.data().producerEpoch());
return true;
}, new TxnOffsetCommitResponse(0, txnOffsetCommitResponse));
}
Aggregations