Search in sources :

Example 96 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project apache-kafka-on-k8s by banzaicloud.

the class RequestResponseTest method checkRequest.

private void checkRequest(AbstractRequest req) throws Exception {
    // Check that we can serialize, deserialize and serialize again
    // We don't check for equality or hashCode because it is likely to fail for any request containing a HashMap
    Struct struct = req.toStruct();
    AbstractRequest deserialized = (AbstractRequest) deserialize(req, struct, req.version());
    deserialized.toStruct();
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 97 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project apache-kafka-on-k8s by banzaicloud.

the class RequestResponseTest method verifyFetchResponseFullWrite.

private void verifyFetchResponseFullWrite(short apiVersion, FetchResponse fetchResponse) throws Exception {
    int correlationId = 15;
    Send send = fetchResponse.toSend("1", new ResponseHeader(correlationId), apiVersion);
    ByteBufferChannel channel = new ByteBufferChannel(send.size());
    send.writeTo(channel);
    channel.close();
    ByteBuffer buf = channel.buffer();
    // read the size
    int size = buf.getInt();
    assertTrue(size > 0);
    // read the header
    ResponseHeader responseHeader = ResponseHeader.parse(channel.buffer());
    assertEquals(correlationId, responseHeader.correlationId());
    // read the body
    Struct responseBody = ApiKeys.FETCH.responseSchema(apiVersion).read(buf);
    assertEquals(fetchResponse.toStruct(apiVersion), responseBody);
    assertEquals(size, responseHeader.sizeOf() + responseBody.sizeOf());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Send(org.apache.kafka.common.network.Send) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 98 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project apache-kafka-on-k8s by banzaicloud.

the class RequestResponseTest method testFetchRequestIsolationLevel.

@Test
public void testFetchRequestIsolationLevel() throws Exception {
    FetchRequest request = createFetchRequest(4, IsolationLevel.READ_COMMITTED);
    Struct struct = request.toStruct();
    FetchRequest deserialized = (FetchRequest) deserialize(request, struct, request.version());
    assertEquals(request.isolationLevel(), deserialized.isolationLevel());
    request = createFetchRequest(4, IsolationLevel.READ_UNCOMMITTED);
    struct = request.toStruct();
    deserialized = (FetchRequest) deserialize(request, struct, request.version());
    assertEquals(request.isolationLevel(), deserialized.isolationLevel());
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct) Test(org.junit.Test)

Example 99 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project apache-kafka-on-k8s by banzaicloud.

the class RequestResponseTest method checkResponse.

private void checkResponse(AbstractResponse response, int version) throws Exception {
    // Check that we can serialize, deserialize and serialize again
    // We don't check for equality or hashCode because it is likely to fail for any response containing a HashMap
    Struct struct = response.toStruct((short) version);
    AbstractResponse deserialized = (AbstractResponse) deserialize(response, struct, (short) version);
    deserialized.toStruct((short) version);
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 100 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project apache-kafka-on-k8s by banzaicloud.

the class ConsumerProtocolTest method deserializeNewAssignmentVersion.

@Test
public void deserializeNewAssignmentVersion() {
    // verify that a new version which adds a field is still parseable
    short version = 100;
    Schema assignmentSchemaV100 = new Schema(new Field(ConsumerProtocol.TOPIC_PARTITIONS_KEY_NAME, new ArrayOf(ConsumerProtocol.TOPIC_ASSIGNMENT_V0)), new Field(ConsumerProtocol.USER_DATA_KEY_NAME, Type.BYTES), new Field("foo", Type.STRING));
    Struct assignmentV100 = new Struct(assignmentSchemaV100);
    assignmentV100.set(ConsumerProtocol.TOPIC_PARTITIONS_KEY_NAME, new Object[] { new Struct(ConsumerProtocol.TOPIC_ASSIGNMENT_V0).set(ConsumerProtocol.TOPIC_KEY_NAME, "foo").set(ConsumerProtocol.PARTITIONS_KEY_NAME, new Object[] { 1 }) });
    assignmentV100.set(ConsumerProtocol.USER_DATA_KEY_NAME, ByteBuffer.wrap(new byte[0]));
    assignmentV100.set("foo", "bar");
    Struct headerV100 = new Struct(ConsumerProtocol.CONSUMER_PROTOCOL_HEADER_SCHEMA);
    headerV100.set(ConsumerProtocol.VERSION_KEY_NAME, version);
    ByteBuffer buffer = ByteBuffer.allocate(assignmentV100.sizeOf() + headerV100.sizeOf());
    headerV100.writeTo(buffer);
    assignmentV100.writeTo(buffer);
    buffer.flip();
    PartitionAssignor.Assignment assignment = ConsumerProtocol.deserializeAssignment(buffer);
    assertEquals(toSet(Arrays.asList(new TopicPartition("foo", 1))), toSet(assignment.partitions()));
}
Also used : Field(org.apache.kafka.common.protocol.types.Field) ArrayOf(org.apache.kafka.common.protocol.types.ArrayOf) TopicPartition(org.apache.kafka.common.TopicPartition) Schema(org.apache.kafka.common.protocol.types.Schema) ByteBuffer(java.nio.ByteBuffer) Struct(org.apache.kafka.common.protocol.types.Struct) Test(org.junit.Test)

Aggregations

Struct (org.apache.kafka.common.protocol.types.Struct)251 ArrayList (java.util.ArrayList)94 ByteBuffer (java.nio.ByteBuffer)90 Map (java.util.Map)73 HashMap (java.util.HashMap)68 TopicPartition (org.apache.kafka.common.TopicPartition)37 Schema (org.apache.kafka.common.protocol.types.Schema)23 List (java.util.List)22 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)15 Test (org.junit.Test)15 Errors (org.apache.kafka.common.protocol.Errors)13 Field (org.apache.kafka.common.protocol.types.Field)13 ByteBuf (io.netty.buffer.ByteBuf)12 ArrayOf (org.apache.kafka.common.protocol.types.ArrayOf)12 RequestHeader (org.apache.kafka.common.requests.RequestHeader)11 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)10 GroupTopicPartition (io.streamnative.pulsar.handlers.kop.coordinator.group.GroupMetadataManager.GroupTopicPartition)8 ByteBufferSend (org.apache.kafka.common.network.ByteBufferSend)8 LinkedHashMap (java.util.LinkedHashMap)7 Lists (com.google.common.collect.Lists)6