Search in sources :

Example 11 with BinaryObjectBuilderImpl

use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testDateInObjectField.

/**
     *
     */
public void testDateInObjectField() {
    GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
    obj.foo = new Date();
    BinaryObjectBuilderImpl mutableObj = wrap(obj);
    assertEquals(Date.class, mutableObj.getField("foo").getClass());
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Date(java.util.Date)

Example 12 with BinaryObjectBuilderImpl

use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testMetadataChanging.

/**
     *
     */
public void testMetadataChanging() {
    GridBinaryTestClasses.TestObjectContainer c = new GridBinaryTestClasses.TestObjectContainer();
    BinaryObjectBuilderImpl mutableObj = wrap(c);
    mutableObj.setField("intField", 1);
    mutableObj.setField("intArrField", new int[] { 1 });
    mutableObj.setField("arrField", new String[] { "1" });
    mutableObj.setField("strField", "1");
    mutableObj.setField("colField", Lists.newArrayList("1"));
    mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
    mutableObj.setField("enumField", GridBinaryTestClasses.TestObjectEnum.A);
    mutableObj.setField("enumArrField", new Enum[] { GridBinaryTestClasses.TestObjectEnum.A });
    mutableObj.build();
    BinaryType metadata = binaries().type(c.getClass());
    assertTrue(metadata.fieldNames().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField", "colField", "mapField", "enumField", "enumArrField")));
    assertEquals("int", metadata.fieldTypeName("intField"));
    assertEquals("int[]", metadata.fieldTypeName("intArrField"));
    assertEquals("String[]", metadata.fieldTypeName("arrField"));
    assertEquals("String", metadata.fieldTypeName("strField"));
    assertEquals("Collection", metadata.fieldTypeName("colField"));
    assertEquals("Map", metadata.fieldTypeName("mapField"));
    assertEquals("Enum", metadata.fieldTypeName("enumField"));
    assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 13 with BinaryObjectBuilderImpl

use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testRemoveFromNewObject.

/**
     *
     */
public void testRemoveFromNewObject() {
    BinaryObjectBuilderImpl wrapper = newWrapper(GridBinaryTestClasses.TestObjectAllTypes.class);
    wrapper.setField("str", "a");
    wrapper.removeField("str");
    TestCase.assertNull(wrapper.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 14 with BinaryObjectBuilderImpl

use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testTimestampArrayModification.

/**
     *
     */
public void testTimestampArrayModification() {
    GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
    obj.tsArr = new Timestamp[] { new Timestamp(111222333), new Timestamp(222333444) };
    BinaryObjectBuilderImpl mutObj = wrap(obj);
    Timestamp[] arr = mutObj.getField("tsArr");
    arr[0] = new Timestamp(333444555);
    GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
    Assert.assertArrayEquals(new Timestamp[] { new Timestamp(333444555), new Timestamp(222333444) }, res.tsArr);
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Timestamp(java.sql.Timestamp)

Example 15 with BinaryObjectBuilderImpl

use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testPlainBinaryObjectCopyFrom.

/**
     *
     */
public void testPlainBinaryObjectCopyFrom() {
    GridBinaryTestClasses.TestObjectPlainBinary obj = new GridBinaryTestClasses.TestObjectPlainBinary(toBinary(new GridBinaryTestClasses.TestObjectAllTypes()));
    BinaryObjectBuilderImpl builder = builder(toBinary(obj));
    assertTrue(builder.getField("plainBinary") instanceof BinaryObject);
    GridBinaryTestClasses.TestObjectPlainBinary deserialized = builder.build().deserialize();
    assertTrue(deserialized.plainBinary != null);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Aggregations

BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)62 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)56 BinaryObject (org.apache.ignite.binary.BinaryObject)24 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Timestamp (java.sql.Timestamp)4 Date (java.util.Date)4 BinaryType (org.apache.ignite.binary.BinaryType)3 Field (java.lang.reflect.Field)2 UUID (java.util.UUID)2 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)2 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 BinaryBuilderEnum (org.apache.ignite.internal.binary.builder.BinaryBuilderEnum)1 GridBinaryMarshalerAwareTestClass (org.apache.ignite.internal.binary.mutabletest.GridBinaryMarshalerAwareTestClass)1 GridBinaryTestClass2 (org.apache.ignite.internal.binary.test.GridBinaryTestClass2)1