Search in sources :

Example 26 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_shutdownOrDestroy_thenGetAllScheduled.

@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_shutdownOrDestroy_thenGetAllScheduled() throws ExecutionException, InterruptedException {
    String runsCounterName = "runs";
    HazelcastInstance[] instances = createClusterWithCount(3);
    ICountDownLatch runsLatch = instances[0].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 * /*numOfShutdownOrDestroy*/
    numOfTasks, actualTotal, 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_killMember_thenGetAllScheduled.

@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_killMember_thenGetAllScheduled() throws ExecutionException, InterruptedException {
    String runsCounterName = "runs";
    HazelcastInstance[] instances = createClusterWithCount(10);
    ICountDownLatch runsLatch = instances[0].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) ICountDownLatch(com.hazelcast.core.ICountDownLatch) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method cancelUninterruptedTask_waitUntilRunCompleted_checkStatusIsCancelled.

@Test
public void cancelUninterruptedTask_waitUntilRunCompleted_checkStatusIsCancelled() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(1);
    String runFinishedLatchName = "runFinishedLatch";
    ICountDownLatch latch = instances[0].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());
    // Even though we cancelled the task is current task is still running.
    // Wait till the task is actually done
    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 : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withNotPeriodicRunableDurable.

@Test
public void scheduleOnKeyOwner_withNotPeriodicRunableDurable() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService s = getScheduledExecutor(instances, "s");
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledFuture future = s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask("latch"), key, 2, SECONDS);
    instances[1].getLifecycleService().shutdown();
    future.get();
    assertEquals(0, latch.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method schedule_withLongSleepingCallable_cancelledAndGet.

@Test
public void schedule_withLongSleepingCallable_cancelledAndGet() throws ExecutionException, InterruptedException {
    int delay = 0;
    HazelcastInstance[] instances = createClusterWithCount(2);
    ICountDownLatch runsCountLatch = instances[0].getCountDownLatch("runsCountLatchName");
    runsCountLatch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture<Double> future = executorService.schedule(new ICountdownLatchCallableTask("runsCountLatchName", 15000), delay, SECONDS);
    Thread.sleep(4000);
    future.cancel(false);
    runsCountLatch.await(15, SECONDS);
    assertEquals(true, future.isDone());
    assertEquals(true, future.isCancelled());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ICountDownLatch (com.hazelcast.core.ICountDownLatch)37 ParallelTest (com.hazelcast.test.annotation.ParallelTest)37 Test (org.junit.Test)37 HazelcastInstance (com.hazelcast.core.HazelcastInstance)35 QuickTest (com.hazelcast.test.annotation.QuickTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 TestThread (com.hazelcast.test.TestThread)3 IAtomicLong (com.hazelcast.core.IAtomicLong)2 RootCauseMatcher (com.hazelcast.util.RootCauseMatcher)2 CountDownLatchService (com.hazelcast.concurrent.countdownlatch.CountDownLatchService)1 Config (com.hazelcast.config.Config)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 Member (com.hazelcast.core.Member)1 DistributedObjectDestroyedException (com.hazelcast.spi.exception.DistributedObjectDestroyedException)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1