Search in sources :

Example 16 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method schedule_andCancel.

@Test
public void schedule_andCancel() {
    HazelcastInstance[] instances = createClusterWithCount(2);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture future = executorService.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 1, 1, SECONDS);
    sleepSeconds(5);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method handlerTaskAndSchedulerNames_withRunnable.

@Test
public void handlerTaskAndSchedulerNames_withRunnable() {
    int delay = 0;
    String schedulerName = ANY_EXECUTOR_NAME;
    String taskName = "TestRunnable";
    HazelcastInstance[] instances = createClusterWithCount(2);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledExecutorService executorService = instances[0].getScheduledExecutorService(schedulerName);
    IScheduledFuture future = executorService.schedule(named(taskName, new ICountdownLatchRunnableTask("latch")), delay, SECONDS);
    assertOpenEventually(latch);
    ScheduledTaskHandler handler = future.getHandler();
    assertEquals(schedulerName, handler.getSchedulerName());
    assertEquals(taskName, handler.getTaskName());
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method cancelledAndDone_durable.

@Test
public void cancelledAndDone_durable() {
    HazelcastInstance[] instances = createClusterWithCount(3);
    Object key = generateKeyOwnedBy(instances[1]);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 1, SECONDS);
    assertOpenEventually(latch);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
    instances[1].getLifecycleService().shutdown();
    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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withNotPeriodicRunnable.

@Test
public void scheduleOnKeyOwner_withNotPeriodicRunnable() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[0]);
    IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    latch.trySetCount(1);
    s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask("latch"), key, 2, SECONDS).get();
    assertEquals(0, latch.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withNotPeriodicRunnableDurable.

@Test
public void scheduleOnKeyOwner_withNotPeriodicRunnableDurable() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[0].getCPSubsystem().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 : 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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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