Search in sources :

Example 26 with SchemaIdentifier

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);
}
Also used : SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Example 27 with SchemaIdentifier

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));
}
Also used : SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Example 28 with SchemaIdentifier

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));
}
Also used : SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Example 29 with SchemaIdentifier

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);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Example 30 with SchemaIdentifier

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));
}
Also used : SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Aggregations

SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)37 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)28 Test (org.junit.Test)22 SimpleRecordSchema (org.apache.nifi.serialization.SimpleRecordSchema)12 OptionalLong (java.util.OptionalLong)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 OptionalInt (java.util.OptionalInt)5 Schema (org.apache.avro.Schema)5 PropertyValue (org.apache.nifi.components.PropertyValue)5 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)5 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)4 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)4 ByteBuffer (java.nio.ByteBuffer)4 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 InitializationException (org.apache.nifi.reporting.InitializationException)3 SchemaNotFoundException (org.apache.nifi.schema.access.SchemaNotFoundException)3