Search in sources :

Example 76 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 77 with BinaryObject

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

the class BinaryMarshallerSelfTest method testBinaryCopyCharArray.

/**
     * @throws Exception If failed.
     */
public void testBinaryCopyCharArray() 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("cArr", new char[] { 1, 2, 3 }));
    assertArrayEquals(new char[] { 1, 2, 3 }, copy.<char[]>field("cArr"));
    SimpleObject obj0 = copy.deserialize();
    assertArrayEquals(new char[] { 1, 2, 3 }, obj0.cArr);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 78 with BinaryObject

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

the class BinaryMarshallerSelfTest method testBinaryCopyFloatArray.

/**
     * @throws Exception If failed.
     */
public void testBinaryCopyFloatArray() 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("fArr", new float[] { 1, 2, 3 }));
    assertArrayEquals(new float[] { 1, 2, 3 }, copy.<float[]>field("fArr"), 0);
    SimpleObject obj0 = copy.deserialize();
    assertArrayEquals(new float[] { 1, 2, 3 }, obj0.fArr, 0);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 79 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)

Example 80 with BinaryObject

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

the class DynamicIndexAbstractSelfTest method put.

/**
     * Put key to cache.
     *
     * @param node Node.
     * @param id ID.
     */
protected static void put(Ignite node, long id) {
    BinaryObject key = key(node, id);
    BinaryObject val = value(node, id);
    cache(node).put(key, val);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)173 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)54 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)24 IgniteCache (org.apache.ignite.IgniteCache)21 Ignite (org.apache.ignite.Ignite)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 LinkedHashMap (java.util.LinkedHashMap)13 ArrayList (java.util.ArrayList)12 Cache (javax.cache.Cache)12 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 List (java.util.List)8 UUID (java.util.UUID)8 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)6 BinaryType (org.apache.ignite.binary.BinaryType)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 Transaction (org.apache.ignite.transactions.Transaction)6