Search in sources :

Example 1 with RandomData

use of org.apache.avro.RandomData in project beam by apache.

the class AvroUtilsTest method avroToBeamRoundTrip.

@Property(trials = 1000)
@SuppressWarnings("unchecked")
public void avroToBeamRoundTrip(@From(RecordSchemaGenerator.class) org.apache.avro.Schema avroSchema) {
    Schema schema = AvroUtils.toBeamSchema(avroSchema);
    Iterable iterable = new RandomData(avroSchema, 10);
    List<GenericRecord> records = Lists.newArrayList((Iterable<GenericRecord>) iterable);
    for (GenericRecord record : records) {
        Row row = AvroUtils.toBeamRowStrict(record, schema);
        GenericRecord out = AvroUtils.toGenericRecord(row, avroSchema);
        assertEquals(record, out);
    }
}
Also used : RandomData(org.apache.avro.RandomData) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) GenericRecord(org.apache.avro.generic.GenericRecord) Property(com.pholser.junit.quickcheck.Property)

Example 2 with RandomData

use of org.apache.avro.RandomData in project beam by apache.

the class AvroUtilsTest method supportsAnyAvroSchema.

@Property(trials = 1000)
@SuppressWarnings("unchecked")
public void supportsAnyAvroSchema(@From(RecordSchemaGenerator.class) org.apache.avro.Schema avroSchema) {
    Schema schema = AvroUtils.toBeamSchema(avroSchema);
    Iterable iterable = new RandomData(avroSchema, 10);
    List<GenericRecord> records = Lists.newArrayList((Iterable<GenericRecord>) iterable);
    for (GenericRecord record : records) {
        AvroUtils.toBeamRowStrict(record, schema);
    }
}
Also used : RandomData(org.apache.avro.RandomData) Schema(org.apache.beam.sdk.schemas.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) Property(com.pholser.junit.quickcheck.Property)

Aggregations

Property (com.pholser.junit.quickcheck.Property)2 RandomData (org.apache.avro.RandomData)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 Schema (org.apache.beam.sdk.schemas.Schema)2 Row (org.apache.beam.sdk.values.Row)1