Search in sources :

Example 46 with IScheduledFuture

use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.

the class ScheduledExecutorServiceSlowTest method cancelUninterruptedTask_waitUntilRunCompleted_checkStatusIsCancelled.

@Test
public void cancelUninterruptedTask_waitUntilRunCompleted_checkStatusIsCancelled() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(1);
    String runFinishedLatchName = "runFinishedLatch";
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch(runFinishedLatchName);
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleAtFixedRate(new HotLoopBusyTask(runFinishedLatchName), 0, 1, SECONDS);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
    // wait till the task is actually done, since even though we cancelled the task is current task is still running
    latch.await(60, SECONDS);
    // make sure SyncState goes through
    sleepSeconds(10);
    // check once more that the task status is consistent
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 47 with IScheduledFuture

use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.

the class ScheduledExecutorServiceSlowTest method stats_manyRepetitionsTask.

@Test
public void stats_manyRepetitionsTask() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(4);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    latch.trySetCount(6);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 10, SECONDS);
    latch.await(120, SECONDS);
    future.cancel(false);
    ScheduledTaskStatistics stats = future.getStats();
    assertEquals(6, stats.getTotalRuns(), 1);
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskStatistics(com.hazelcast.scheduledexecutor.ScheduledTaskStatistics) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 48 with IScheduledFuture

use of com.hazelcast.scheduledexecutor.IScheduledFuture in project hazelcast by hazelcast.

the class ScheduledExecutorServiceSlowTest method cancelUninterruptedTask_waitUntilRunCompleted_killMember_checkStatusIsCancelled.

@Test
public void cancelUninterruptedTask_waitUntilRunCompleted_killMember_checkStatusIsCancelled() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    String runFinishedLatchName = "runFinishedLatch";
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch(runFinishedLatchName);
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new HotLoopBusyTask(runFinishedLatchName), key, 0, 1, SECONDS);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
    // wait till the task is actually done, since even though we cancelled the task is current task is still running
    latch.await(60, SECONDS);
    // make sure SyncState goes through
    sleepSeconds(10);
    instances[1].getLifecycleService().terminate();
    // check once more that the task status is consistent
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)48 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)35 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)34 Test (org.junit.Test)34 QuickTest (com.hazelcast.test.annotation.QuickTest)27 Config (com.hazelcast.config.Config)16 ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)16 Member (com.hazelcast.cluster.Member)14 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)14 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)10 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 Member (com.hazelcast.core.Member)5 TaskDefinition (com.hazelcast.scheduledexecutor.impl.TaskDefinition)5 List (java.util.List)5 Map (java.util.Map)5 Nonnull (javax.annotation.Nonnull)4 LinkedList (java.util.LinkedList)3