Search in sources :

Example 6 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method stats_longRunningTask_durable.

@Test
public void stats_longRunningTask_durable() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(4);
    String key = generateKeyOwnedBy(instances[1]);
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(6);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 10, SECONDS);
    Thread.sleep(12000);
    instances[1].getLifecycleService().shutdown();
    latch.await(70, SECONDS);
    // Wait for run-cycle to finish before cancelling, in order for stats to get updated.
    sleepSeconds(4);
    future.cancel(false);
    ScheduledTaskStatistics stats = future.getStats();
    assertEquals(6, stats.getTotalRuns());
}
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 7 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method schedule_withLongSleepingCallable_blockingOnGet.

@Test
public void schedule_withLongSleepingCallable_blockingOnGet() throws ExecutionException, InterruptedException {
    int delay = 0;
    double expectedResult = 169.4;
    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);
    double result = future.get();
    assertEquals(expectedResult, result, 0);
    assertEquals(true, future.isDone());
    assertEquals(false, future.isCancelled());
}
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 8 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_thenGetAllScheduled.

@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_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);
    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 9 with ICountDownLatch

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

the class ScheduledExecutorServiceSlowTest method stats_manyRepetitionsTask.

@Test
public void stats_manyRepetitionsTask() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(4);
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(6);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 10, SECONDS);
    latch.await(120, SECONDS);
    // Wait for run-cycle to finish before cancelling, in order for stats to get updated.
    sleepSeconds(4);
    future.cancel(false);
    ScheduledTaskStatistics stats = future.getStats();
    assertEquals(6, stats.getTotalRuns());
}
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 10 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method schedule_andCancel_onMember.

@Test()
public void schedule_andCancel_onMember() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(2);
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleOnMemberAtFixedRate(new ICountdownLatchRunnableTask("latch"), instances[0].getCluster().getLocalMember(), 1, 1, SECONDS);
    Thread.sleep(5000);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
}
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