Search in sources :

Example 1 with LocalSchemaRegistryServer

use of com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer in project registry by hortonworks.

the class ConfluentProtocolCompatibleTest method testRegistryProduceConfluentConsume.

@Test
public void testRegistryProduceConfluentConsume() throws Exception {
    String configPath = new File(Resources.getResource("schema-registry-test.yaml").toURI()).getAbsolutePath();
    LocalSchemaRegistryServer localSchemaRegistryServer = new LocalSchemaRegistryServer(configPath);
    try {
        localSchemaRegistryServer.start();
        final String confluentUrl = String.format("http://localhost:%d/api/v1/confluent", localSchemaRegistryServer.getLocalPort());
        final String registryUrl = String.format("http://localhost:%d/api/v1", localSchemaRegistryServer.getLocalPort());
        Map<String, Object> confluentConfig = new HashMap<>();
        confluentConfig.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, confluentUrl);
        Map<String, Object> registryConfig = new HashMap<>();
        registryConfig.put(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), registryUrl);
        registryConfig.put(SERDES_PROTOCOL_VERSION, SerDesProtocolHandlerRegistry.CONFLUENT_VERSION_PROTOCOL);
        Schema schema = new Schema.Parser().parse(GENERIC_TEST_RECORD_SCHEMA);
        GenericRecord record = new GenericRecordBuilder(schema).set("field1", "some value").set("field2", "some other value").build();
        KafkaAvroSerializer kafkaAvroSerializer = new KafkaAvroSerializer();
        kafkaAvroSerializer.configure(registryConfig, false);
        byte[] bytes = kafkaAvroSerializer.serialize("topic", record);
        KafkaAvroDeserializer kafkaAvroDeserializer = new KafkaAvroDeserializer();
        kafkaAvroDeserializer.configure(registryConfig, false);
        GenericRecord registryResult = (GenericRecord) kafkaAvroDeserializer.deserialize("topic", bytes);
        LOG.info(registryResult.toString());
        io.confluent.kafka.serializers.KafkaAvroDeserializer confluentKafkaAvroDeserializer = new io.confluent.kafka.serializers.KafkaAvroDeserializer();
        confluentKafkaAvroDeserializer.configure(confluentConfig, false);
        GenericRecord confluentResult = (GenericRecord) confluentKafkaAvroDeserializer.deserialize("topic", bytes);
        LOG.info(confluentResult.toString());
        Assert.assertEquals(record, registryResult);
        Assert.assertEquals(record, confluentResult);
        Assert.assertEquals(registryResult, confluentResult);
    } finally {
        localSchemaRegistryServer.stop();
    }
}
Also used : HashMap(java.util.HashMap) LocalSchemaRegistryServer(com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer) Schema(org.apache.avro.Schema) KafkaAvroSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.kafka.KafkaAvroSerializer) KafkaAvroDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.kafka.KafkaAvroDeserializer) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) GenericRecord(org.apache.avro.generic.GenericRecord) File(java.io.File) Test(org.junit.Test)

Example 2 with LocalSchemaRegistryServer

use of com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer in project registry by hortonworks.

the class ConfluentProtocolCompatibleTest method testConfluentProduceRegistryConsume.

@Test
public void testConfluentProduceRegistryConsume() throws Exception {
    String configPath = new File(Resources.getResource("schema-registry-test.yaml").toURI()).getAbsolutePath();
    LocalSchemaRegistryServer localSchemaRegistryServer = new LocalSchemaRegistryServer(configPath);
    try {
        localSchemaRegistryServer.start();
        final String confluentUrl = String.format("http://localhost:%d/api/v1/confluent", localSchemaRegistryServer.getLocalPort());
        final String registryUrl = String.format("http://localhost:%d/api/v1", localSchemaRegistryServer.getLocalPort());
        Map<String, Object> confluentConfig = new HashMap<>();
        confluentConfig.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, confluentUrl);
        Map<String, Object> registryConfig = new HashMap<>();
        registryConfig.put(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), registryUrl);
        Schema schema = new Schema.Parser().parse(GENERIC_TEST_RECORD_SCHEMA);
        GenericRecord record = new GenericRecordBuilder(schema).set("field1", "some value").set("field2", "some other value").build();
        io.confluent.kafka.serializers.KafkaAvroSerializer kafkaAvroSerializer = new io.confluent.kafka.serializers.KafkaAvroSerializer();
        kafkaAvroSerializer.configure(confluentConfig, false);
        byte[] bytes = kafkaAvroSerializer.serialize("topic", record);
        io.confluent.kafka.serializers.KafkaAvroDeserializer confluentKafkaAvroDeserializer = new io.confluent.kafka.serializers.KafkaAvroDeserializer();
        confluentKafkaAvroDeserializer.configure(confluentConfig, false);
        GenericRecord confluentResult = (GenericRecord) confluentKafkaAvroDeserializer.deserialize("topic", bytes);
        LOG.info(confluentResult.toString());
        KafkaAvroDeserializer kafkaAvroDeserializer = new KafkaAvroDeserializer();
        kafkaAvroDeserializer.configure(registryConfig, false);
        GenericRecord registryResult = (GenericRecord) kafkaAvroDeserializer.deserialize("topic", bytes);
        LOG.info(registryResult.toString());
        Assert.assertEquals(record, registryResult);
        Assert.assertEquals(record, confluentResult);
        Assert.assertEquals(registryResult, confluentResult);
    } finally {
        localSchemaRegistryServer.stop();
    }
}
Also used : HashMap(java.util.HashMap) LocalSchemaRegistryServer(com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer) Schema(org.apache.avro.Schema) KafkaAvroSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.kafka.KafkaAvroSerializer) KafkaAvroDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.kafka.KafkaAvroDeserializer) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) GenericRecord(org.apache.avro.generic.GenericRecord) File(java.io.File) Test(org.junit.Test)

Example 3 with LocalSchemaRegistryServer

use of com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer in project registry by hortonworks.

the class SchemaLifecycleApp method startUp.

public static void startUp() throws Exception {
    LOCAL_SCHEMA_REGISTRY_SERVER = new LocalSchemaRegistryServer(SchemaLifecycleApp.class.getClassLoader().getResource("registry-lifecycle-example.yaml").getPath());
    LOCAL_SCHEMA_REGISTRY_SERVER.start();
}
Also used : LocalSchemaRegistryServer(com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer)

Example 4 with LocalSchemaRegistryServer

use of com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer in project registry by hortonworks.

the class ConfluentRegistryCompatibleResourceTest method setup.

@Before
public void setup() throws Exception {
    String configPath = new File(Resources.getResource("schema-registry-test.yaml").toURI()).getAbsolutePath();
    localSchemaRegistryServer = new LocalSchemaRegistryServer(configPath);
    localSchemaRegistryServer.start();
    String rootUrl = String.format("http://localhost:%d/api/v1/confluent", localSchemaRegistryServer.getLocalPort());
    rootTarget = createRootTarget(rootUrl);
}
Also used : LocalSchemaRegistryServer(com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer) SchemaString(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString) File(java.io.File) Before(org.junit.Before)

Aggregations

LocalSchemaRegistryServer (com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer)4 File (java.io.File)3 KafkaAvroDeserializer (com.hortonworks.registries.schemaregistry.serdes.avro.kafka.KafkaAvroDeserializer)2 KafkaAvroSerializer (com.hortonworks.registries.schemaregistry.serdes.avro.kafka.KafkaAvroSerializer)2 HashMap (java.util.HashMap)2 Schema (org.apache.avro.Schema)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)2 Test (org.junit.Test)2 SchemaString (com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString)1 Before (org.junit.Before)1