Search in sources :

Example 26 with BinaryObjectBuilderImpl

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

the class BinaryObjectBuilderAdditionalSelfTest method testStringArrayModification.

/**
     *
     */
public void testStringArrayModification() {
    GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
    obj.strArr = new String[] { "a", "a", "a" };
    BinaryObjectBuilderImpl mutObj = wrap(obj);
    String[] arr = mutObj.getField("strArr");
    arr[0] = "b";
    GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
    Assert.assertArrayEquals(new String[] { "b", "a", "a" }, res.strArr);
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 27 with BinaryObjectBuilderImpl

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

the class BinaryObjectBuilderAdditionalSelfTest method testMapModification.

/**
     *
     */
public void testMapModification() {
    GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
    obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
    BinaryObjectBuilderImpl mutObj = wrap(obj);
    Map<Object, Object> map = mutObj.getField("foo");
    map.put(3, mutObj);
    Object rmv = map.remove(1);
    assertEquals("a", rmv);
    GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
    assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) BinaryObject(org.apache.ignite.binary.BinaryObject) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 28 with BinaryObjectBuilderImpl

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

the class GridCacheUtilsSelfTest method testCacheKeyValidation.

/**
     */
@SuppressWarnings("ResultOfMethodCallIgnored")
public void testCacheKeyValidation() throws IgniteCheckedException {
    CU.validateCacheKey("key");
    CU.validateCacheKey(1);
    CU.validateCacheKey(1L);
    CU.validateCacheKey(1.0);
    CU.validateCacheKey(new ExtendsClassWithEqualsAndHashCode());
    CU.validateCacheKey(new ExtendsClassWithEqualsAndHashCode2());
    assertThrowsForInvalidKey(new NoEqualsAndHashCode());
    assertThrowsForInvalidKey(new NoEquals());
    assertThrowsForInvalidKey(new NoHashCode());
    assertThrowsForInvalidKey(new WrongEquals());
    BinaryObjectBuilderImpl binBuilder = new BinaryObjectBuilderImpl(binaryContext(), EqualsAndHashCode.class.getName());
    BinaryObject binObj = binBuilder.build();
    CU.validateCacheKey(binObj);
    BinaryObjectBuilderImpl binBuilder2 = new BinaryObjectBuilderImpl((BinaryObjectImpl) binObj);
    CU.validateCacheKey(binBuilder2.build());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)

Example 29 with BinaryObjectBuilderImpl

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

the class BinaryMarshallerSelfTest method testFieldOrderByBuilder.

/**
     * The test must be refactored after {@link IgniteSystemProperties#IGNITE_BINARY_SORT_OBJECT_FIELDS}
     * is removed.
     *
     * @throws Exception If failed.
     */
public void testFieldOrderByBuilder() throws Exception {
    if (BinaryUtils.FIELDS_SORTED_ORDER)
        return;
    BinaryMarshaller m = binaryMarshaller();
    BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(m), "MyFakeClass");
    String[] fieldNames = { "field9", "field8", "field0", "field1", "field2" };
    for (String fieldName : fieldNames) builder.setField(fieldName, 0);
    BinaryObject binObj = builder.build();
    Collection<String> fieldsBin = binObj.type().fieldNames();
    assertEquals(fieldNames.length, fieldsBin.size());
    int i = 0;
    for (String fieldName : fieldsBin) {
        assertEquals(fieldNames[i], fieldName);
        ++i;
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 30 with BinaryObjectBuilderImpl

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

the class BinaryObjectBuilderAdditionalSelfTest method testTimestampArrayOverride.

/**
     *
     */
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testTimestampArrayOverride() {
    GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
    BinaryObjectBuilderImpl mutableObj = wrap(obj);
    Timestamp[] arr = { new Timestamp(100020003) };
    mutableObj.setField("foo", arr, Object.class);
    GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
    assertEquals(Timestamp[].class, res.foo.getClass());
    assertTrue(Objects.deepEquals(arr, res.foo));
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Timestamp(java.sql.Timestamp)

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