Search in sources :

Example 1 with SchedulerFuture

use of org.apache.ignite.scheduler.SchedulerFuture 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

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteException (org.apache.ignite.IgniteException)1 GridTuple (org.apache.ignite.internal.util.lang.GridTuple)1 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)1 SchedulerFuture (org.apache.ignite.scheduler.SchedulerFuture)1