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