use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestConfluentSchemaRegistryWriter method testValidateValidSchema.
@Test
public void testValidateValidSchema() throws SchemaNotFoundException {
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().id(123456L).version(2).build();
final RecordSchema recordSchema = createRecordSchema(schemaIdentifier);
final SchemaAccessWriter schemaAccessWriter = new ConfluentSchemaRegistryWriter();
schemaAccessWriter.validateSchema(recordSchema);
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestHortonworksAttributeSchemaReferenceWriter method testGetAttributesWithoutBranch.
@Test
public void testGetAttributesWithoutBranch() {
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().id(123456L).version(2).build();
final RecordSchema recordSchema = createRecordSchema(schemaIdentifier);
final SchemaAccessWriter schemaAccessWriter = new HortonworksAttributeSchemaReferenceWriter();
final Map<String, String> attributes = schemaAccessWriter.getAttributes(recordSchema);
Assert.assertEquals(3, attributes.size());
Assert.assertEquals(String.valueOf(schemaIdentifier.getIdentifier().getAsLong()), attributes.get(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_ID_ATTRIBUTE));
Assert.assertEquals(String.valueOf(schemaIdentifier.getVersion().getAsInt()), attributes.get(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_VERSION_ATTRIBUTE));
Assert.assertEquals(String.valueOf(HortonworksAttributeSchemaReferenceWriter.LATEST_PROTOCOL_VERSION), attributes.get(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_PROTOCOL_VERSION_ATTRIBUTE));
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestHortonworksAttributeSchemaReferenceWriter method testGetAttributesWithBranch.
@Test
public void testGetAttributesWithBranch() {
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().id(123456L).version(2).branch("foo").build();
final RecordSchema recordSchema = createRecordSchema(schemaIdentifier);
final SchemaAccessWriter schemaAccessWriter = new HortonworksAttributeSchemaReferenceWriter();
final Map<String, String> attributes = schemaAccessWriter.getAttributes(recordSchema);
Assert.assertEquals(4, attributes.size());
Assert.assertEquals(String.valueOf(schemaIdentifier.getIdentifier().getAsLong()), attributes.get(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_ID_ATTRIBUTE));
Assert.assertEquals(String.valueOf(schemaIdentifier.getVersion().getAsInt()), attributes.get(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_VERSION_ATTRIBUTE));
Assert.assertEquals(String.valueOf(HortonworksAttributeSchemaReferenceWriter.LATEST_PROTOCOL_VERSION), attributes.get(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_PROTOCOL_VERSION_ATTRIBUTE));
Assert.assertEquals("foo", attributes.get(HortonworksAttributeSchemaReferenceWriter.SCHEMA_BRANCH_ATTRIBUTE));
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestHortonworksEncodedSchemaReferenceStrategy method testGetSchemaWithValidEncoding.
@Test
public void testGetSchemaWithValidEncoding() throws IOException, SchemaNotFoundException {
final SchemaAccessStrategy schemaAccessStrategy = new HortonworksEncodedSchemaReferenceStrategy(schemaRegistry);
final int protocol = 1;
final long schemaId = 123456;
final int version = 2;
try (final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(bytesOut)) {
out.write(protocol);
out.writeLong(schemaId);
out.writeInt(version);
out.flush();
try (final ByteArrayInputStream in = new ByteArrayInputStream(bytesOut.toByteArray())) {
// the confluent strategy will read the id from the input stream and use '1' as the version
final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().id(schemaId).version(version).build();
when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
final RecordSchema retrievedSchema = schemaAccessStrategy.getSchema(Collections.emptyMap(), in, recordSchema);
assertNotNull(retrievedSchema);
}
}
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestSchemaNameAsAttribute method testWriteNameBranchAndVersion.
@Test
public void testWriteNameBranchAndVersion() {
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name("person").branch("master").version(1).id(1L).build();
final RecordSchema schema = new SimpleRecordSchema(fields, schemaIdentifier);
final Map<String, String> attributes = schemaAccessWriter.getAttributes(schema);
Assert.assertEquals(3, attributes.size());
Assert.assertEquals(schemaIdentifier.getName().get(), attributes.get(SchemaNameAsAttribute.SCHEMA_NAME_ATTRIBUTE));
Assert.assertEquals(schemaIdentifier.getBranch().get(), attributes.get(SchemaNameAsAttribute.SCHEMA_BRANCH_ATTRIBUTE));
Assert.assertEquals(String.valueOf(schemaIdentifier.getVersion().getAsInt()), attributes.get(SchemaNameAsAttribute.SCHEMA_VERSION_ATTRIBUTE));
}
Aggregations