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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations