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();
}
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());
}
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());
}
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);
}
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()));
}
Aggregations