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);
for (int i = 0; i < CacheConfiguration.DFLT_WRITE_BEHIND_FLUSH_SIZE * 2; i++) {
cache.put(i, i);
}
Collection<IgniteFuture<?>> futs = new ArrayList<>();
for (int i = 0; i < 1000; i++) futs.add(updateKey(cache));
for (IgniteFuture<?> fut : futs) fut.get();
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class DataStreamProcessorSelfTest method checkDataStreamer.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("ErrorNotRethrown")
private void checkDataStreamer() throws Exception {
try {
useCache = true;
Ignite igniteWithCache = startGrid(2);
startGrid(3);
useCache = false;
Ignite igniteWithoutCache = startGrid(1);
final IgniteDataStreamer<Integer, Integer> ldr = igniteWithoutCache.dataStreamer(DEFAULT_CACHE_NAME);
ldr.receiver(DataStreamerCacheUpdaters.<Integer, Integer>batchedSorted());
final AtomicInteger idxGen = new AtomicInteger();
final int cnt = 400;
final int threads = 10;
final CountDownLatch l1 = new CountDownLatch(threads);
IgniteInternalFuture<?> f1 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Collection<IgniteFuture<?>> futs = new ArrayList<>(cnt);
for (int i = 0; i < cnt; i++) {
int idx = idxGen.getAndIncrement();
futs.add(ldr.addData(idx, idx));
}
l1.countDown();
for (IgniteFuture<?> fut : futs) fut.get();
return null;
}
}, threads);
l1.await();
// This will wait until data streamer finishes loading.
stopGrid(getTestIgniteInstanceName(1), false);
f1.get();
int s2 = grid(2).cache(DEFAULT_CACHE_NAME).localSize(CachePeekMode.PRIMARY);
int s3 = grid(3).cache(DEFAULT_CACHE_NAME).localSize(CachePeekMode.PRIMARY);
int total = threads * cnt;
assertEquals(total, s2 + s3);
final IgniteDataStreamer<Integer, Integer> rmvLdr = igniteWithCache.dataStreamer(DEFAULT_CACHE_NAME);
rmvLdr.receiver(DataStreamerCacheUpdaters.<Integer, Integer>batchedSorted());
final CountDownLatch l2 = new CountDownLatch(threads);
IgniteInternalFuture<?> f2 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Collection<IgniteFuture<?>> futs = new ArrayList<>(cnt);
for (int i = 0; i < cnt; i++) {
final int key = idxGen.decrementAndGet();
futs.add(rmvLdr.removeData(key));
}
l2.countDown();
for (IgniteFuture<?> fut : futs) fut.get();
return null;
}
}, threads);
l2.await();
rmvLdr.close(false);
f2.get();
s2 = grid(2).cache(DEFAULT_CACHE_NAME).localSize(CachePeekMode.PRIMARY);
s3 = grid(3).cache(DEFAULT_CACHE_NAME).localSize(CachePeekMode.PRIMARY);
assert s2 == 0 && s3 == 0 : "Incorrect entries count [s2=" + s2 + ", s3=" + s3 + ']';
} finally {
stopAllGrids();
}
}
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();
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridJobExecutionLoadTestClientSemaphore method call.
/**
* {@inheritDoc}
*/
@SuppressWarnings("InfiniteLoopStatement")
@Nullable
@Override
public Object call() throws Exception {
final IgniteInClosure<IgniteFuture<?>> lsnr = new CI1<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> t) {
tasksSem.release();
}
};
ClusterGroup rmts = g.cluster().forRemotes();
while (!finish) {
tasksSem.acquire();
g.compute(rmts).executeAsync(GridJobExecutionLoadTestTask.class, null).listen(lsnr);
txCnt.increment();
}
return null;
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridJobExecutionSingleNodeSemaphoreLoadTest method runTest.
/**
* Runs the actual load test.
*
* @param g Grid.
* @param threadCnt Number of threads.
* @param taskCnt Number of tasks.
* @param dur Test duration.
* @param iterCntr Iteration counter.
*/
private static void runTest(final Ignite g, int threadCnt, int taskCnt, long dur, final LongAdder iterCntr) {
final Semaphore sem = new Semaphore(taskCnt);
final IgniteInClosure<IgniteFuture> lsnr = new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture t) {
sem.release();
}
};
GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
sem.acquire();
g.compute().executeAsync(GridJobExecutionLoadTestTask.class, null).listen(lsnr);
iterCntr.increment();
return null;
}
}, threadCnt, dur > 0 ? dur : Long.MAX_VALUE);
}
Aggregations