use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class CacheAsyncOperationsFailoverAbstractTest method putAllAsyncFailover.
/**
* @param threads Number of threads.
* @param opsPerThread Number of concurrent async operations per thread.
* @throws Exception If failed.
*/
private void putAllAsyncFailover(final int threads, final int opsPerThread) throws Exception {
log.info("Start test [threads=" + threads + ", opsPerThread=" + opsPerThread + ']');
final AtomicBoolean finished = new AtomicBoolean();
final long endTime = System.currentTimeMillis() + TEST_TIME;
IgniteInternalFuture<Object> restartFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.currentThread().setName("restart-thread");
while (!finished.get() && System.currentTimeMillis() < endTime) {
startGrid(NODE_CNT);
U.sleep(500);
stopGrid(NODE_CNT);
}
return null;
}
});
try {
final IgniteCache<TestKey, TestValue> cache = ignite(0).cache(DEFAULT_CACHE_NAME);
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
int iter = 0;
ThreadLocalRandom rnd = ThreadLocalRandom.current();
long time;
long lastInfo = 0;
while ((time = System.currentTimeMillis()) < endTime) {
if (time - lastInfo > 5000)
log.info("Starting operations [iter=" + iter + ']');
List<IgniteFuture<?>> futs = new ArrayList<>(opsPerThread);
for (int i = 0; i < opsPerThread; i++) {
TreeMap<TestKey, TestValue> map = new TreeMap<>();
int keys = rnd.nextInt(1, 50);
for (int k = 0; k < keys; k++) map.put(new TestKey(rnd.nextInt(10_000)), new TestValue(iter));
IgniteFuture<?> fut = cache.putAllAsync(map);
assertNotNull(fut);
futs.add(fut);
}
if (time - lastInfo > 5000) {
log.info("Waiting for futures [iter=" + iter + ']');
lastInfo = time;
}
for (IgniteFuture<?> fut : futs) fut.get();
iter++;
}
return null;
}
}, threads, "update-thread");
finished.set(true);
restartFut.get();
} finally {
finished.set(true);
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class IgniteBinaryMetadataUpdateChangingTopologySelfTest method testNoDeadlockOptimistic.
/**
* @throws Exception If failed.
*/
public void testNoDeadlockOptimistic() throws Exception {
int key1 = primaryKey(ignite(1).cache("cache"));
int key2 = primaryKey(ignite(2).cache("cache"));
TestCommunicationSpi spi = (TestCommunicationSpi) ignite(1).configuration().getCommunicationSpi();
spi.blockMessages(GridNearTxPrepareResponse.class, ignite(0).cluster().localNode().id());
IgniteCache<Object, Object> cache = ignite(0).cache("cache");
IgniteFuture futPutAll = cache.putAllAsync(F.asMap(key1, "val1", key2, new TestValue1()));
try {
Thread.sleep(500);
IgniteInternalFuture<Void> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(4);
return null;
}
});
Thread.sleep(1000);
spi.stopBlock();
futPutAll.get();
fut.get();
} finally {
stopGrid(4);
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class IgniteBinaryMetadataUpdateChangingTopologySelfTest method testNoDeadlockInvoke.
/**
* @throws Exception If failed.
*/
public void testNoDeadlockInvoke() throws Exception {
int key1 = primaryKey(ignite(1).cache("cache"));
int key2 = primaryKey(ignite(2).cache("cache"));
TestCommunicationSpi spi = (TestCommunicationSpi) ignite(1).configuration().getCommunicationSpi();
spi.blockMessages(GridNearTxPrepareResponse.class, ignite(0).cluster().localNode().id());
IgniteCache<Object, Object> cache = ignite(0).cache("cache");
IgniteFuture futInvokeAll = cache.invokeAllAsync(F.asSet(key1, key2), new TestEntryProcessor());
try {
Thread.sleep(500);
IgniteInternalFuture<Void> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(4);
return null;
}
});
Thread.sleep(1000);
spi.stopBlock();
futInvokeAll.get();
fut.get();
} finally {
stopGrid(4);
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class IgnteCacheClientWriteBehindStoreNonCoalescingTest method testNonCoalescingIncrementing.
/**
* @throws Exception If failed.
*/
public void testNonCoalescingIncrementing() throws Exception {
Ignite ignite = grid(0);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertEquals(cache.getConfiguration(CacheConfiguration.class).getCacheStoreFactory().getClass(), TestIncrementStoreFactory.class);
Set<Integer> keys = new HashSet<>();
for (int i = 0; i < 1000; i++) {
keys.add(i);
cache.put(i, i);
}
Collection<IgniteFuture<?>> futs = new ArrayList<>();
for (int i = 0; i < 100; i++) futs.add(updateKeys(cache, keys));
for (IgniteFuture<?> fut : futs) fut.get();
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridScheduleSelfTest method testScheduleCallable.
/**
* @throws Exception If failed.
*/
public void testScheduleCallable() throws Exception {
SchedulerFuture<Integer> fut = null;
// 1 minute frequency.
long freq = 60;
// 2 seconds delay.
long delay = 2;
try {
fut = grid(0).scheduler().scheduleLocal(new Callable<Integer>() {
private int cnt;
@Override
public Integer call() {
info(">>> EXECUTING SCHEDULED CALLABLE! <<<");
return ++cnt;
}
}, "{1, 2} * * * * *");
final AtomicInteger notifyCnt = new AtomicInteger();
fut.listen(new CI1<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> e) {
notifyCnt.incrementAndGet();
}
});
assert !fut.isDone();
assert !fut.isCancelled();
assert fut.last() == null;
long timeTillRun = freq + delay;
info("Going to wait for the 1st run: " + timeTillRun);
assertEquals((Integer) 1, fut.get(timeTillRun, SECONDS));
assertEquals((Integer) 1, fut.last());
assert !fut.isDone();
assert !fut.isCancelled();
info("Going to wait for the 2nd run: " + timeTillRun);
assertEquals((Integer) 2, fut.get(timeTillRun, SECONDS));
assertEquals((Integer) 2, fut.last());
assert fut.isDone();
assert !fut.isCancelled();
} finally {
assert fut != null;
fut.cancel();
}
}
Aggregations