Search in sources :

Example 1 with EntryProcessorResult

use of javax.cache.processor.EntryProcessorResult in project hazelcast by hazelcast.

the class ClientCacheReadWriteQuorumTest method testInvokeAllOperationSuccessfulWhenQuorumSizeMet.

@Test
public void testInvokeAllOperationSuccessfulWhenQuorumSizeMet() {
    HashSet<Integer> hashSet = new HashSet<Integer>();
    hashSet.add(123);
    EntryProcessorResult epr = cache1.invokeAll(hashSet, new SimpleEntryProcessor()).get(123);
    assertNull(epr);
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with EntryProcessorResult

use of javax.cache.processor.EntryProcessorResult in project ignite by apache.

the class GridDhtAtomicCache method invoke0.

/**
     * @param async Async operation flag.
     * @param key Key.
     * @param entryProcessor Entry processor.
     * @param args Entry processor arguments.
     * @return Future.
     */
private <T> IgniteInternalFuture<EntryProcessorResult<T>> invoke0(boolean async, K key, EntryProcessor<K, V, T> entryProcessor, Object... args) {
    A.notNull(key, "key", entryProcessor, "entryProcessor");
    if (keyCheck)
        validateCacheKey(key);
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut = update0(key, null, entryProcessor, args, false, null, async);
    return fut.chain(new CX1<IgniteInternalFuture<Map<K, EntryProcessorResult<T>>>, EntryProcessorResult<T>>() {

        @Override
        public EntryProcessorResult<T> applyx(IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut) throws IgniteCheckedException {
            Map<K, EntryProcessorResult<T>> resMap = fut.get();
            if (resMap != null) {
                assert resMap.isEmpty() || resMap.size() == 1 : resMap.size();
                EntryProcessorResult<T> res = resMap.isEmpty() ? null : resMap.values().iterator().next();
                if (res instanceof CacheInvokeResult) {
                    CacheInvokeResult invokeRes = (CacheInvokeResult) res;
                    if (invokeRes.result() != null)
                        res = CacheInvokeResult.fromResult((T) ctx.unwrapBinaryIfNeeded(invokeRes.result(), keepBinary, false));
                }
                return res;
            }
            return null;
        }
    });
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IGNITE_ATOMIC_DEFERRED_ACK_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_DEFERRED_ACK_TIMEOUT) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) HashMap(java.util.HashMap) CacheInvokeResult(org.apache.ignite.internal.processors.cache.CacheInvokeResult)

Example 3 with EntryProcessorResult

use of javax.cache.processor.EntryProcessorResult in project ignite by apache.

the class PlatformCache method writeInvokeAllResult.

/**
     * Writes the result of InvokeAll cache method.
     *
     * @param writer Writer.
     * @param results Results.
     */
private static void writeInvokeAllResult(BinaryRawWriterEx writer, Map<Object, EntryProcessorResult> results) {
    if (results == null) {
        writer.writeInt(-1);
        return;
    }
    writer.writeInt(results.size());
    for (Map.Entry<Object, EntryProcessorResult> entry : results.entrySet()) {
        writer.writeObjectDetached(entry.getKey());
        EntryProcessorResult procRes = entry.getValue();
        try {
            Object res = procRes.get();
            // No exception
            writer.writeBoolean(false);
            writer.writeObjectDetached(res);
        } catch (Exception ex) {
            // Exception
            writer.writeBoolean(true);
            PlatformUtils.writeError(ex, writer);
        }
    }
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException)

Example 4 with EntryProcessorResult

use of javax.cache.processor.EntryProcessorResult in project ignite by apache.

the class CacheSerializableTransactionsTest method testTxConflictInvokeAll.

/**
     * @throws Exception If failed
     */
public void testTxConflictInvokeAll() throws Exception {
    Ignite ignite0 = ignite(0);
    for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
        logCacheInfo(ccfg);
        try {
            IgniteCache<Integer, Integer> cache0 = ignite0.createCache(ccfg);
            final Integer key1 = primaryKey(ignite(0).cache(cache0.getName()));
            final Integer key2 = primaryKey(ignite(1).cache(cache0.getName()));
            Map<Integer, Integer> vals = new HashMap<>();
            int newVal = 0;
            for (Ignite ignite : G.allGrids()) {
                log.info("Test node: " + ignite.name());
                IgniteTransactions txs = ignite.transactions();
                IgniteCache<Integer, Integer> cache = ignite.cache(cache0.getName());
                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
                    Map<Integer, EntryProcessorResult<Integer>> res = cache.invokeAll(F.asSet(key1, key2), new SetValueProcessor(newVal));
                    if (!vals.isEmpty()) {
                        EntryProcessorResult<Integer> res1 = res.get(key1);
                        assertNotNull(res1);
                        assertEquals(vals.get(key1), res1.get());
                        EntryProcessorResult<Integer> res2 = res.get(key2);
                        assertNotNull(res2);
                        assertEquals(vals.get(key2), res2.get());
                    } else
                        assertTrue(res.isEmpty());
                    tx.commit();
                }
                checkValue(key1, newVal, cache.getName());
                checkValue(key2, newVal, cache.getName());
                vals.put(key1, newVal);
                vals.put(key2, newVal);
                try {
                    try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
                        Map<Integer, EntryProcessorResult<Integer>> res = cache.invokeAll(F.asSet(key1, key2), new SetValueProcessor(newVal + 1));
                        EntryProcessorResult<Integer> res1 = res.get(key1);
                        assertNotNull(res1);
                        assertEquals(vals.get(key1), res1.get());
                        EntryProcessorResult<Integer> res2 = res.get(key2);
                        assertNotNull(res2);
                        assertEquals(vals.get(key2), res2.get());
                        updateKey(cache0, key1, -1);
                        tx.commit();
                    }
                    fail();
                } catch (TransactionOptimisticException e) {
                    log.info("Expected exception: " + e);
                }
                checkValue(key1, -1, cache.getName());
                checkValue(key2, newVal, cache.getName());
                vals.put(key1, -1);
                vals.put(key2, newVal);
                newVal++;
            }
        } finally {
            destroyCache(ccfg.getName());
        }
    }
}
Also used : TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IgniteTransactions(org.apache.ignite.IgniteTransactions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite)

Example 5 with EntryProcessorResult

use of javax.cache.processor.EntryProcessorResult 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

EntryProcessorResult (javax.cache.processor.EntryProcessorResult)26 Map (java.util.Map)11 LinkedHashMap (java.util.LinkedHashMap)10 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 EntryProcessor (javax.cache.processor.EntryProcessor)5 EntryProcessorException (javax.cache.processor.EntryProcessorException)5 Transaction (org.apache.ignite.transactions.Transaction)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Ignite (org.apache.ignite.Ignite)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)3 CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)3