Search in sources :

Example 26 with ICountDownLatch

use of com.hazelcast.cp.ICountDownLatch 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 27 with ICountDownLatch

use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.

the class ScheduledExecutorServiceSlowTest method scheduleRandomPartitions_periodicTask_getAllScheduled_durable.

@Test
public void scheduleRandomPartitions_periodicTask_getAllScheduled_durable() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(3);
    IScheduledExecutorService s = getScheduledExecutor(instances, "s");
    String key = generateKeyOwnedBy(instances[1]);
    String runsCounterName = "runs";
    ICountDownLatch runsLatch = instances[0].getCPSubsystem().getCountDownLatch(runsCounterName);
    runsLatch.trySetCount(2);
    int expectedTotal = 11;
    for (int i = 0; i < expectedTotal; i++) {
        s.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask(runsCounterName), key, 0, 2, SECONDS);
    }
    runsLatch.await(10, SECONDS);
    instances[1].getLifecycleService().shutdown();
    assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
}
Also used : 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 28 with ICountDownLatch

use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.

the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_killMember_thenGetAllScheduled.

@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_killMember_thenGetAllScheduled() throws Exception {
    String runsCounterName = "runs";
    HazelcastInstance[] instances = createClusterWithCount(10);
    ICountDownLatch runsLatch = instances[0].getCPSubsystem().getCountDownLatch(runsCounterName);
    int numOfSchedulers = 20;
    int numOfTasks = 10;
    int expectedTotal = numOfSchedulers * numOfTasks;
    runsLatch.trySetCount(expectedTotal);
    for (int i = 0; i < numOfSchedulers; i++) {
        IScheduledExecutorService s = getScheduledExecutor(instances, "scheduler_" + i);
        String key = generateKeyOwnedBy(instances[i % instances.length]);
        for (int k = 0; k < numOfTasks; k++) {
            s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask(runsCounterName), key, 0, SECONDS);
        }
    }
    runsLatch.await(10, SECONDS);
    instances[1].getLifecycleService().terminate();
    int actualTotal = 0;
    for (int i = 0; i < numOfSchedulers; i++) {
        actualTotal += countScheduledTasksOn(getScheduledExecutor(instances, "scheduler_" + i));
    }
    assertEquals(expectedTotal, actualTotal, 0);
}
Also used : 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 29 with ICountDownLatch

use of com.hazelcast.cp.ICountDownLatch 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 30 with ICountDownLatch

use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.

the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_shutdownOrDestroy_thenGetAllScheduled.

@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_shutdownOrDestroy_thenGetAllScheduled() throws Exception {
    String runsCounterName = "runs";
    HazelcastInstance[] instances = createClusterWithCount(3);
    ICountDownLatch runsLatch = instances[0].getCPSubsystem().getCountDownLatch(runsCounterName);
    int numOfSchedulers = 10;
    int numOfTasks = 10;
    int expectedTotal = numOfSchedulers * numOfTasks;
    runsLatch.trySetCount(expectedTotal);
    for (int i = 0; i < numOfSchedulers; i++) {
        IScheduledExecutorService s = getScheduledExecutor(instances, "scheduler_" + i);
        String key = generateKeyOwnedBy(instances[1]);
        for (int k = 0; k < numOfTasks; k++) {
            s.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask(runsCounterName), key, 0, 2, SECONDS);
        }
    }
    runsLatch.await(10, SECONDS);
    getScheduledExecutor(instances, "scheduler_" + 0).shutdown();
    getScheduledExecutor(instances, "scheduler_" + 1).shutdown();
    getScheduledExecutor(instances, "scheduler_" + 3).destroy();
    int actualTotal = 0;
    for (int i = 0; i < numOfSchedulers; i++) {
        actualTotal += countScheduledTasksOn(getScheduledExecutor(instances, "scheduler_" + i));
    }
    assertEquals(expectedTotal - 3 * numOfTasks, actualTotal, 0);
}
Also used : 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

ICountDownLatch (com.hazelcast.cp.ICountDownLatch)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)31 Test (org.junit.Test)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)30 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)27 QuickTest (com.hazelcast.test.annotation.QuickTest)21 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)14 SlowTest (com.hazelcast.test.annotation.SlowTest)11 IAtomicLong (com.hazelcast.cp.IAtomicLong)3 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)3 Member (com.hazelcast.cluster.Member)2 RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)2 ScheduledTaskStatistics (com.hazelcast.scheduledexecutor.ScheduledTaskStatistics)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 Address (com.hazelcast.cluster.Address)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 CPSubsystem (com.hazelcast.cp.CPSubsystem)1 CountDownLatchService (com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService)1