Package org.apache.avro.reflect

Examples of org.apache.avro.reflect.ReflectData


    assertEquals(record, decoded);
  }

  @Test
  public void testRecordWithNullIO() throws IOException {
    ReflectData reflectData = ReflectData.AllowNull.get();
    Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
    ReflectDatumWriter<AnotherSampleRecord> writer =
      new ReflectDatumWriter<AnotherSampleRecord>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // keep record.a null and see if that works
    Encoder e = factory.directBinaryEncoder(out, null);
View Full Code Here


  public static class A { B1 b1; B2 b2; }
  public static interface C { void foo(A a); }

  @Test
  public void testForwardReference() {
    ReflectData data = ReflectData.get();
    Protocol reflected = data.getProtocol(C.class);
    Protocol reparsed = Protocol.parse(reflected.toString());
    assertEquals(reflected, reparsed);
    assert(reparsed.getTypes().contains(data.getSchema(A.class)));
    assert(reparsed.getTypes().contains(data.getSchema(B1.class)));
    assert(reparsed.getTypes().contains(data.getSchema(B2.class)));
    assert(reparsed.getTypes().contains(data.getSchema(X.class)));
  }
View Full Code Here

  }

  @Test
  /** Test nesting of reflect data within generic. */
  public void testReflectWithinGeneric() throws Exception {
    ReflectData data = ReflectData.get();
    // define a record with a field that's a specific Y
    Schema schema = Schema.createRecord("Foo", "", "x.y.z", false);
    List<Schema.Field> fields = new ArrayList<Schema.Field>();
    fields.add(new Schema.Field("f", data.getSchema(Y.class), "", null));
    schema.setFields(fields);

    // create a generic instance of this record
    Y y = new Y();
    y.i = 1;
View Full Code Here

   */
  @Test
  public void testMultiReflectWithUnionBeforeWriting() throws IOException {
    FileOutputStream fos = new FileOutputStream(FILE);

    ReflectData reflectData = ReflectData.get();
    List<Schema> schemas = Arrays.asList(new Schema[] {
        reflectData.getSchema(FooRecord.class),
        reflectData.getSchema(BarRecord.class) });
    Schema union = Schema.createUnion(schemas);
    DataFileWriter<Object> writer = new DataFileWriter<Object>(union, fos,
        new ReflectDatumWriter(union));

    // test writing to a file
View Full Code Here

   */
  @Test
  public void testMultiReflectWithUntionAfterWriting() throws IOException {
    FileOutputStream fos = new FileOutputStream(FILE);

    ReflectData reflectData = ReflectData.get();
    List<Schema> schemas = new ArrayList<Schema>();
    schemas.add(reflectData.getSchema(FooRecord.class));
    Schema union = Schema.createUnion(schemas);
    DataFileWriter<Object> writer = new DataFileWriter<Object>(union, fos,
        new ReflectDatumWriter(union));

    CheckList check = new CheckList();
    // write known type
    write(writer, new FooRecord(10), check);
    write(writer, new FooRecord(15), check);

    // we have a new type, add it to the file
    writer.addSchema(reflectData.getSchema(BarRecord.class));

    // test writing those new types to a file
    write(writer, new BarRecord("One beer please"), check);
    write(writer, new BarRecord("Two beers please"), check);

View Full Code Here

   */
  @Test
  public void testNull() throws IOException {
    FileOutputStream fos = new FileOutputStream(FILE);

    ReflectData reflectData = ReflectData.AllowNull.get();
    Schema schema = reflectData.getSchema(BarRecord.class);
    DataFileWriter<Object> writer = new DataFileWriter<Object>(schema, fos,
        new ReflectDatumWriter(schema, reflectData));

    // test writing to a file
    CheckList check = new CheckList();
View Full Code Here

    assertEquals(record, decoded);
  }

  @Test
  public void testRecordWithNull() throws IOException {
    ReflectData reflectData = ReflectData.AllowNull.get();
    Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
    ReflectDatumWriter writer = new ReflectDatumWriter(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // keep record.a null and see if that works
    AnotherSampleRecord a = new AnotherSampleRecord();
    writer.write(a, new BinaryEncoder(out));
View Full Code Here

    assertEquals(record, decoded);
  }

  @Test
  public void testRecordWithNullIO() throws IOException {
    ReflectData reflectData = ReflectData.AllowNull.get();
    Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
    ReflectDatumWriter<AnotherSampleRecord> writer =
      new ReflectDatumWriter<AnotherSampleRecord>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // keep record.a null and see if that works
    Encoder e = factory.directBinaryEncoder(out, null);
View Full Code Here

  public static class A { B1 b1; B2 b2; }
  public static interface C { void foo(A a); }

  @Test
  public void testForwardReference() {
    ReflectData data = ReflectData.get();
    Protocol reflected = data.getProtocol(C.class);
    Protocol reparsed = Protocol.parse(reflected.toString());
    assertEquals(reflected, reparsed);
    assert(reparsed.getTypes().contains(data.getSchema(A.class)));
    assert(reparsed.getTypes().contains(data.getSchema(B1.class)));
    assert(reparsed.getTypes().contains(data.getSchema(B2.class)));
    assert(reparsed.getTypes().contains(data.getSchema(X.class)));
  }
View Full Code Here

  }

  @Test
  /** Test nesting of reflect data within generic. */
  public void testReflectWithinGeneric() throws Exception {
    ReflectData data = ReflectData.get();
    // define a record with a field that's a specific Y
    Schema schema = Schema.createRecord("Foo", "", "x.y.z", false);
    List<Schema.Field> fields = new ArrayList<Schema.Field>();
    fields.add(new Schema.Field("f", data.getSchema(Y.class), "", null));
    schema.setFields(fields);

    // create a generic instance of this record
    Y y = new Y();
    y.i = 1;
View Full Code Here

TOP

Related Classes of org.apache.avro.reflect.ReflectData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.