Package org.apache.avro.reflect

Examples of org.apache.avro.reflect.ReflectData


  /**
   * Experiment to see what a schema looks like.
   */
  @Test
  public void testEventSchema() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(EventImpl.class);
    LOG.info(schm);
  }
View Full Code Here


  /**
   * Try BinaryEncoder
   */
  @Test
  public void testSerializeBinary() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(A.class);
    LOG.info(schm);

    ReflectDatumWriter<A> writer = new ReflectDatumWriter<A>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Encoder json = new BinaryEncoder(out);
View Full Code Here

  /**
   * Try JsonEncoder
   */
  @Test
  public void testSerializeJson() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(A.class);
    LOG.info(schm);

    ReflectDatumWriter<A> writer = new ReflectDatumWriter<A>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonEncoder json = new JsonEncoder(schm, out);
View Full Code Here

  /**
   * JsonEncoder and JsonDecoder on a EventImpl
   */
  @Test
  public void testEventSchemaSerializeJson() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(EventImpl.class);
    LOG.info(schm);

    ReflectDatumWriter<EventImpl> writer = new ReflectDatumWriter<EventImpl>(
        schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

  /**
   * BinaryEnconder and BinaryDecoder on a EventImpl
   */
  @Test
  public void testEventSchemaSerializeBin() throws IOException {
    ReflectData reflectData = ReflectData.get();
    Schema schm = reflectData.getSchema(EventImpl.class);
    LOG.info(schm);

    ReflectDatumWriter<EventImpl> writer = new ReflectDatumWriter<EventImpl>(
        schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

    ByteArrayOutputStream sos = new ByteArrayOutputStream();
    format.format(sos, e);
    format.close();
    byte[] bytes = sos.toByteArray();

    ReflectData reflectData = ReflectData.get();
    Schema schema = reflectData.getSchema(EventImpl.class);
    ReflectDatumReader<EventImpl> dr = new ReflectDatumReader<EventImpl>(schema);
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    DataFileStream<EventImpl> dec = new DataFileStream<EventImpl>(bais, dr);

    Event er = dec.next();
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

                    if (f != null) {
                        Protocol protocol = (Protocol)f.get(null);
                        config.setProtocol(protocol);
                    }
                } catch (NoSuchFieldException e) {
                    ReflectData reflectData = ReflectData.get();
                    config.setProtocol(reflectData.getProtocol(protocolClass));
                    config.setReflectionProtocol(true);
                }
            }
        }
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.