Search in sources :

Example 26 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class DelegatingScheduledFutureStripperTest method cancel.

@Test
public void cancel() throws ExecutionException, InterruptedException {
    ScheduledFuture outter = mock(ScheduledFuture.class);
    ScheduledFuture inner = mock(ScheduledFuture.class);
    when(outter.get()).thenReturn(inner);
    new DelegatingScheduledFutureStripper(outter).cancel(true);
    verify(inner).cancel(eq(true));
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class DelegatingScheduledFutureStripperTest method cancel_twice.

@Test
public void cancel_twice() throws ExecutionException, InterruptedException, TimeoutException {
    ScheduledFuture original = taskScheduler.schedule(new SimpleCallableTestTask(), 10, TimeUnit.SECONDS);
    ScheduledFuture stripper = new DelegatingScheduledFutureStripper(original);
    stripper.cancel(true);
    stripper.cancel(true);
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project jdk8u_jdk by JetBrains.

the class LdapTimeoutTest method call.

public Boolean call() {
    InitialContext ctx = null;
    ScheduledFuture killer = null;
    long start = System.nanoTime();
    try {
        while (!server.accepting()) // allow the server to start up
        Thread.sleep(200);
        // to be sure
        Thread.sleep(200);
        // interrupt after a certain time
        if (killSwitchPool != null) {
            final Thread current = Thread.currentThread();
            killer = killSwitchPool.schedule(new Callable<Void>() {

                public Void call() throws Exception {
                    current.interrupt();
                    return null;
                }
            }, HANGING_TEST_TIMEOUT, MILLISECONDS);
        }
        env.put(Context.PROVIDER_URL, "ldap://localhost:" + server.getLocalPort());
        try {
            ctx = new InitialDirContext(env);
            performOp(ctx);
            fail();
        } catch (NamingException e) {
            long end = System.nanoTime();
            System.out.println(this.getClass().toString() + " - elapsed: " + NANOSECONDS.toMillis(end - start));
            handleNamingException(e, start, end);
        } finally {
            if (killer != null && !killer.isDone())
                killer.cancel(true);
            shutItDown(ctx);
            server.close();
        }
        return passed;
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) Callable(java.util.concurrent.Callable)

Example 29 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class QueueManagerImpl method scheduleRedundancySatisfierIfNeeded.

protected void scheduleRedundancySatisfierIfNeeded(long delay) {
    if (shuttingDown) {
        return;
    }
    synchronized (lock) {
        if (shuttingDown) {
            return;
        }
        if (queueConnections.getPrimary() == null || getCurrentRedundancy() < redundancyLevel || redundancyLevel == -1 || queueConnections.primaryDiscoveryFailed()) {
            if (redundancySatisfierTask != null) {
                if (redundancySatisfierTask.getRemainingDelay() > delay) {
                    redundancySatisfierTask.cancel();
                } else {
                    return;
                }
            }
            redundancySatisfierTask = new RedundancySatisfierTask();
            try {
                ScheduledFuture future = recoveryThread.schedule(redundancySatisfierTask, delay, TimeUnit.MILLISECONDS);
                redundancySatisfierTask.setFuture(future);
            } catch (RejectedExecutionException e) {
            // ignore, the timer has been cancelled, which means we're shutting down.
            }
        }
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 30 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class ScheduledThreadPoolExecutorWithKeepAlive method schedule.

private ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit, Object result) {
    DelegatingScheduledFuture future = new DelegatingScheduledFuture(command, result);
    ScheduledFuture timerFuture = timer.schedule(new HandOffTask(future), delay, unit);
    future.setDelegate(timerFuture);
    return future;
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Aggregations

ScheduledFuture (java.util.concurrent.ScheduledFuture)83 Test (org.junit.Test)27 DelegatingScheduledFutureStripper (com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Date (java.util.Date)9 IOException (java.io.IOException)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 Map (java.util.Map)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 None (com.linkedin.common.util.None)5 D2Client (com.linkedin.d2.balancer.D2Client)5 D2ClientBuilder (com.linkedin.d2.balancer.D2ClientBuilder)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 JSONObject (org.json.simple.JSONObject)5 IdleReaderException (com.twitter.distributedlog.exceptions.IdleReaderException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Future (java.util.concurrent.Future)4