Search in sources :

Example 16 with ObjectSerializationCache

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;
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache)

Example 17 with ObjectSerializationCache

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());
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 18 with ObjectSerializationCache

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);
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) FetchRequestData(org.apache.kafka.common.message.FetchRequestData) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) UpdateMetadataEndpoint(org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataEndpoint) Test(org.junit.jupiter.api.Test)

Example 19 with ObjectSerializationCache

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());
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache) RequestHeaderData(org.apache.kafka.common.message.RequestHeaderData) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 20 with ObjectSerializationCache

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);
    }
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache) TopicRecord(org.apache.kafka.common.metadata.TopicRecord) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectSerializationCache (org.apache.kafka.common.protocol.ObjectSerializationCache)21 ByteBuffer (java.nio.ByteBuffer)13 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)13 Test (org.junit.jupiter.api.Test)7 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)3 FetchResponseData (org.apache.kafka.common.message.FetchResponseData)2 UpdateMetadataEndpoint (org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataEndpoint)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 OptionalLong (java.util.OptionalLong)1 ExecutionException (java.util.concurrent.ExecutionException)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 FetchRequestData (org.apache.kafka.common.message.FetchRequestData)1 LeaderChangeMessage (org.apache.kafka.common.message.LeaderChangeMessage)1 Voter (org.apache.kafka.common.message.LeaderChangeMessage.Voter)1 RequestHeaderData (org.apache.kafka.common.message.RequestHeaderData)1 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)1 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)1 Send (org.apache.kafka.common.network.Send)1