Search in sources :

Example 66 with MemoryRecordsBuilder

use of org.apache.kafka.common.record.MemoryRecordsBuilder in project starlight-for-kafka by datastax.

the class GroupMetadataManagerTest method appendTransactionalOffsetCommits.

private int appendTransactionalOffsetCommits(ByteBuffer buffer, long producerId, short producerEpoch, long baseOffset, Map<TopicPartition, Long> offsets, String namespacePrefix) {
    MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, CompressionType.NONE, baseOffset, producerId, producerEpoch, 0, true);
    List<SimpleRecord> commitRecords = createCommittedOffsetRecords(offsets, groupId, namespacePrefix);
    commitRecords.forEach(builder::append);
    builder.build();
    return offsets.size();
}
Also used : SimpleRecord(org.apache.kafka.common.record.SimpleRecord) MemoryRecordsBuilder(org.apache.kafka.common.record.MemoryRecordsBuilder)

Example 67 with MemoryRecordsBuilder

use of org.apache.kafka.common.record.MemoryRecordsBuilder in project starlight-for-kafka by datastax.

the class GroupMetadataManagerTest method completeTransactionalOffsetCommit.

private int completeTransactionalOffsetCommit(ByteBuffer buffer, long producerId, short producerEpoch, long baseOffset, boolean isCommit) {
    MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, RecordBatch.MAGIC_VALUE_V2, CompressionType.NONE, TimestampType.LOG_APPEND_TIME, baseOffset, Time.SYSTEM.milliseconds(), producerId, producerEpoch, 0, true, true, RecordBatch.NO_PARTITION_LEADER_EPOCH);
    ControlRecordType controlRecordType;
    if (isCommit) {
        controlRecordType = ControlRecordType.COMMIT;
    } else {
        controlRecordType = ControlRecordType.ABORT;
    }
    builder.appendEndTxnMarker(Time.SYSTEM.milliseconds(), new EndTransactionMarker(controlRecordType, 0));
    builder.build();
    return 1;
}
Also used : EndTransactionMarker(org.apache.kafka.common.record.EndTransactionMarker) MemoryRecordsBuilder(org.apache.kafka.common.record.MemoryRecordsBuilder) ControlRecordType(org.apache.kafka.common.record.ControlRecordType)

Example 68 with MemoryRecordsBuilder

use of org.apache.kafka.common.record.MemoryRecordsBuilder in project starlight-for-kafka by datastax.

the class PartitionLogTest method buildIdempotentRecords.

private MemoryRecords buildIdempotentRecords(int[] batchSizes) {
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    int baseOffset = 0;
    for (int batchSize : batchSizes) {
        MemoryRecordsBuilder builder = MemoryRecords.idempotentBuilder(buffer, CompressionType.NONE, baseOffset, 0, (short) 0, 0);
        for (int i = 0; i < batchSize; i++) {
            builder.append(0L, "a".getBytes(), "1".getBytes());
        }
        builder.close();
    }
    buffer.flip();
    return MemoryRecords.readableRecords(buffer);
}
Also used : MemoryRecordsBuilder(org.apache.kafka.common.record.MemoryRecordsBuilder) ByteBuffer(java.nio.ByteBuffer)

Example 69 with MemoryRecordsBuilder

use of org.apache.kafka.common.record.MemoryRecordsBuilder in project starlight-for-kafka by datastax.

the class PartitionLogTest method buildMemoryRecords.

private MemoryRecords buildMemoryRecords(int[] batchSizes, CompressionType compressionType, int valueSize) {
    int totalBatchSize = 0;
    for (int batchSize : batchSizes) {
        totalBatchSize += batchSize;
    }
    ByteBuffer buffer = ByteBuffer.allocate(valueSize * totalBatchSize * 2);
    int baseOffset = 0;
    for (int batchSize : batchSizes) {
        MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, RecordBatch.CURRENT_MAGIC_VALUE, compressionType, TimestampType.LOG_APPEND_TIME, baseOffset);
        for (int i = 0; i < batchSize; i++) {
            builder.append(0L, "a".getBytes(), new byte[valueSize]);
        }
        builder.close();
    }
    buffer.flip();
    return MemoryRecords.readableRecords(buffer);
}
Also used : MemoryRecordsBuilder(org.apache.kafka.common.record.MemoryRecordsBuilder) ByteBuffer(java.nio.ByteBuffer)

Example 70 with MemoryRecordsBuilder

use of org.apache.kafka.common.record.MemoryRecordsBuilder in project starlight-for-kafka by datastax.

the class KafkaApisTest method newAbortTxnMarker.

private static MemoryRecords newAbortTxnMarker() {
    final MemoryRecordsBuilder builder = MemoryRecords.builder(ByteBuffer.allocate(1024), RecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, TimestampType.CREATE_TIME, 0L, 0L, System.currentTimeMillis(), (short) 0, 0, true, true, /* isControlBatch */
    0);
    builder.appendEndTxnMarker(System.currentTimeMillis(), new EndTransactionMarker(ControlRecordType.ABORT, 0));
    return builder.build();
}
Also used : EndTransactionMarker(org.apache.kafka.common.record.EndTransactionMarker) MemoryRecordsBuilder(org.apache.kafka.common.record.MemoryRecordsBuilder)

Aggregations

MemoryRecordsBuilder (org.apache.kafka.common.record.MemoryRecordsBuilder)97 ByteBuffer (java.nio.ByteBuffer)50 MemoryRecords (org.apache.kafka.common.record.MemoryRecords)36 TopicPartition (org.apache.kafka.common.TopicPartition)30 HashMap (java.util.HashMap)26 SimpleRecord (org.apache.kafka.common.record.SimpleRecord)25 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 List (java.util.List)17 Record (org.apache.kafka.common.record.Record)17 LinkedHashMap (java.util.LinkedHashMap)16 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)14 MetricName (org.apache.kafka.common.MetricName)14 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)14 Arrays.asList (java.util.Arrays.asList)10 CompressionType (org.apache.kafka.common.record.CompressionType)10 RecordBatch (org.apache.kafka.common.record.RecordBatch)10 Header (org.apache.kafka.common.header.Header)9 EndTransactionMarker (org.apache.kafka.common.record.EndTransactionMarker)9