Search in sources :

Example 51 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testBuilderReusage.

/**
 * @throws Exception If fails
 */
public void testBuilderReusage() throws Exception {
    // Check: rewrite null field value.
    BinaryObjectBuilder builder = newWrapper("SimpleCls1");
    builder.setField("f1", null, Object.class);
    assertNull(builder.build().field("f1"));
    builder.setField("f1", "val1");
    assertEquals("val1", builder.build().field("f1"));
    // Check: rewrite non-null field value to null and back.
    builder = newWrapper("SimpleCls2");
    builder.setField("f1", "val1", String.class);
    assertEquals("val1", builder.build().field("f1"));
    builder.setField("f1", null);
    assertNull(builder.build().field("f1"));
    builder.setField("f1", "val2");
    assertEquals("val2", builder.build().field("f1"));
}
Also used : BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 52 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testCorrectMetadataNullField2.

/**
 */
public void testCorrectMetadataNullField2() {
    BinaryObjectBuilder builder = binaries().builder("SomeType3");
    builder.setField("dateField", null, Date.class);
    builder.setField("objectField", null, GridBinaryTestClasses.Company.class);
    BinaryObject obj = builder.build();
    builder = binaries().builder(obj);
    builder.setField("dateField", new Date());
    builder.setField("objectField", new GridBinaryTestClasses.Company());
    builder.build();
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Date(java.util.Date)

Example 53 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testEnum.

/**
 * Checks correct serialization/deserialization of enums in builder.
 *
 * @throws Exception If failed.
 */
public void testEnum() throws Exception {
    BinaryObjectBuilder builder = newWrapper("TestType");
    final TestEnum exp = TestEnum.A;
    final TestEnum[] expArr = { TestEnum.A, TestEnum.B };
    BinaryObject enumObj = builder.setField("testEnum", exp).setField("testEnumArr", expArr).build();
    assertEquals(exp, ((BinaryObject) enumObj.field("testEnum")).deserialize());
    Assert.assertArrayEquals(expArr, (Object[]) deserializeEnumBinaryArray(enumObj.field("testEnumArr")));
    builder = newWrapper(enumObj.type().typeName());
    enumObj = builder.setField("testEnum", (Object) enumObj.field("testEnum")).setField("testEnumArr", (Object) enumObj.field("testEnumArr")).build();
    assertEquals(exp, ((BinaryObject) enumObj.field("testEnum")).deserialize());
    Assert.assertArrayEquals(expArr, (Object[]) deserializeEnumBinaryArray(enumObj.field("testEnumArr")));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 54 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testWrongMetadataNullField.

/**
 */
public void testWrongMetadataNullField() {
    BinaryObjectBuilder builder = binaries().builder("SomeType");
    builder.setField("dateField", null);
    builder.setField("objectField", null, Integer.class);
    builder.build();
    try {
        builder = binaries().builder("SomeType");
        builder.setField("dateField", new Date());
        builder.build();
    } catch (BinaryObjectException ex) {
        assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
    }
    builder = binaries().builder("SomeType");
    try {
        builder.setField("objectField", new GridBinaryTestClasses.Company());
        builder.build();
        fail("BinaryObjectBuilder accepted wrong metadata");
    } catch (BinaryObjectException ex) {
        assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
    }
}
Also used : BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Date(java.util.Date) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 55 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.

the class BinarySimpleNameTestPropertySelfTest method checkProperty.

/**
 * @param expTypeName Type name.
 * @throws Exception If failed.
 */
private void checkProperty(String expTypeName) throws Exception {
    String marshBackup = GridTestProperties.getProperty(MARSH_CLASS_NAME);
    try {
        GridTestProperties.setProperty(MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
        IgniteBinary binary = startGrid().binary();
        BinaryObjectBuilder builder = binary.builder("org.ignite.test.TestClass");
        BinaryObject bObj = builder.build();
        assertEquals(expTypeName, bObj.type().typeName());
    } finally {
        if (marshBackup != null)
            GridTestProperties.setProperty(MARSH_CLASS_NAME, marshBackup);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Aggregations

BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)83 BinaryObject (org.apache.ignite.binary.BinaryObject)63 Ignite (org.apache.ignite.Ignite)11 IgniteBinary (org.apache.ignite.IgniteBinary)8 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)7 Date (java.util.Date)4 HashMap (java.util.HashMap)4 BinaryType (org.apache.ignite.binary.BinaryType)4 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)3 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)3 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Column (org.h2.table.Column)3 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 UUID (java.util.UUID)2