Search in sources :

Example 6 with GridTuple

use of org.apache.ignite.internal.util.lang.GridTuple in project ignite by apache.

the class GridScheduleSelfTest method testRunnableCancel.

/**
 * @throws Exception If failed.
 */
public void testRunnableCancel() throws Exception {
    SchedulerFuture fut = null;
    final GridTuple<Integer> tpl = new GridTuple<>(0);
    try {
        fut = grid(0).scheduler().scheduleLocal(new Runnable() {

            @Override
            public void run() {
                tpl.set(tpl.get() + 1);
            }
        }, "{1, *} * * * * *");
        assertEquals(Integer.valueOf(0), tpl.get());
        fut.cancel();
        assert fut.isCancelled();
        assert fut.isDone();
        assertEquals(Integer.valueOf(0), tpl.get());
        try {
            fut.get();
            fail("IgniteException must have been thrown");
        } catch (IgniteException e) {
            info("Caught expected exception: " + e);
        }
        try {
            fut.get(500, SECONDS);
            fail("IgniteException must have been thrown");
        } catch (IgniteException e) {
            info("Caught expected exception: " + e);
        }
    } finally {
        assert fut != null;
        if (!fut.isCancelled())
            fut.cancel();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) SchedulerFuture(org.apache.ignite.scheduler.SchedulerFuture) GridTuple(org.apache.ignite.internal.util.lang.GridTuple)

Aggregations

GridTuple (org.apache.ignite.internal.util.lang.GridTuple)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CacheException (javax.cache.CacheException)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1 Ignite (org.apache.ignite.Ignite)1 IgniteTransactions (org.apache.ignite.IgniteTransactions)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)1