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));
}
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);
}
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();
}
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();
}
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);
}
Aggregations