use of org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider in project pulsar by apache.
the class MessageImplTest method testDefaultJSONVersionGetProducerDataAssigned.
@Test
public void testDefaultJSONVersionGetProducerDataAssigned() {
JSONSchema<SchemaTestUtils.Foo> fooSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
JSONSchema<SchemaTestUtils.Bar> barSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
MultiVersionSchemaInfoProvider multiVersionSchemaInfoProvider = mock(MultiVersionSchemaInfoProvider.class);
Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema);
keyValueSchema.setSchemaInfoProvider(multiVersionSchemaInfoProvider);
when(multiVersionSchemaInfoProvider.getSchemaByVersion(any(byte[].class))).thenReturn(CompletableFuture.completedFuture(keyValueSchema.getSchemaInfo()));
SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
foo.setField1("field1");
foo.setField2("field2");
foo.setField3(3);
SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
bar.setField1(true);
byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
MessageMetadata builder = new MessageMetadata().setProducerName("default");
builder.setSchemaVersion(new byte[10]);
MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema, null);
KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
assertEquals(keyValue.getKey(), foo);
assertEquals(keyValue.getValue(), bar);
assertFalse(builder.hasPartitionKey());
Assert.assertEquals(KeyValueEncodingType.valueOf(keyValueSchema.getSchemaInfo().getProperties().get("kv.encoding.type")), KeyValueEncodingType.INLINE);
}
use of org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider in project pulsar by apache.
the class MessageImplTest method testSeparatedJSONVersionGetProducerDataAssigned.
@Test
public void testSeparatedJSONVersionGetProducerDataAssigned() {
JSONSchema<SchemaTestUtils.Foo> fooSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
JSONSchema<SchemaTestUtils.Bar> barSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
MultiVersionSchemaInfoProvider multiVersionSchemaInfoProvider = mock(MultiVersionSchemaInfoProvider.class);
Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema, KeyValueEncodingType.SEPARATED);
keyValueSchema.setSchemaInfoProvider(multiVersionSchemaInfoProvider);
when(multiVersionSchemaInfoProvider.getSchemaByVersion(any(byte[].class))).thenReturn(CompletableFuture.completedFuture(keyValueSchema.getSchemaInfo()));
SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
foo.setField1("field1");
foo.setField2("field2");
foo.setField3(3);
SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
bar.setField1(true);
byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
MessageMetadata builder = new MessageMetadata().setProducerName("separated");
builder.setSchemaVersion(new byte[10]);
builder.setPartitionKey(Base64.getEncoder().encodeToString(fooSchema.encode(foo)));
builder.setPartitionKeyB64Encoded(true);
MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema, null);
KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
assertEquals(keyValue.getKey(), foo);
assertEquals(keyValue.getValue(), bar);
assertTrue(builder.hasPartitionKey());
Assert.assertEquals(KeyValueEncodingType.valueOf(keyValueSchema.getSchemaInfo().getProperties().get("kv.encoding.type")), KeyValueEncodingType.SEPARATED);
}
use of org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider in project pulsar by apache.
the class MessageImplTest method testSeparatedAVROJSONVersionGetProducerDataAssigned.
@Test
public void testSeparatedAVROJSONVersionGetProducerDataAssigned() {
AvroSchema<SchemaTestUtils.Foo> fooSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
JSONSchema<SchemaTestUtils.Bar> barSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
MultiVersionSchemaInfoProvider multiVersionSchemaInfoProvider = mock(MultiVersionSchemaInfoProvider.class);
Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema, KeyValueEncodingType.SEPARATED);
keyValueSchema.setSchemaInfoProvider(multiVersionSchemaInfoProvider);
when(multiVersionSchemaInfoProvider.getSchemaByVersion(any(byte[].class))).thenReturn(CompletableFuture.completedFuture(keyValueSchema.getSchemaInfo()));
SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
foo.setField1("field1");
foo.setField2("field2");
foo.setField3(3);
SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
bar.setField1(true);
byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
MessageMetadata builder = new MessageMetadata().setProducerName("separated");
builder.setSchemaVersion(new byte[10]);
builder.setPartitionKey(Base64.getEncoder().encodeToString(fooSchema.encode(foo)));
builder.setPartitionKeyB64Encoded(true);
MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema, null);
KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
assertEquals(keyValue.getKey(), foo);
assertEquals(keyValue.getValue(), bar);
assertTrue(builder.hasPartitionKey());
Assert.assertEquals(KeyValueEncodingType.valueOf(keyValueSchema.getSchemaInfo().getProperties().get("kv.encoding.type")), KeyValueEncodingType.SEPARATED);
}
use of org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider in project pulsar by yahoo.
the class MessageImplTest method testSeparatedAVROVersionGetProducerDataAssigned.
@Test
public void testSeparatedAVROVersionGetProducerDataAssigned() {
AvroSchema<SchemaTestUtils.Foo> fooSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
AvroSchema<SchemaTestUtils.Bar> barSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
MultiVersionSchemaInfoProvider multiVersionSchemaInfoProvider = mock(MultiVersionSchemaInfoProvider.class);
Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema, KeyValueEncodingType.SEPARATED);
keyValueSchema.setSchemaInfoProvider(multiVersionSchemaInfoProvider);
when(multiVersionSchemaInfoProvider.getSchemaByVersion(any(byte[].class))).thenReturn(CompletableFuture.completedFuture(keyValueSchema.getSchemaInfo()));
SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
foo.setField1("field1");
foo.setField2("field2");
foo.setField3(3);
SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
bar.setField1(true);
byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
MessageMetadata builder = new MessageMetadata().setProducerName("separated");
builder.setSchemaVersion(new byte[10]);
builder.setPartitionKey(Base64.getEncoder().encodeToString(fooSchema.encode(foo)));
builder.setPartitionKeyB64Encoded(true);
MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema, null);
KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
assertEquals(keyValue.getKey(), foo);
assertEquals(keyValue.getValue(), bar);
assertTrue(builder.hasPartitionKey());
Assert.assertEquals(KeyValueEncodingType.valueOf(keyValueSchema.getSchemaInfo().getProperties().get("kv.encoding.type")), KeyValueEncodingType.SEPARATED);
}
use of org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider in project pulsar by yahoo.
the class MessageImplTest method testDefaultAVROJSONVersionGetProducerDataAssigned.
@Test
public void testDefaultAVROJSONVersionGetProducerDataAssigned() {
AvroSchema<SchemaTestUtils.Foo> fooSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
JSONSchema<SchemaTestUtils.Bar> barSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
MultiVersionSchemaInfoProvider multiVersionSchemaInfoProvider = mock(MultiVersionSchemaInfoProvider.class);
Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema);
keyValueSchema.setSchemaInfoProvider(multiVersionSchemaInfoProvider);
when(multiVersionSchemaInfoProvider.getSchemaByVersion(any(byte[].class))).thenReturn(CompletableFuture.completedFuture(keyValueSchema.getSchemaInfo()));
SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
foo.setField1("field1");
foo.setField2("field2");
foo.setField3(3);
SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
bar.setField1(true);
byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
MessageMetadata builder = new MessageMetadata().setProducerName("default");
builder.setSchemaVersion(new byte[10]);
MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema, null);
KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
assertEquals(keyValue.getKey(), foo);
assertEquals(keyValue.getValue(), bar);
assertFalse(builder.hasPartitionKey());
Assert.assertEquals(KeyValueEncodingType.valueOf(keyValueSchema.getSchemaInfo().getProperties().get("kv.encoding.type")), KeyValueEncodingType.INLINE);
}
Aggregations