Search in sources :

Example 51 with BinaryObject

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

the class GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest method doTestGet.

/**
     * @throws Exception Exception.
     */
private void doTestGet(boolean withKeepBinary) throws Exception {
    try {
        clientMode = false;
        startGrid(0);
        clientMode = true;
        startGrid(1);
        Class valCls = grid(1).configuration().getClassLoader().loadClass(TEST_VALUE);
        assertTrue(grid(1).configuration().isClientMode());
        assertFalse(grid(0).configuration().isClientMode());
        IgniteCache cache1 = grid(1).cache(DEFAULT_CACHE_NAME);
        IgniteCache cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
        if (withKeepBinary) {
            cache1 = cache1.withKeepBinary();
            cache0 = cache0.withKeepBinary();
        }
        cache1.put("key", valCls.newInstance());
        if (withKeepBinary) {
            BinaryObject obj = (BinaryObject) (cache0.get("key"));
            try {
                obj.deserialize();
                fail("Exception did not happened.");
            } catch (BinaryInvalidTypeException ignored) {
            // No-op.
            }
        } else
            try {
                cache0.get("key");
                fail("Exception did not happened.");
            } catch (BinaryInvalidTypeException ignored) {
            // No-op.
            }
    } finally {
        stopAllGrids();
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryInvalidTypeException(org.apache.ignite.binary.BinaryInvalidTypeException) IgniteCache(org.apache.ignite.IgniteCache)

Example 52 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method checkGetAllTx.

/**
     * @param concurrency Concurrency.
     * @param isolation Isolation.
     */
private void checkGetAllTx(TransactionConcurrency concurrency, TransactionIsolation isolation) {
    if (atomicityMode() != TRANSACTIONAL)
        return;
    IgniteCache<Integer, TestObject> c = jcache(0);
    IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache();
    for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i));
    for (int i = 0; i < ENTRY_CNT; ) {
        Set<Integer> keys = new HashSet<>();
        for (int j = 0; j < 10; j++) keys.add(i++);
        try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
            Map<Integer, TestObject> objs = c.getAll(keys);
            assertEquals(10, objs.size());
            for (Map.Entry<Integer, TestObject> e : objs.entrySet()) assertEquals(e.getKey().intValue(), e.getValue().val);
            tx.commit();
        }
    }
    for (int i = 0; i < ENTRY_CNT; ) {
        Set<Integer> keys = new HashSet<>();
        for (int j = 0; j < 10; j++) keys.add(i++);
        try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
            Map<Integer, BinaryObject> objs = kpc.getAll(keys);
            assertEquals(10, objs.size());
            for (Map.Entry<Integer, BinaryObject> e : objs.entrySet()) {
                BinaryObject val = e.getValue();
                assertEquals(new Integer(e.getKey().intValue()), val.field("val"));
                kpc.put(e.getKey(), val);
                assertFalse("Key=" + i, val instanceof BinaryObjectOffheapImpl);
            }
            tx.commit();
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Transaction(org.apache.ignite.transactions.Transaction) Map(java.util.Map) HashMap(java.util.HashMap) BinaryObjectOffheapImpl(org.apache.ignite.internal.binary.BinaryObjectOffheapImpl) HashSet(java.util.HashSet)

Example 53 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method testCrossFormatObjectsIdentity.

/**
     *
     */
@SuppressWarnings("unchecked")
public void testCrossFormatObjectsIdentity() {
    IgniteCache c = binKeysCache();
    c.put(new ComplexBinaryFieldsListHashedKey(), "zzz");
    // Now let's build an identical key for get
    BinaryObjectBuilder bldr = grid(0).binary().builder(ComplexBinaryFieldsListHashedKey.class.getName());
    bldr.setField("firstField", 1);
    bldr.setField("secondField", "value");
    bldr.setField("thirdField", 0x1020304050607080L);
    BinaryObject binKey = bldr.build();
    assertEquals("zzz", c.get(binKey));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteCache(org.apache.ignite.IgniteCache) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 54 with BinaryObject

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

the class GridCacheBinaryObjectsAbstractSelfTest method testGet.

/**
     * @throws Exception If failed.
     */
public void testGet() 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.get(i);
        assertEquals(i, obj.val);
    }
    IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache();
    for (int i = 0; i < ENTRY_CNT; i++) {
        BinaryObject po = kpc.get(i);
        assertEquals(i, (int) po.field("val"));
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 55 with BinaryObject

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

the class WithKeepBinaryCacheFullApiTest method checkInvokeAllResult.

/**
     * @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 checkInvokeAllResult(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);
        if (cache.get(e.getKey()) == null)
            cache.get(e.getKey());
        assertEquals(cacheVal, deserializeBinary(cache.get(e.getKey())));
    }
}
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)

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