Search in sources :

Example 6 with EntryProcessorResult

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

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

the class GridCacheRebalancingOrderingTest method testEvents.

/**
     * @throws Exception If failed.
     */
public void testEvents() throws Exception {
    Ignite ignite = startGrid(0);
    ServerStarter srvStarter = startServers();
    IgniteCache<IntegerKey, Integer> cache = ignite.cache(TEST_CACHE_NAME);
    // Generate a key per partition.
    Map<Integer, IntegerKey> keyMap = generateKeysForPartitions(ignite, cache);
    // Populate a random number of keys per partition.
    Map<Integer, Set<IntegerKey>> partMap = new HashMap<>(keyMap.size());
    for (Map.Entry<Integer, IntegerKey> entry : keyMap.entrySet()) {
        Integer part = entry.getKey();
        int affinity = entry.getValue().getKey();
        int cnt = RANDOM.nextInt(10) + 1;
        Set<IntegerKey> keys = new HashSet<>(cnt);
        for (int i = 0; i < cnt; i++) {
            IntegerKey key = new IntegerKey(RANDOM.nextInt(10000), affinity);
            keys.add(key);
            cache.put(key, RANDOM.nextInt());
        }
        partMap.put(part, keys);
    }
    // Display the partition map.
    X.println("Partition Map:");
    for (Map.Entry<Integer, Set<IntegerKey>> entry : partMap.entrySet()) X.println(entry.getKey() + ": " + entry.getValue());
    // Validate keys across all partitions.
    Affinity<IntegerKey> affinity = ignite.affinity(cache.getName());
    Map<IntegerKey, KeySetValidator> validatorMap = new HashMap<>(partMap.size());
    for (Map.Entry<Integer, Set<IntegerKey>> partEntry : partMap.entrySet()) {
        Integer part = partEntry.getKey();
        validatorMap.put(keyMap.get(part), new KeySetValidator(partEntry.getValue()));
    }
    int i = 0;
    while (!srvStarter.isDone()) {
        Map<IntegerKey, EntryProcessorResult<KeySetValidator.Result>> results = cache.invokeAll(validatorMap);
        Set<Integer> failures = new HashSet<>();
        Set<Integer> retries = new HashSet<>();
        for (Map.Entry<IntegerKey, EntryProcessorResult<KeySetValidator.Result>> result : results.entrySet()) {
            try {
                if (result.getValue().get() == KeySetValidator.Result.RETRY)
                    retries.add(affinity.partition(result.getKey()));
            } catch (Exception e) {
                X.println("!!! " + e.getMessage());
                e.printStackTrace();
                failures.add(affinity.partition(result.getKey()));
            }
        }
        if (!failures.isEmpty()) {
            X.println("*** Key validation failed for partitions: " + failures);
            fail("https://issues.apache.org/jira/browse/IGNITE-3456");
        } else if (!retries.isEmpty()) {
            X.println("*** Key validation requires a retry for partitions: " + retries);
            retries.clear();
        } else
            X.println("*** Key validation was successful: " + i);
        i++;
        Thread.sleep(500);
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EntryProcessorException(javax.cache.processor.EntryProcessorException) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Ignite(org.apache.ignite.Ignite) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet)

Example 8 with EntryProcessorResult

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

the class GridCacheAtomicEntryProcessorDeploymentSelfTest method doTestInvokeAll.

/**
     * @throws Exception In case of error.
     */
private void doTestInvokeAll() throws Exception {
    try {
        clientMode = false;
        startGrid(0);
        clientMode = true;
        startGrid(1);
        Class procCls = grid(1).configuration().getClassLoader().loadClass(getEntryProcessor());
        Class valCls = grid(1).configuration().getClassLoader().loadClass(TEST_VALUE);
        assertTrue(grid(1).configuration().isClientMode());
        assertFalse(grid(0).configuration().isClientMode());
        IgniteCache cache = getCache();
        HashSet keys = new HashSet();
        for (int i = 0; i < 3; i++) {
            String key = "key" + i;
            cache.put(key, valCls.newInstance());
            keys.add(key);
        }
        Map<String, EntryProcessorResult> res = (Map<String, EntryProcessorResult>) cache.invokeAll(keys, (CacheEntryProcessor) procCls.newInstance());
        assertEquals(3, res.size());
        for (EntryProcessorResult result : res.values()) assertTrue((Boolean) result.get());
        // Checks that get produces no exceptions.
        for (int i = 0; i < 3; i++) {
            String key = "key" + i;
            cache.get(key);
        }
    } finally {
        stopAllGrids();
    }
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) CacheEntryProcessor(org.apache.ignite.cache.CacheEntryProcessor) IgniteCache(org.apache.ignite.IgniteCache) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with EntryProcessorResult

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

the class CacheReadWriteQuorumTest 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 10 with EntryProcessorResult

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

the class CacheWriteQuorumTest 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)

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