use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class HortonworksAttributeSchemaReferenceWriter method getAttributes.
@Override
public Map<String, String> getAttributes(final RecordSchema schema) {
final Map<String, String> attributes = new HashMap<>(4);
final SchemaIdentifier id = schema.getIdentifier();
final Long schemaId = id.getIdentifier().getAsLong();
final Integer schemaVersion = id.getVersion().getAsInt();
attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_ID_ATTRIBUTE, String.valueOf(schemaId));
attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_VERSION_ATTRIBUTE, String.valueOf(schemaVersion));
attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_PROTOCOL_VERSION_ATTRIBUTE, String.valueOf(LATEST_PROTOCOL_VERSION));
if (id.getBranch().isPresent()) {
attributes.put(SCHEMA_BRANCH_ATTRIBUTE, id.getBranch().get());
}
return attributes;
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class SchemaNameAsAttribute method getAttributes.
@Override
public Map<String, String> getAttributes(final RecordSchema schema) {
final Map<String, String> attributes = new HashMap<>(3);
final SchemaIdentifier identifier = schema.getIdentifier();
final Optional<String> nameOption = identifier.getName();
if (nameOption.isPresent()) {
attributes.put(SCHEMA_NAME_ATTRIBUTE, nameOption.get());
}
final OptionalInt versionOption = identifier.getVersion();
if (versionOption.isPresent()) {
attributes.put(SCHEMA_VERSION_ATTRIBUTE, String.valueOf(versionOption.getAsInt()));
}
final Optional<String> branchOption = identifier.getBranch();
if (branchOption.isPresent()) {
attributes.put(SCHEMA_BRANCH_ATTRIBUTE, branchOption.get());
}
return attributes;
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestConfluentSchemaRegistryWriter method testWriteHeader.
@Test
public void testWriteHeader() throws IOException {
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().id(123456L).version(2).build();
final RecordSchema recordSchema = createRecordSchema(schemaIdentifier);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final SchemaAccessWriter schemaAccessWriter = new ConfluentSchemaRegistryWriter();
schemaAccessWriter.writeHeader(recordSchema, out);
try (final ByteArrayInputStream bytesIn = new ByteArrayInputStream(out.toByteArray());
final DataInputStream in = new DataInputStream(bytesIn)) {
Assert.assertEquals(0, in.readByte());
Assert.assertEquals((int) schemaIdentifier.getIdentifier().getAsLong(), in.readInt());
}
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestHortonworksAttributeSchemaReferenceStrategy method testGetSchemaWithValidAttributes.
@Test
public void testGetSchemaWithValidAttributes() throws IOException, SchemaNotFoundException {
final long schemaId = 123456;
final int version = 2;
final int protocol = 1;
final Map<String, String> attributes = new HashMap<>();
attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_ID_ATTRIBUTE, String.valueOf(schemaId));
attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_VERSION_ATTRIBUTE, String.valueOf(version));
attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_PROTOCOL_VERSION_ATTRIBUTE, String.valueOf(protocol));
final SchemaAccessStrategy schemaAccessStrategy = new HortonworksAttributeSchemaReferenceStrategy(schemaRegistry);
final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().id(schemaId).version(version).build();
when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
final RecordSchema retrievedSchema = schemaAccessStrategy.getSchema(attributes, null, recordSchema);
assertNotNull(retrievedSchema);
}
use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.
the class TestHortonworksAttributeSchemaReferenceWriter method testValidateWithValidSchema.
@Test
public void testValidateWithValidSchema() throws SchemaNotFoundException {
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().id(123456L).version(2).build();
final RecordSchema recordSchema = createRecordSchema(schemaIdentifier);
final SchemaAccessWriter schemaAccessWriter = new HortonworksAttributeSchemaReferenceWriter();
schemaAccessWriter.validateSchema(recordSchema);
}
Aggregations