Search in sources :

Example 76 with BinaryObjectBuilder

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

the class GridCacheBinaryObjectsAbstractSelfTest method checkTransform.

/**
     * @param key Key.
     * @throws Exception If failed.
     */
private void checkTransform(Integer key) throws Exception {
    log.info("Transform: " + key);
    IgniteCache<Integer, BinaryObject> c = keepBinaryCache();
    try {
        c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {

            @Override
            public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
                BinaryObject val = e.getValue();
                assertNull("Unexpected value: " + val, val);
                return null;
            }
        });
        jcache(0).put(key, new TestObject(1));
        c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {

            @Override
            public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
                BinaryObject val = e.getValue();
                assertNotNull("Unexpected value: " + val, val);
                assertEquals(new Integer(1), val.field("val"));
                Ignite ignite = e.unwrap(Ignite.class);
                IgniteBinary binaries = ignite.binary();
                BinaryObjectBuilder builder = binaries.builder(val);
                builder.setField("val", 2);
                e.setValue(builder.build());
                return null;
            }
        });
        BinaryObject obj = c.get(key);
        assertEquals(new Integer(2), obj.field("val"));
        c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {

            @Override
            public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
                BinaryObject val = e.getValue();
                assertNotNull("Unexpected value: " + val, val);
                assertEquals(new Integer(2), val.field("val"));
                e.setValue(val);
                return null;
            }
        });
        obj = c.get(key);
        assertEquals(new Integer(2), obj.field("val"));
        c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {

            @Override
            public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
                BinaryObject val = e.getValue();
                assertNotNull("Unexpected value: " + val, val);
                assertEquals(new Integer(2), val.field("val"));
                e.remove();
                return null;
            }
        });
        assertNull(c.get(key));
    } finally {
        c.remove(key);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 77 with BinaryObjectBuilder

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

the class GridDataStreamerImplSelfTest method testAddBinaryCreatedWithBuilder.

/**
     *  Tries to propagate cache with binary objects created using the builder.
     *
     * @throws Exception If failed.
     */
public void testAddBinaryCreatedWithBuilder() throws Exception {
    try {
        binaries = true;
        startGrids(2);
        awaitPartitionMapExchange();
        Ignite g0 = grid(0);
        IgniteDataStreamer<Integer, BinaryObject> dataLdr = g0.dataStreamer(DEFAULT_CACHE_NAME);
        for (int i = 0; i < 500; i++) {
            BinaryObjectBuilder obj = g0.binary().builder("NoExistedClass");
            obj.setField("id", i);
            obj.setField("name", String.valueOf("name = " + i));
            dataLdr.addData(i, obj.build());
        }
        dataLdr.close(false);
        assertEquals(500, g0.cache(DEFAULT_CACHE_NAME).size(CachePeekMode.ALL));
        assertEquals(500, grid(1).cache(DEFAULT_CACHE_NAME).size(CachePeekMode.ALL));
    } finally {
        G.stopAll(true);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Aggregations

BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)77 BinaryObject (org.apache.ignite.binary.BinaryObject)60 Ignite (org.apache.ignite.Ignite)11 IgniteBinary (org.apache.ignite.IgniteBinary)7 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)7 Date (java.util.Date)4 BinaryType (org.apache.ignite.binary.BinaryType)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 IgniteCache (org.apache.ignite.IgniteCache)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2