use of org.apache.pulsar.client.impl.schema.StringSchema in project incubator-pulsar by apache.
the class KeyValueSchemaCompatibilityCheckTest method testCheckSchemaTypeOtherCompatibility.
@Test
public void testCheckSchemaTypeOtherCompatibility() {
AvroSchema<Foo> fooSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
AvroSchema<Bar> barSchema = AvroSchema.of(SchemaDefinition.<Bar>builder().withPojo(Bar.class).build());
StringSchema stringSchema = new StringSchema();
SchemaData fromSchemaData = SchemaData.builder().type(SchemaType.STRING).data(stringSchema.getSchemaInfo().getSchema()).build();
SchemaData toSchemaData = SchemaData.builder().type(SchemaType.KEY_VALUE).data(KeyValueSchemaImpl.of(fooSchema, barSchema).getSchemaInfo().getSchema()).build();
Assert.assertFalse(checkers.get(SchemaType.KEY_VALUE).isCompatible(fromSchemaData, toSchemaData, SchemaCompatibilityStrategy.ALWAYS_INCOMPATIBLE));
}
use of org.apache.pulsar.client.impl.schema.StringSchema in project incubator-pulsar by apache.
the class KeyValueSchemaCompatibilityCheckTest method testCheckSchemaTypeAlwaysCompatibility.
@Test
public void testCheckSchemaTypeAlwaysCompatibility() {
AvroSchema<Foo> fooSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
AvroSchema<Bar> barSchema = AvroSchema.of(SchemaDefinition.<Bar>builder().withPojo(Bar.class).build());
StringSchema stringSchema = new StringSchema();
SchemaData fromSchemaData = SchemaData.builder().type(SchemaType.STRING).data(stringSchema.getSchemaInfo().getSchema()).build();
SchemaData toSchemaData = SchemaData.builder().type(SchemaType.KEY_VALUE).data(KeyValueSchemaImpl.of(fooSchema, barSchema).getSchemaInfo().getSchema()).build();
Assert.assertTrue(checkers.get(SchemaType.KEY_VALUE).isCompatible(fromSchemaData, toSchemaData, SchemaCompatibilityStrategy.ALWAYS_COMPATIBLE));
}
use of org.apache.pulsar.client.impl.schema.StringSchema in project pulsar by apache.
the class KeyValueSchemaCompatibilityCheckTest method testCheckSchemaTypeAlwaysCompatibility.
@Test
public void testCheckSchemaTypeAlwaysCompatibility() {
AvroSchema<Foo> fooSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
AvroSchema<Bar> barSchema = AvroSchema.of(SchemaDefinition.<Bar>builder().withPojo(Bar.class).build());
StringSchema stringSchema = new StringSchema();
SchemaData fromSchemaData = SchemaData.builder().type(SchemaType.STRING).data(stringSchema.getSchemaInfo().getSchema()).build();
SchemaData toSchemaData = SchemaData.builder().type(SchemaType.KEY_VALUE).data(KeyValueSchemaImpl.of(fooSchema, barSchema).getSchemaInfo().getSchema()).build();
Assert.assertTrue(checkers.get(SchemaType.KEY_VALUE).isCompatible(fromSchemaData, toSchemaData, SchemaCompatibilityStrategy.ALWAYS_COMPATIBLE));
}
use of org.apache.pulsar.client.impl.schema.StringSchema in project pulsar by apache.
the class KeyValueSchemaCompatibilityCheckTest method testCheckSchemaTypeOtherCompatibility.
@Test
public void testCheckSchemaTypeOtherCompatibility() {
AvroSchema<Foo> fooSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
AvroSchema<Bar> barSchema = AvroSchema.of(SchemaDefinition.<Bar>builder().withPojo(Bar.class).build());
StringSchema stringSchema = new StringSchema();
SchemaData fromSchemaData = SchemaData.builder().type(SchemaType.STRING).data(stringSchema.getSchemaInfo().getSchema()).build();
SchemaData toSchemaData = SchemaData.builder().type(SchemaType.KEY_VALUE).data(KeyValueSchemaImpl.of(fooSchema, barSchema).getSchemaInfo().getSchema()).build();
Assert.assertFalse(checkers.get(SchemaType.KEY_VALUE).isCompatible(fromSchemaData, toSchemaData, SchemaCompatibilityStrategy.ALWAYS_INCOMPATIBLE));
}
use of org.apache.pulsar.client.impl.schema.StringSchema in project pulsar-adapters by apache.
the class KafkaApiTest method testConsumerAvroSchemaWithPulsarKafkaClient.
@Test
public void testConsumerAvroSchemaWithPulsarKafkaClient() throws Exception {
String topic = "testConsumerAvroSchemaWithPulsarKafkaClient";
StringSchema stringSchema = new StringSchema();
AvroSchema<Foo> fooSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
Properties props = new Properties();
props.put("bootstrap.servers", getPlainTextServiceUrl());
props.put("group.id", "my-subscription-name");
props.put("enable.auto.commit", "false");
props.put("key.deserializer", StringDeserializer.class.getName());
props.put("value.deserializer", StringDeserializer.class.getName());
@Cleanup Consumer<String, Foo> consumer = new KafkaConsumer<String, Foo>(props, new StringSchema(), fooSchema);
consumer.subscribe(Arrays.asList(topic));
@Cleanup PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(getPlainTextServiceUrl()).build();
org.apache.pulsar.client.api.Producer<Foo> pulsarProducer = pulsarClient.newProducer(fooSchema).topic(topic).create();
for (int i = 0; i < 10; i++) {
Foo foo = new Foo();
foo.setField1("field1");
foo.setField2("field2");
foo.setField3(i);
pulsarProducer.newMessage().keyBytes(stringSchema.encode(Integer.toString(i))).value(foo).send();
}
AtomicInteger received = new AtomicInteger();
while (received.get() < 10) {
ConsumerRecords<String, Foo> records = consumer.poll(100);
if (!records.isEmpty()) {
records.forEach(record -> {
Assert.assertEquals(record.key(), Integer.toString(received.get()));
Foo value = record.value();
Assert.assertEquals(value.getField1(), "field1");
Assert.assertEquals(value.getField2(), "field2");
Assert.assertEquals(value.getField3(), received.get());
received.incrementAndGet();
});
consumer.commitSync();
}
}
}
Aggregations