Search in sources :

Example 86 with BinaryObject

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

the class BinaryMarshallerSelfTest method testThreadLocalArrayReleased.

/**
 * @throws IgniteCheckedException If failed.
 */
public void testThreadLocalArrayReleased() throws Exception {
    // Checking the writer directly.
    assertEquals(false, INSTANCE.isAcquired());
    BinaryMarshaller marsh = binaryMarshaller();
    try (BinaryWriterExImpl writer = new BinaryWriterExImpl(binaryContext(marsh))) {
        assertEquals(true, INSTANCE.isAcquired());
        writer.writeString("Thread local test");
        writer.array();
        assertEquals(true, INSTANCE.isAcquired());
    }
    // Checking the binary marshaller.
    assertEquals(false, INSTANCE.isAcquired());
    marsh = binaryMarshaller();
    marsh.marshal(new SimpleObject());
    assertEquals(false, INSTANCE.isAcquired());
    marsh = binaryMarshaller();
    // Checking the builder.
    BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(marsh), "org.gridgain.foo.bar.TestClass");
    builder.setField("a", "1");
    BinaryObject binaryObj = builder.build();
    assertEquals(false, INSTANCE.isAcquired());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 87 with BinaryObject

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

the class BinaryMarshallerSelfTest method testBinaryCopyStringArray.

/**
 * @throws Exception If failed.
 */
public void testBinaryCopyStringArray() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
    SimpleObject obj = simpleObject();
    BinaryObject po = marshal(obj, marsh);
    BinaryObject copy = copy(po, F.<String, Object>asMap("strArr", new String[] { "str1", "str2" }));
    assertArrayEquals(new String[] { "str1", "str2" }, copy.<String[]>field("strArr"));
    SimpleObject obj0 = copy.deserialize();
    assertArrayEquals(new String[] { "str1", "str2" }, obj0.strArr);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 88 with BinaryObject

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

the class BinaryObjectBuilderAdditionalSelfTest method testBuildFromObjectWithoutSchema.

/**
 * Ensure that object w/o schema can be re-built.
 */
public void testBuildFromObjectWithoutSchema() {
    BinaryObjectBuilderImpl binBuilder = wrap(new GridBinaryTestClass2());
    BinaryObject binObj = binBuilder.build();
    BinaryObjectBuilderImpl binBuilder2 = wrap(binObj);
    binBuilder2.build();
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClass2(org.apache.ignite.internal.binary.test.GridBinaryTestClass2)

Example 89 with BinaryObject

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

the class BinaryObjectBuilderAdditionalSelfTest method testCollectionsSerialization.

/**
 * Check that correct type is stored in binary object.
 */
public void testCollectionsSerialization() {
    final BinaryObjectBuilder root = newWrapper(BigInteger.class);
    final List<Integer> arrList = new ArrayList<>();
    arrList.add(Integer.MAX_VALUE);
    final List<Integer> linkedList = new LinkedList<>();
    linkedList.add(Integer.MAX_VALUE);
    final Set<Integer> hashSet = new HashSet<>();
    hashSet.add(Integer.MAX_VALUE);
    final Set<Integer> linkedHashSet = new LinkedHashSet<>();
    linkedHashSet.add(Integer.MAX_VALUE);
    final Map<String, String> hashMap = new HashMap<>();
    hashMap.put("key", "val");
    final Map<String, String> linkedHashMap = new LinkedHashMap<>();
    linkedHashMap.put("key", "val");
    // collections
    root.setField("arrayList", arrList);
    root.setField("linkedList", linkedList);
    root.setField("hashSet", hashSet);
    root.setField("linkedHashSet", linkedHashSet);
    root.setField("singletonList", Collections.singletonList(Integer.MAX_VALUE), Collection.class);
    root.setField("singletonSet", Collections.singleton(Integer.MAX_VALUE), Collection.class);
    // maps
    root.setField("hashMap", hashMap);
    root.setField("linkedHashMap", linkedHashMap);
    root.setField("singletonMap", Collections.singletonMap("key", "val"), Map.class);
    // objects
    root.setField("asList", Collections.singletonList(Integer.MAX_VALUE));
    root.setField("asSet", Collections.singleton(Integer.MAX_VALUE));
    root.setField("asMap", Collections.singletonMap("key", "val"));
    root.setField("asListHint", Collections.singletonList(Integer.MAX_VALUE), List.class);
    root.setField("asSetHint", Collections.singleton(Integer.MAX_VALUE), Set.class);
    root.setField("asMapHint", (AbstractMap) Collections.singletonMap("key", "val"), AbstractMap.class);
    BinaryObject binaryObj = root.build();
    final String COL = "Collection";
    final String MAP = "Map";
    final String OBJ = "Object";
    assert COL.equals(binaryObj.type().fieldTypeName("arrayList"));
    assert COL.equals(binaryObj.type().fieldTypeName("linkedList"));
    assert COL.equals(binaryObj.type().fieldTypeName("hashSet"));
    assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
    assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
    assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
    assert COL.equals(binaryObj.type().fieldTypeName("singletonList"));
    assert COL.equals(binaryObj.type().fieldTypeName("singletonSet"));
    assert MAP.equals(binaryObj.type().fieldTypeName("singletonMap"));
    assert COL.equals(binaryObj.type().fieldTypeName("asList"));
    assert OBJ.equals(binaryObj.type().fieldTypeName("asSet"));
    assert OBJ.equals(binaryObj.type().fieldTypeName("asMap"));
    assert OBJ.equals(binaryObj.type().fieldTypeName("asListHint"));
    assert OBJ.equals(binaryObj.type().fieldTypeName("asSetHint"));
    assert OBJ.equals(binaryObj.type().fieldTypeName("asMapHint"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) BigInteger(java.math.BigInteger) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 90 with BinaryObject

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

the class BinaryObjectBuilderAdditionalSelfTest method testWrongMetadataNullField2.

/**
 */
public void testWrongMetadataNullField2() {
    BinaryObjectBuilder builder = binaries().builder("SomeType1");
    builder.setField("dateField", null);
    builder.setField("objectField", null, Integer.class);
    BinaryObject obj = builder.build();
    try {
        builder = binaries().builder(obj);
        builder.setField("dateField", new Date());
        builder.build();
    } catch (BinaryObjectException ex) {
        assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
    }
    builder = binaries().builder(obj);
    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 : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Date(java.util.Date) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)200 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)55 Ignite (org.apache.ignite.Ignite)28 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)26 IgniteCache (org.apache.ignite.IgniteCache)25 HashMap (java.util.HashMap)16 Cache (javax.cache.Cache)15 ArrayList (java.util.ArrayList)13 Map (java.util.Map)13 LinkedHashMap (java.util.LinkedHashMap)12 List (java.util.List)10 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 IgniteException (org.apache.ignite.IgniteException)9 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 UUID (java.util.UUID)8 BigInteger (java.math.BigInteger)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 BinaryType (org.apache.ignite.binary.BinaryType)7