Search in sources :

Example 16 with SpecificRecord

use of org.apache.avro.specific.SpecificRecord in project flink by apache.

the class AvroRowDeSerializationSchemaTest method testSpecificSerializeFromSchemaSeveralTimes.

@Test
public void testSpecificSerializeFromSchemaSeveralTimes() throws IOException {
    final Tuple3<Class<? extends SpecificRecord>, SpecificRecord, Row> testData = AvroTestUtils.getSpecificTestData();
    final String schemaString = testData.f1.getSchema().toString();
    final AvroRowSerializationSchema serializationSchema = new AvroRowSerializationSchema(schemaString);
    final AvroRowDeserializationSchema deserializationSchema = new AvroRowDeserializationSchema(schemaString);
    serializationSchema.serialize(testData.f2);
    serializationSchema.serialize(testData.f2);
    final byte[] bytes = serializationSchema.serialize(testData.f2);
    final Row actual = deserializationSchema.deserialize(bytes);
    assertEquals(testData.f2, actual);
}
Also used : SpecificRecord(org.apache.avro.specific.SpecificRecord) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

SpecificRecord (org.apache.avro.specific.SpecificRecord)16 IOException (java.io.IOException)7 Row (org.apache.flink.types.Row)7 Schema (org.apache.avro.Schema)6 Test (org.junit.Test)6 BinaryEncoder (org.apache.avro.io.BinaryEncoder)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)3 AvroException (com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroException)2 AvroRetryableException (com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroRetryableException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 EncoderFactory (org.apache.avro.io.EncoderFactory)2 JsonEncoder (org.apache.avro.io.JsonEncoder)2 SamzaException (org.apache.samza.SamzaException)2 AppendableOutputStream (org.spf4j.io.AppendableOutputStream)2 BlockBlobAsyncClient (com.azure.storage.blob.specialized.BlockBlobAsyncClient)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DatabusRuntimeException (com.linkedin.databus.core.DatabusRuntimeException)1 SchemaId (com.linkedin.databus2.schemas.SchemaId)1 VersionedSchema (com.linkedin.databus2.schemas.VersionedSchema)1