use of org.apache.kafka.common.protocol.types.Field in project kafka by apache.
the class ConsumerProtocolTest method deserializeFutureSubscriptionVersion.
@Test
public void deserializeFutureSubscriptionVersion() {
// verify that a new version which adds a field is still parseable
short version = 100;
Schema subscriptionSchemaV100 = new Schema(new Field("topics", new ArrayOf(Type.STRING)), new Field("user_data", Type.NULLABLE_BYTES), new Field("owned_partitions", new ArrayOf(ConsumerProtocolSubscription.TopicPartition.SCHEMA_1)), new Field("foo", Type.STRING));
Struct subscriptionV100 = new Struct(subscriptionSchemaV100);
subscriptionV100.set("topics", new Object[] { "topic" });
subscriptionV100.set("user_data", ByteBuffer.wrap(new byte[0]));
subscriptionV100.set("owned_partitions", new Object[] { new Struct(ConsumerProtocolSubscription.TopicPartition.SCHEMA_1).set("topic", tp2.topic()).set("partitions", new Object[] { tp2.partition() }) });
subscriptionV100.set("foo", "bar");
Struct headerV100 = new Struct(new Schema(new Field("version", Type.INT16)));
headerV100.set("version", version);
ByteBuffer buffer = ByteBuffer.allocate(subscriptionV100.sizeOf() + headerV100.sizeOf());
headerV100.writeTo(buffer);
subscriptionV100.writeTo(buffer);
buffer.flip();
Subscription subscription = ConsumerProtocol.deserializeSubscription(buffer);
subscription.setGroupInstanceId(groupInstanceId);
assertEquals(Collections.singleton("topic"), toSet(subscription.topics()));
assertEquals(Collections.singleton(tp2), toSet(subscription.ownedPartitions()));
assertEquals(groupInstanceId, subscription.groupInstanceId());
}
use of org.apache.kafka.common.protocol.types.Field in project kafka by apache.
the class ConsumerProtocolTest method deserializeFutureAssignmentVersion.
@Test
public void deserializeFutureAssignmentVersion() {
// verify that a new version which adds a field is still parseable
short version = 100;
Schema assignmentSchemaV100 = new Schema(new Field("assigned_partitions", new ArrayOf(ConsumerProtocolAssignment.TopicPartition.SCHEMA_0)), new Field("user_data", Type.BYTES), new Field("foo", Type.STRING));
Struct assignmentV100 = new Struct(assignmentSchemaV100);
assignmentV100.set("assigned_partitions", new Object[] { new Struct(ConsumerProtocolAssignment.TopicPartition.SCHEMA_0).set("topic", tp1.topic()).set("partitions", new Object[] { tp1.partition() }) });
assignmentV100.set("user_data", ByteBuffer.wrap(new byte[0]));
assignmentV100.set("foo", "bar");
Struct headerV100 = new Struct(new Schema(new Field("version", Type.INT16)));
headerV100.set("version", version);
ByteBuffer buffer = ByteBuffer.allocate(assignmentV100.sizeOf() + headerV100.sizeOf());
headerV100.writeTo(buffer);
assignmentV100.writeTo(buffer);
buffer.flip();
Assignment assignment = ConsumerProtocol.deserializeAssignment(buffer);
assertEquals(toSet(Collections.singletonList(tp1)), toSet(assignment.partitions()));
}
Aggregations