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);
}
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;
}
});
}
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);
}
}
}
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());
}
}
}
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())));
}
}
Aggregations