Search in sources :

Example 6 with SchemaMetadata

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

the class AvroSchemaRegistryClientTest method testSerializerOps.

@Test
public void testSerializerOps() throws Exception {
    String fileId = uploadFile();
    SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BOTH);
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/device.avsc"), "Initial version of the schema"));
    SerDesPair serDesPair = createSerDesInfo(fileId);
    Long serDesId = SCHEMA_REGISTRY_CLIENT.addSerDes(serDesPair);
    Assert.assertNotNull("Returned serDesId can not be null", serDesId);
    String schemaName = schemaMetadata.getName();
    SCHEMA_REGISTRY_CLIENT.mapSchemaWithSerDes(schemaName, serDesId);
    Collection<SerDesInfo> serializers = SCHEMA_REGISTRY_CLIENT.getSerDes(schemaName);
    Assert.assertTrue(serializers.stream().map(x -> x.getSerDesPair()).collect(Collectors.toList()).contains(serDesPair));
}
Also used : Arrays(java.util.Arrays) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) SchemaRegistryTestProfileType(com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType) SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) SERDES_PROTOCOL_VERSION(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer.SERDES_PROTOCOL_VERSION) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) AvroSnapshotSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) Utf8(org.apache.avro.util.Utf8) SerDesProtocolHandlerRegistry(com.hortonworks.registries.schemaregistry.serdes.avro.SerDesProtocolHandlerRegistry) AvroSnapshotDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer) SchemaRegistryTestName(com.hortonworks.registries.schemaregistry.avro.util.SchemaRegistryTestName) Collection(java.util.Collection) BAD_REQUEST_PARAM_MISSING(com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.BAD_REQUEST_PARAM_MISSING) Set(java.util.Set) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) Response(javax.ws.rs.core.Response) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) CustomParameterizedRunner(com.hortonworks.registries.schemaregistry.avro.util.CustomParameterizedRunner) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) UNSUPPORTED_SCHEMA_TYPE(com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE) IntStream(java.util.stream.IntStream) SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) AvroSchemaRegistryClientUtil(com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SchemaValidationLevel(com.hortonworks.registries.schemaregistry.SchemaValidationLevel) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) Files(java.nio.file.Files) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) FileOutputStream(java.io.FileOutputStream) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) Test(org.junit.Test) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Maps(com.google.common.collect.Maps) File(java.io.File) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Rule(org.junit.Rule) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) Assert(org.junit.Assert) Collections(java.util.Collections) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) InputStream(java.io.InputStream) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Example 7 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata 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 8 with SchemaMetadata

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

the class AvroSchemaRegistryTest method testSchemaTextAsNull.

@Test(expected = InvalidSchemaException.class)
public void testSchemaTextAsNull() throws Exception {
    SchemaMetadata schemaMetadataInfo = createSchemaInfo(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    // registering a new schema
    Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadataInfo, new SchemaVersion(null, "Initial version of the schema")).getVersion();
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Test(org.junit.Test)

Example 9 with SchemaMetadata

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

the class AvroSchemaRegistryTest method testIncompatibleSchemas.

@Test(expected = IncompatibleSchemaException.class)
public void testIncompatibleSchemas() throws Exception {
    String schema = getSchema("/device.avsc");
    String incompatSchema = getSchema("/device-incompat.avsc");
    SchemaMetadata schemaMetadata = createSchemaInfo(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    // registering a new schema
    Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema")).getVersion();
    // adding a new version of the schema
    Integer v2 = schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(incompatSchema, "second version")).getVersion();
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Test(org.junit.Test)

Example 10 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata 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)

Aggregations

SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)57 Test (org.junit.Test)35 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)33 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)31 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)21 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)17 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)15 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)11 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)11 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)9 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)8 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)7 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)6 SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)6 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)6 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)6 Collection (java.util.Collection)6 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)5