Search in sources :

Example 66 with IgniteFuture

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();
}
Also used : ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 67 with IgniteFuture

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();
    }
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite)

Example 68 with IgniteFuture

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();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable)

Example 69 with IgniteFuture

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;
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) CI1(org.apache.ignite.internal.util.typedef.CI1) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with IgniteFuture

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);
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) CI1(org.apache.ignite.internal.util.typedef.CI1) Semaphore(java.util.concurrent.Semaphore) Nullable(org.jetbrains.annotations.Nullable) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Aggregations

IgniteFuture (org.apache.ignite.lang.IgniteFuture)76 Ignite (org.apache.ignite.Ignite)36 ArrayList (java.util.ArrayList)28 IgniteException (org.apache.ignite.IgniteException)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 CountDownLatch (java.util.concurrent.CountDownLatch)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 CacheException (javax.cache.CacheException)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteCompute (org.apache.ignite.IgniteCompute)9 CI1 (org.apache.ignite.internal.util.typedef.CI1)9 List (java.util.List)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 UUID (java.util.UUID)6 Collection (java.util.Collection)5 IgniteInClosure (org.apache.ignite.lang.IgniteInClosure)5 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4