use of org.apache.kafka.common.record.EndTransactionMarker in project apache-kafka-on-k8s by banzaicloud.
the class FetcherTest method commitTransaction.
private int commitTransaction(ByteBuffer buffer, long producerId, long baseOffset) {
short producerEpoch = 0;
int partitionLeaderEpoch = 0;
MemoryRecords.writeEndTransactionalMarker(buffer, baseOffset, time.milliseconds(), partitionLeaderEpoch, producerId, producerEpoch, new EndTransactionMarker(ControlRecordType.COMMIT, 0));
return 1;
}
use of org.apache.kafka.common.record.EndTransactionMarker in project apache-kafka-on-k8s by banzaicloud.
the class FetcherTest method abortTransaction.
private int abortTransaction(ByteBuffer buffer, long producerId, long baseOffset) {
short producerEpoch = 0;
int partitionLeaderEpoch = 0;
MemoryRecords.writeEndTransactionalMarker(buffer, baseOffset, time.milliseconds(), partitionLeaderEpoch, producerId, producerEpoch, new EndTransactionMarker(ControlRecordType.ABORT, 0));
return 1;
}
use of org.apache.kafka.common.record.EndTransactionMarker in project kafka by apache.
the class FetcherTest method abortTransaction.
private int abortTransaction(ByteBuffer buffer, long producerId, long baseOffset) {
short producerEpoch = 0;
int partitionLeaderEpoch = 0;
MemoryRecords.writeEndTransactionalMarker(buffer, baseOffset, time.milliseconds(), partitionLeaderEpoch, producerId, producerEpoch, new EndTransactionMarker(ControlRecordType.ABORT, 0));
return 1;
}
use of org.apache.kafka.common.record.EndTransactionMarker in project kafka by apache.
the class FetcherTest method testFetcherIgnoresControlRecords.
@Test
public void testFetcherIgnoresControlRecords() {
buildFetcher();
assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
// normal fetch
assertEquals(1, fetcher.sendFetches());
assertFalse(fetcher.hasCompletedFetches());
long producerId = 1;
short producerEpoch = 0;
int baseSequence = 0;
int partitionLeaderEpoch = 0;
ByteBuffer buffer = ByteBuffer.allocate(1024);
MemoryRecordsBuilder builder = MemoryRecords.idempotentBuilder(buffer, CompressionType.NONE, 0L, producerId, producerEpoch, baseSequence);
builder.append(0L, "key".getBytes(), null);
builder.close();
MemoryRecords.writeEndTransactionalMarker(buffer, 1L, time.milliseconds(), partitionLeaderEpoch, producerId, producerEpoch, new EndTransactionMarker(ControlRecordType.ABORT, 0));
buffer.flip();
client.prepareResponse(fullFetchResponse(tidp0, MemoryRecords.readableRecords(buffer), Errors.NONE, 100L, 0));
consumerClient.poll(time.timer(0));
assertTrue(fetcher.hasCompletedFetches());
Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> partitionRecords = fetchedRecords();
assertTrue(partitionRecords.containsKey(tp0));
List<ConsumerRecord<byte[], byte[]>> records = partitionRecords.get(tp0);
assertEquals(1, records.size());
assertEquals(2L, subscriptions.position(tp0).offset);
ConsumerRecord<byte[], byte[]> record = records.get(0);
assertArrayEquals("key".getBytes(), record.key());
}
use of org.apache.kafka.common.record.EndTransactionMarker in project apache-kafka-on-k8s by banzaicloud.
the class FetcherTest method testFetcherIgnoresControlRecords.
@Test
public void testFetcherIgnoresControlRecords() {
subscriptions.assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
// normal fetch
assertEquals(1, fetcher.sendFetches());
assertFalse(fetcher.hasCompletedFetches());
long producerId = 1;
short producerEpoch = 0;
int baseSequence = 0;
int partitionLeaderEpoch = 0;
ByteBuffer buffer = ByteBuffer.allocate(1024);
MemoryRecordsBuilder builder = MemoryRecords.idempotentBuilder(buffer, CompressionType.NONE, 0L, producerId, producerEpoch, baseSequence);
builder.append(0L, "key".getBytes(), null);
builder.close();
MemoryRecords.writeEndTransactionalMarker(buffer, 1L, time.milliseconds(), partitionLeaderEpoch, producerId, producerEpoch, new EndTransactionMarker(ControlRecordType.ABORT, 0));
buffer.flip();
client.prepareResponse(fullFetchResponse(tp0, MemoryRecords.readableRecords(buffer), Errors.NONE, 100L, 0));
consumerClient.poll(0);
assertTrue(fetcher.hasCompletedFetches());
Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> partitionRecords = fetcher.fetchedRecords();
assertTrue(partitionRecords.containsKey(tp0));
List<ConsumerRecord<byte[], byte[]>> records = partitionRecords.get(tp0);
assertEquals(1, records.size());
assertEquals(2L, subscriptions.position(tp0).longValue());
ConsumerRecord<byte[], byte[]> record = records.get(0);
assertArrayEquals("key".getBytes(), record.key());
}
Aggregations