Package org.apache.avro

Examples of org.apache.avro.Interop


   
    interopBuilder.setStringField("Hello");
    interopBuilder.setUnionField(Arrays.asList(new ByteBuffer[] {
        ByteBuffer.wrap(new byte[] { 1, 2 }) }));
   
    Interop interop = interopBuilder.build();
   
    // Verify that deepCopy works for all fields:
    for (Field field : Interop.SCHEMA$.getFields()) {
      // Original field and deep copy should be equivalent:
      if (interop.get(field.pos()) instanceof ByteBuffer) {
        assertTrue(Arrays.equals(((ByteBuffer)interop.get(field.pos())).array(),
            ((ByteBuffer)GenericData.get().deepCopy(field.schema(),
                interop.get(field.pos()))).array()));
      }
      else {
        assertEquals(interop.get(field.pos()),
            SpecificData.get().deepCopy(
                field.schema(), interop.get(field.pos())));
      }
     
      // Original field and deep copy should be different instances:
      if ((field.schema().getType() != Type.ENUM)
           && (field.schema().getType() != Type.NULL)
           && (field.schema().getType() != Type.BOOLEAN)
           && (field.schema().getType() != Type.INT)
           && (field.schema().getType() != Type.LONG)
           && (field.schema().getType() != Type.FLOAT)
           && (field.schema().getType() != Type.DOUBLE)
           && (field.schema().getType() != Type.STRING)) {
        assertFalse("Field " + field.name() + " is same instance in deep copy",
            interop.get(field.pos()) ==
              GenericData.get().deepCopy(
                  field.schema(), interop.get(field.pos())));
      }
    }
  }
View Full Code Here


   
  }

  @Test
  public void testInterop() {
    Interop interop = Interop.newBuilder()
        .setNullField(null)
        .setArrayField(Arrays.asList(new Double[] { 3.14159265, 6.022 }))
        .setBoolField(true)
        .setBytesField(ByteBuffer.allocate(4).put(new byte[] { 3, 2, 1, 0 }))
        .setDoubleField(1.41421)
        .setEnumField(Kind.C)
        .setFixedField(new MD5(
            new byte[] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 }))
        .setFloatField(1.61803f)
        .setIntField(64)
        .setLongField(1024)
        .setMapField(Collections.singletonMap("Foo1", new Foo()))
        .setRecordField(new Node())
        .setStringField("MyInterop")
        .setUnionField(2.71828)
        .build();
   
    Interop copy = Interop.newBuilder(interop).build();
    Assert.assertEquals(interop.getArrayField().size(), copy.getArrayField().size());
    Assert.assertEquals(interop.getArrayField(), copy.getArrayField());
    Assert.assertEquals(interop.getBoolField(), copy.getBoolField());
    Assert.assertEquals(interop.getBytesField(), copy.getBytesField());
    Assert.assertEquals(interop.getDoubleField(), copy.getDoubleField());
    Assert.assertEquals(interop.getEnumField(), copy.getEnumField());
    Assert.assertEquals(interop.getFixedField(), copy.getFixedField());
    Assert.assertEquals(interop.getFloatField(), copy.getFloatField());
    Assert.assertEquals(interop.getIntField(), copy.getIntField());
    Assert.assertEquals(interop.getLongField(), copy.getLongField());
    Assert.assertEquals(interop.getMapField(), copy.getMapField());
    Assert.assertEquals(interop.getRecordField(), copy.getRecordField());
    Assert.assertEquals(interop.getStringField(), copy.getStringField());
    Assert.assertEquals(interop.getUnionField(), copy.getUnionField());
    Assert.assertEquals(interop, copy);
  }
