use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class CachePutEventListenerErrorSelfTest method doTest.
/**
* @param cacheMode Cache mode.
* @param atomicityMode Atomicity mode.
* @throws Exception If failed.
*/
private void doTest(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
Ignite ignite = grid("client");
try {
CacheConfiguration<Integer, Integer> cfg = defaultCacheConfiguration();
cfg.setName("cache");
cfg.setCacheMode(cacheMode);
cfg.setAtomicityMode(atomicityMode);
IgniteCache<Integer, Integer> cache = ignite.createCache(cfg);
IgniteFuture f = cache.putAsync(0, 0);
try {
f.get(2000);
assert false : "Exception was not thrown";
} catch (CacheException e) {
info("Caught expected exception: " + e);
}
} finally {
ignite.destroyCache("cache");
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class CacheRebalancingSelfTest method testRebalanceFuture.
/**
* @throws Exception If failed.
*/
public void testRebalanceFuture() throws Exception {
IgniteEx ig0 = startGrid(0);
startGrid(1);
IgniteCache<Object, Object> cache = ig0.cache(DEFAULT_CACHE_NAME);
IgniteFuture fut1 = cache.rebalance();
fut1.get();
startGrid(2);
IgniteFuture fut2 = cache.rebalance();
assert internalFuture(fut2) != internalFuture(fut1);
fut2.get();
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridCachePartitionedExplicitLockNodeFailureSelfTest method testLockFromNearOrBackup.
/** @throws Exception If check failed. */
@SuppressWarnings("ErrorNotRethrown")
public void testLockFromNearOrBackup() throws Exception {
startGrids(GRID_CNT);
int idx = 0;
info("Grid will be stopped: " + idx);
Integer key = 0;
while (grid(idx).affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key).id().equals(grid(0).localNode().id())) key++;
ClusterNode node = grid(idx).affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key);
info("Primary node for key [id=" + node.id() + ", order=" + node.order() + ", key=" + key + ']');
IgniteCache<Integer, String> cache = jcache(idx);
cache.put(key, "val");
Lock lock = cache.lock(key);
assert lock.tryLock();
for (int checkIdx = 1; checkIdx < GRID_CNT; checkIdx++) {
info("Check grid index: " + checkIdx);
IgniteCache<Integer, String> checkCache = jcache(checkIdx);
assert !checkCache.lock(key).tryLock();
}
Collection<IgniteFuture<?>> futs = new LinkedList<>();
for (int i = 1; i < GRID_CNT; i++) {
futs.add(waitForLocalEvent(grid(i).events(), new P1<Event>() {
@Override
public boolean apply(Event e) {
info("Received grid event: " + e);
return true;
}
}, EVT_NODE_LEFT));
}
stopGrid(idx);
for (IgniteFuture<?> fut : futs) fut.get();
for (int i = 0; i < 3; i++) {
try {
for (int checkIdx = 1; checkIdx < GRID_CNT; checkIdx++) {
info("Check grid index: " + checkIdx);
IgniteCache<Integer, String> checkCache = jcache(checkIdx);
assert !checkCache.isLocalLocked(key, false);
}
} catch (AssertionError e) {
if (i == 2)
throw e;
U.warn(log, "Check failed (will retry in 1000 ms): " + e.getMessage());
U.sleep(1000);
continue;
}
// Check passed on all grids.
break;
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridScheduleSelfTest method testScheduleRunnable.
/**
* @throws Exception If failed.
*/
public void testScheduleRunnable() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
SchedulerFuture<?> fut = null;
// 1 minute frequency.
long freq = 60;
// 2 seconds delay.
long delay = 2;
try {
// Execute 2 times after 2 seconds delay every minute.
fut = grid(0).scheduler().scheduleLocal(new Runnable() {
@Override
public void run() {
latch.countDown();
info(">>> EXECUTING SCHEDULED RUNNABLE! <<<");
}
}, "{2, 2} * * * * *");
assert !fut.isDone();
assert !fut.isCancelled();
assert fut.last() == null;
final AtomicInteger notifyCnt = new AtomicInteger();
fut.listen(new CI1<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> e) {
notifyCnt.incrementAndGet();
}
});
final SchedulerFuture<?> fut0 = fut;
//noinspection ThrowableNotThrown
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
fut0.listenAsync(new IgniteInClosure<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> fut) {
// No-op
}
}, null);
return null;
}
}, NullPointerException.class, null);
fut.listenAsync(new IgniteInClosure<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> fut) {
assertEquals(Thread.currentThread().getName(), CUSTOM_THREAD_NAME);
notifyCnt.incrementAndGet();
}
}, exec);
//noinspection ThrowableNotThrown
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
fut0.chainAsync(new IgniteClosure<IgniteFuture<?>, String>() {
@Override
public String apply(IgniteFuture<?> fut) {
return null;
}
}, null);
return null;
}
}, NullPointerException.class, null);
IgniteFuture<String> chained1 = fut.chainAsync(new IgniteClosure<IgniteFuture<?>, String>() {
@Override
public String apply(IgniteFuture<?> fut) {
assertEquals(Thread.currentThread().getName(), CUSTOM_THREAD_NAME);
fut.get();
return "done-custom";
}
}, exec);
long timeTillRun = freq + delay;
info("Going to wait for the first run: " + timeTillRun);
latch.await(timeTillRun, SECONDS);
assertEquals(0, latch.getCount());
assert !fut.isDone();
assert !fut.isCancelled();
assert fut.last() == null;
assertFalse(chained1.isDone());
info("Going to wait for 2nd run: " + timeTillRun);
// Wait until scheduling will be finished.
Thread.sleep(timeTillRun * 1000);
assert fut.isDone();
assert notifyCnt.get() == 2 * 2;
assert !fut.isCancelled();
assert fut.last() == null;
assertEquals("done-custom", chained1.get());
assertTrue(chained1.isDone());
} finally {
assert fut != null;
fut.cancel();
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class IgniteGetFromComputeBenchmark method test.
/** {@inheritDoc} */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
IgniteFuture fut = invokeFut.get();
if (fut == null || fut.isDone()) {
Set<Integer> keys = new TreeSet<>();
for (int i = 0; i < 3; i++) keys.add(nextRandom(args.range()));
asyncCache.invokeAll(keys, new SlowEntryProcessor(0));
invokeFut.set(asyncCache.future());
}
int key = nextRandom(args.range());
compute.affinityCall(CACHE_NAME, key, new GetClosure(key));
return true;
}
Aggregations