Search in sources :

Example 56 with BinaryObject

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

the class WithKeepBinaryCacheFullApiTest method checkInvokeAllAsyncResult.

/**
     * @param cache Cache.
     * @param resMap Result map.
     * @param expRes Expected result.
     * @param cacheVal Expected cache value for key.
     * @param deserializeRes Deseriallize result flag.
     */
private void checkInvokeAllAsyncResult(IgniteCache cache, Map<Object, EntryProcessorResult<Object>> resMap, Object expRes, Object cacheVal, boolean deserializeRes) {
    for (Map.Entry<Object, EntryProcessorResult<Object>> e : resMap.entrySet()) {
        info("Key: " + e.getKey());
        assertTrue("Wrong key type, binary object expected: " + e.getKey(), e.getKey() instanceof BinaryObject);
        Object res = e.getValue().get();
        // TODO IGNITE-2953: delete the following if when the issue wiil be fixed.
        if (deserializeRes)
            assertEquals(expRes, deserializeRes ? deserializeBinary(res) : res);
        assertEquals(cacheVal, deserializeBinary(cache.getAsync(e.getKey()).get()));
    }
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 57 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method testGetAsync.

/**
     * @throws Exception If failed.
     */
public void testGetAsync() throws Exception {
    IgniteCache<Integer, TestObject> c = jcache(0);
    for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
    for (int i = 0; i < ENTRY_CNT; i++) {
        TestObject obj = c.getAsync(i).get();
        assertNotNull(obj);
        assertEquals(i, obj.val);
    }
    IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache();
    for (int i = 0; i < ENTRY_CNT; i++) {
        BinaryObject po = kpc.getAsync(i).get();
        assertEquals(i, (int) po.field("val"));
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 58 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method testCircularReference.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
public void testCircularReference() throws Exception {
    IgniteCache c = keepBinaryCache();
    TestReferenceObject obj1 = new TestReferenceObject();
    obj1.obj = new TestReferenceObject(obj1);
    c.put(1, obj1);
    BinaryObject po = (BinaryObject) c.get(1);
    String str = po.toString();
    log.info("toString: " + str);
    assertNotNull(str);
    BinaryNameMapper nameMapper = BinaryContext.defaultNameMapper();
    if (cfg.getBinaryConfiguration() != null && cfg.getBinaryConfiguration().getNameMapper() != null)
        nameMapper = cfg.getBinaryConfiguration().getNameMapper();
    String typeName = nameMapper.typeName(TestReferenceObject.class.getName());
    assertTrue("Unexpected toString: " + str, S.INCLUDE_SENSITIVE ? str.startsWith(typeName) && str.contains("obj=" + typeName + " [") : str.startsWith("BinaryObject") && str.contains("idHash=") && str.contains("hash="));
    TestReferenceObject obj1_r = po.deserialize();
    assertNotNull(obj1_r);
    TestReferenceObject obj2_r = obj1_r.obj;
    assertNotNull(obj2_r);
    assertSame(obj1_r, obj2_r.obj);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteCache(org.apache.ignite.IgniteCache) BinaryNameMapper(org.apache.ignite.binary.BinaryNameMapper)

Example 59 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method checkGetAsyncTx.

/**
     * @param concurrency Concurrency.
     * @param isolation Isolation.
     */
private void checkGetAsyncTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
    if (atomicityMode() != TRANSACTIONAL)
        return;
    IgniteCache<Integer, TestObject> c = jcache(0);
    IgniteCache<Integer, BinaryObject> kbCache = keepBinaryCache();
    for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
    for (int i = 0; i < ENTRY_CNT; i++) {
        try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
            TestObject obj = c.getAsync(i).get();
            assertEquals(i, obj.val);
            tx.commit();
        }
    }
    for (int i = 0; i < ENTRY_CNT; i++) {
        try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
            BinaryObject val = kbCache.getAsync(i).get();
            assertFalse("Key=" + i, val instanceof BinaryObjectOffheapImpl);
            assertEquals(i, (int) val.field("val"));
            kbCache.putAsync(i, val).get();
            tx.commit();
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)

Example 60 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method checkGetTx.

/**
     * @param concurrency Concurrency.
     * @param isolation Isolation.
     */
private void checkGetTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
    if (atomicityMode() != TRANSACTIONAL)
        return;
    IgniteCache<Integer, TestObject> c = jcache(0);
    IgniteCache<Integer, BinaryObject> kbCache = keepBinaryCache();
    for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
    for (int i = 0; i < ENTRY_CNT; i++) {
        try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
            TestObject obj = c.get(i);
            assertEquals(i, obj.val);
            tx.commit();
        }
    }
    for (int i = 0; i < ENTRY_CNT; i++) {
        try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
            BinaryObject val = kbCache.get(i);
            assertFalse("Key=" + i, val instanceof BinaryObjectOffheapImpl);
            assertEquals(i, (int) val.field("val"));
            kbCache.put(i, val);
            tx.commit();
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl)

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