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