Search in sources :

Example 6 with SchemaIdVersion

use of com.hortonworks.registries.schemaregistry.SchemaIdVersion in project registry by hortonworks.

the class LocalRegistryServerHATest method testHASanity.

@Test
public void testHASanity() throws Exception {
    SchemaRegistryTestServerClientWrapper followerServer = followerSchemaRegistryServer();
    SchemaRegistryClient schemaRegistryClient = followerServer.getClient();
    // registering schema metadata on follower, this should have been redirected to leader.
    String schemaName = "foo";
    SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(schemaName).type("avro").build();
    Long schemaId = schemaRegistryClient.registerSchemaMetadata(schemaMetadata);
    Assert.assertNotNull(schemaId);
    // registering a new schema on follower, this should have been redirected to leader.
    String schema1 = IOUtils.toString(LocalRegistryServerTest.class.getResourceAsStream("/schema-1.avsc"), "UTF-8");
    SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaName, new SchemaVersion(schema1, "Initial version of the schema"));
    // retrieve schema on leader as the schema data is stored in memory in leader. this data does not exist on
    // followers as the storage is inmemory.
    SchemaRegistryTestServerClientWrapper leaderServer = leaderSchemaRegistryServer();
    int leaderPort = leaderServer.getLocalPort();
    SchemaRegistryClient leaderClient = leaderServer.getClient();
    SchemaMetadataInfo schemaMetadataInfo = leaderClient.getSchemaMetadataInfo(schemaName);
    Assert.assertEquals(schemaMetadata, schemaMetadataInfo.getSchemaMetadata());
    // stop the leader server
    leaderServer.stopTestServer();
    // get the new leader server and run operations.
    SchemaRegistryTestServerClientWrapper newLeaderServer = leaderSchemaRegistryServer();
    Assert.assertNotEquals(leaderPort, newLeaderServer.getLocalPort());
    leaderClient = newLeaderServer.getClient();
    String receivedSchema = leaderClient.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v1.getVersion())).getSchemaText();
    Assert.assertEquals(schema1, receivedSchema);
}
Also used : SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Test(org.junit.Test)

Example 7 with SchemaIdVersion

use of com.hortonworks.registries.schemaregistry.SchemaIdVersion in project registry by hortonworks.

the class MessageContextBasedAvroSerDesTest method testSerDes.

@Test
public void testSerDes() throws Exception {
    SchemaMetadata schemaMetadata = new SchemaMetadata.Builder("msgCtx-" + System.currentTimeMillis()).schemaGroup("custom").type(AvroSchemaProvider.TYPE).compatibility(SchemaCompatibility.BACKWARD).build();
    SchemaIdVersion schemaIdVersion = new SchemaIdVersion(1L, 1, 1L);
    Device input = new Device(1L, "device", 1, System.currentTimeMillis());
    SchemaVersionInfo schemaVersionInfo = new SchemaVersionInfo(1l, input.getName().toString(), schemaIdVersion.getVersion(), input.getSchema().toString(), System.currentTimeMillis(), "");
    new Expectations() {

        {
            mockSchemaRegistryClient.addSchemaVersion(withInstanceOf(SchemaMetadata.class), withInstanceOf(SchemaVersion.class));
            result = schemaIdVersion;
            mockSchemaRegistryClient.getSchemaMetadataInfo(anyString);
            result = new SchemaMetadataInfo(schemaMetadata);
            mockSchemaRegistryClient.getSchemaVersionInfo(withInstanceOf(SchemaVersionKey.class));
            result = schemaVersionInfo;
        }
    };
    MessageContextBasedAvroSerializer serializer = new MessageContextBasedAvroSerializer();
    serializer.init(Collections.emptyMap());
    MessageContext messageContext = serializer.serialize(input, schemaMetadata);
    MessageContextBasedAvroDeserializer deserializer = new MessageContextBasedAvroDeserializer();
    deserializer.init(Collections.emptyMap());
    Object deserializedObject = deserializer.deserialize(messageContext, null);
    Assert.assertTrue(SpecificData.get().compare(input, deserializedObject, input.getSchema()) == 0);
}
Also used : Expectations(mockit.Expectations) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Device(com.hortonworks.registries.serdes.Device) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Test(org.junit.Test)

Example 8 with SchemaIdVersion

use of com.hortonworks.registries.schemaregistry.SchemaIdVersion in project registry by hortonworks.

the class SchemaVersionIdAsIntProtocolHandler method handleSchemaVersionDeserialization.

@Override
public SchemaIdVersion handleSchemaVersionDeserialization(InputStream inputStream) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(4);
    try {
        inputStream.read(byteBuffer.array());
    } catch (IOException e) {
        throw new AvroRetryableException(e);
    }
    int schemaVersionId = byteBuffer.getInt();
    return new SchemaIdVersion((long) schemaVersionId);
}
Also used : SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) AvroRetryableException(com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 9 with SchemaIdVersion

use of com.hortonworks.registries.schemaregistry.SchemaIdVersion in project registry by hortonworks.

the class ConfluentProtocolHandler method handleSchemaVersionDeserialization.

@Override
public SchemaIdVersion handleSchemaVersionDeserialization(InputStream inputStream) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(4);
    try {
        inputStream.read(byteBuffer.array());
    } catch (IOException e) {
        throw new AvroRetryableException(e);
    }
    int schemaVersionId = byteBuffer.getInt();
    return new SchemaIdVersion((long) schemaVersionId);
}
Also used : SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) AvroRetryableException(com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 10 with SchemaIdVersion

use of com.hortonworks.registries.schemaregistry.SchemaIdVersion in project registry by hortonworks.

the class SchemaMetadataIdProtocolHandler method handleSchemaVersionDeserialization.

@Override
public SchemaIdVersion handleSchemaVersionDeserialization(InputStream inputStream) {
    // 8 bytes : schema metadata Id
    // 4 bytes : schema version
    ByteBuffer byteBuffer = ByteBuffer.allocate(12);
    try {
        inputStream.read(byteBuffer.array());
    } catch (IOException e) {
        throw new AvroRetryableException(e);
    }
    long schemaMetadataId = byteBuffer.getLong();
    int schemaVersion = byteBuffer.getInt();
    return new SchemaIdVersion(schemaMetadataId, schemaVersion);
}
Also used : SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) AvroRetryableException(com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)45 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)32 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)22 Test (org.junit.Test)21 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)15 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)15 IOException (java.io.IOException)11 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)10 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)10 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)9 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)9 Timed (com.codahale.metrics.annotation.Timed)5 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)5 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)5 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)5 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)5 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)5 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)5 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)5 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)4