View Full Code Here

   
  }

  @Test
  public void testInterop() {
    Interop interop = Interop.newBuilder()
        .setNullField(null)
        .setArrayField(Arrays.asList(new Double[] { 3.14159265, 6.022 }))
        .setBoolField(true)
        .setBytesField(ByteBuffer.allocate(4).put(new byte[] { 3, 2, 1, 0 }))
        .setDoubleField(1.41421)
        .setEnumField(Kind.C)
        .setFixedField(new MD5(
            new byte[] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 }))
        .setFloatField(1.61803f)
        .setIntField(64)
        .setLongField(1024)
        .setMapField(Collections.singletonMap("Foo1", new Foo()))
        .setRecordField(new Node())
        .setStringField("MyInterop")
        .setUnionField(2.71828)
        .build();
   
    Interop copy = Interop.newBuilder(interop).build();
    Assert.assertEquals(interop.getArrayField().size(), copy.getArrayField().size());
    Assert.assertEquals(interop.getArrayField(), copy.getArrayField());
    Assert.assertEquals(interop.getBoolField(), copy.getBoolField());
    Assert.assertEquals(interop.getBytesField(), copy.getBytesField());
    Assert.assertEquals(interop.getDoubleField(), copy.getDoubleField());
    Assert.assertEquals(interop.getEnumField(), copy.getEnumField());
    Assert.assertEquals(interop.getFixedField(), copy.getFixedField());
    Assert.assertEquals(interop.getFloatField(), copy.getFloatField());
    Assert.assertEquals(interop.getIntField(), copy.getIntField());
    Assert.assertEquals(interop.getLongField(), copy.getLongField());
    Assert.assertEquals(interop.getMapField(), copy.getMapField());
    Assert.assertEquals(interop.getRecordField(), copy.getRecordField());
    Assert.assertEquals(interop.getStringField(), copy.getStringField());
    Assert.assertEquals(interop.getUnionField(), copy.getUnionField());
  }
View Full Code Here

    interopBuilder.setRecordField(rootBuilder.build());
   
    interopBuilder.setStringField("Hello");
    interopBuilder.setUnionField(true);
   
    Interop interop = interopBuilder.build();
   
    // Verify that deepCopy works for all fields:
    for (Field field : Interop.SCHEMA$.getFields()) {
      // Original field and deep copy should be equivalent:
      if (interop.get(field.pos()) instanceof ByteBuffer) {
        assertTrue(Arrays.equals(((ByteBuffer)interop.get(field.pos())).array(),
            ((ByteBuffer)GenericData.get().deepCopy(field.schema(),
                interop.get(field.pos()))).array()));
      }
      else {
        assertEquals(interop.get(field.pos()),
            SpecificData.get().deepCopy(
                field.schema(), interop.get(field.pos())));
      }
     
      // Original field and deep copy should be different instances:
      if ((field.schema().getType() != Type.ENUM)
           && (field.schema().getType() != Type.NULL)
           && (field.schema().getType() != Type.STRING)) {
        assertFalse("Field " + field.name() + " is same instance in deep copy",
            interop.get(field.pos()) ==
              GenericData.get().deepCopy(
                  field.schema(), interop.get(field.pos())));
      }
    }
  }
View Full Code Here

   
  }

  @Test
  public void testInterop() {
    Interop interop = Interop.newBuilder()
        .setNullField(null)
        .setArrayField(Arrays.asList(new Double[] { 3.14159265, 6.022 }))
        .setBoolField(true)
        .setBytesField(ByteBuffer.allocate(4).put(new byte[] { 3, 2, 1, 0 }))
        .setDoubleField(1.41421)
        .setEnumField(Kind.C)
        .setFixedField(new MD5(
            new byte[] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 }))
        .setFloatField(1.61803f)
        .setIntField(64)
        .setLongField(1024)
        .setMapField(Collections.singletonMap("Foo1", new Foo()))
        .setRecordField(new Node())
        .setStringField("MyInterop")
        .setUnionField(2.71828)
        .build();
   
    Interop copy = Interop.newBuilder(interop).build();
    Assert.assertEquals(interop.getArrayField().size(), copy.getArrayField().size());
    Assert.assertEquals(interop.getArrayField(), copy.getArrayField());
    Assert.assertEquals(interop.getBoolField(), copy.getBoolField());
    Assert.assertEquals(interop.getBytesField().capacity(), copy.getBytesField().capacity());
    Assert.assertEquals(interop.getBytesField(), copy.getBytesField());
    Assert.assertEquals(interop.getDoubleField(), copy.getDoubleField());
    Assert.assertEquals(interop.getEnumField(), copy.getEnumField());
    Assert.assertEquals(interop.getFixedField(), copy.getFixedField());
    Assert.assertEquals(interop.getFloatField(), copy.getFloatField());
    Assert.assertEquals(interop.getIntField(), copy.getIntField());
    Assert.assertEquals(interop.getLongField(), copy.getLongField());
    Assert.assertEquals(interop.getMapField(), copy.getMapField());
    Assert.assertEquals(interop.getRecordField(), copy.getRecordField());
    Assert.assertEquals(interop.getStringField(), copy.getStringField());
    Assert.assertEquals(interop.getUnionField(), copy.getUnionField());
  }
View Full Code Here

TOP

Related Classes of org.apache.avro.Interop

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.