use of org.apache.kafka.common.protocol.ObjectSerializationCache in project kafka by apache.
the class BatchAccumulatorTest method recordSizeInBytes.
int recordSizeInBytes(String record, int numberOfRecords) {
int serdeSize = serde.recordSize("a", new ObjectSerializationCache());
int recordSizeInBytes = DefaultRecord.sizeOfBodyInBytes(numberOfRecords, 0, -1, serdeSize, DefaultRecord.EMPTY_HEADERS);
return ByteUtils.sizeOfVarint(recordSizeInBytes) + recordSizeInBytes;
}
use of org.apache.kafka.common.protocol.ObjectSerializationCache in project kafka by apache.
the class RequestResponseTest method testResponseHeader.
@Test
public void testResponseHeader() {
ResponseHeader header = new ResponseHeader(10, (short) 1);
ObjectSerializationCache serializationCache = new ObjectSerializationCache();
ByteBuffer buffer = ByteBuffer.allocate(header.size(serializationCache));
header.write(buffer, serializationCache);
buffer.flip();
ResponseHeader deserialized = ResponseHeader.parse(buffer, header.headerVersion());
assertEquals(header.correlationId(), deserialized.correlationId());
}
use of org.apache.kafka.common.protocol.ObjectSerializationCache in project kafka by apache.
the class RequestResponseTest method testFetchRequestCompat.
@Test
public void testFetchRequestCompat() {
Map<TopicPartition, FetchRequest.PartitionData> fetchData = new HashMap<>();
fetchData.put(new TopicPartition("test", 0), new FetchRequest.PartitionData(Uuid.ZERO_UUID, 100, 2, 100, Optional.of(42)));
FetchRequest req = FetchRequest.Builder.forConsumer((short) 2, 100, 100, fetchData).metadata(new FetchMetadata(10, 20)).isolationLevel(IsolationLevel.READ_COMMITTED).build((short) 2);
FetchRequestData data = req.data();
ObjectSerializationCache cache = new ObjectSerializationCache();
int size = data.size(cache, (short) 2);
ByteBufferAccessor writer = new ByteBufferAccessor(ByteBuffer.allocate(size));
data.write(writer, cache, (short) 2);
}
use of org.apache.kafka.common.protocol.ObjectSerializationCache in project kafka by apache.
the class RequestHeaderTest method parseHeaderWithNullClientId.
@Test
public void parseHeaderWithNullClientId() {
RequestHeaderData headerData = new RequestHeaderData().setClientId(null).setCorrelationId(123).setRequestApiKey(ApiKeys.FIND_COORDINATOR.id).setRequestApiVersion((short) 10);
ObjectSerializationCache serializationCache = new ObjectSerializationCache();
ByteBuffer buffer = ByteBuffer.allocate(headerData.size(serializationCache, (short) 2));
headerData.write(new ByteBufferAccessor(buffer), serializationCache, (short) 2);
buffer.flip();
RequestHeader parsed = RequestHeader.parse(buffer);
assertEquals("", parsed.clientId());
assertEquals(123, parsed.correlationId());
assertEquals(ApiKeys.FIND_COORDINATOR, parsed.apiKey());
assertEquals((short) 10, parsed.apiVersion());
}
use of org.apache.kafka.common.protocol.ObjectSerializationCache in project kafka by apache.
the class MetadataRecordSerdeTest method testSerde.
@Test
public void testSerde() {
TopicRecord topicRecord = new TopicRecord().setName("foo").setTopicId(Uuid.randomUuid());
MetadataRecordSerde serde = new MetadataRecordSerde();
for (short version = TopicRecord.LOWEST_SUPPORTED_VERSION; version <= TopicRecord.HIGHEST_SUPPORTED_VERSION; version++) {
ApiMessageAndVersion messageAndVersion = new ApiMessageAndVersion(topicRecord, version);
ObjectSerializationCache cache = new ObjectSerializationCache();
int size = serde.recordSize(messageAndVersion, cache);
ByteBuffer buffer = ByteBuffer.allocate(size);
ByteBufferAccessor bufferAccessor = new ByteBufferAccessor(buffer);
serde.write(messageAndVersion, cache, bufferAccessor);
buffer.flip();
assertEquals(size, buffer.remaining());
ApiMessageAndVersion readMessageAndVersion = serde.read(bufferAccessor, size);
assertEquals(messageAndVersion, readMessageAndVersion);
}
}
Aggregations