use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withMapChanges_durable.
@Test
public void schedule_withMapChanges_durable() {
HazelcastInstance[] instances = createClusterWithCount(2);
IMap<String, Integer> map = instances[1].getMap("map");
map.put("foo", 1);
Object key = generateKeyOwnedBy(instances[0]);
ICountDownLatch startedLatch = instances[1].getCPSubsystem().getCountDownLatch("startedLatch");
ICountDownLatch finishedLatch = instances[1].getCPSubsystem().getCountDownLatch("finishedLatch");
ICountDownLatch waitAfterStartLatch = instances[1].getCPSubsystem().getCountDownLatch("waitAfterStartLatch");
startedLatch.trySetCount(1);
finishedLatch.trySetCount(1);
waitAfterStartLatch.trySetCount(1);
IAtomicLong runEntryCounter = instances[1].getCPSubsystem().getAtomicLong("runEntryCounterName");
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
executorService.scheduleOnKeyOwner(new ICountdownLatchMapIncrementCallableTask("map", "runEntryCounterName", "startedLatch", "finishedLatch", "waitAfterStartLatch"), key, 0, SECONDS);
assertOpenEventually(startedLatch);
instances[0].getLifecycleService().shutdown();
waitAfterStartLatch.countDown();
assertOpenEventually(finishedLatch);
assertEquals(2, (int) map.get("foo"));
assertEquals(2, runEntryCounter.get());
}
use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwnerWithRepetition.
@Test
public void scheduleOnKeyOwnerWithRepetition() {
String key = "TestKey";
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(5);
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 1, SECONDS);
ScheduledTaskHandler handler = future.getHandler();
int expectedPartition = instances[0].getPartitionService().getPartition(key).getPartitionId();
assertEquals(expectedPartition, handler.getPartitionId());
assertOpenEventually(latch);
assertEquals(0, latch.getCount());
}
use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleWithRepetition.
@Test
public void scheduleWithRepetition() {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(3);
IScheduledFuture future = s.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 1, SECONDS);
assertOpenEventually(latch);
future.cancel(false);
assertEquals(0, latch.getCount());
}
use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withLongSleepingCallable_cancelledAndGet.
@Test
public void schedule_withLongSleepingCallable_cancelledAndGet() {
int delay = 0;
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch initCountLatch = instances[0].getCPSubsystem().getCountDownLatch("initCountLatchName");
initCountLatch.trySetCount(1);
ICountDownLatch waitCountLatch = instances[0].getCPSubsystem().getCountDownLatch("waitCountLatchName");
waitCountLatch.trySetCount(1);
ICountDownLatch doneCountLatch = instances[0].getCPSubsystem().getCountDownLatch("doneCountLatchName");
doneCountLatch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> future = executorService.schedule(new ICountdownLatchCallableTask(initCountLatch.getName(), waitCountLatch.getName(), doneCountLatch.getName()), delay, SECONDS);
assertOpenEventually(initCountLatch);
assertTrue(future.cancel(false));
waitCountLatch.countDown();
assertOpenEventually(doneCountLatch);
assertTrue(future.isDone());
assertTrue(future.isCancelled());
}
use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withNamedInstanceAware_whenLocalRun.
@Test
public void schedule_withNamedInstanceAware_whenLocalRun() {
HazelcastInstance[] instances = createClusterWithCount(1);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
s.schedule(TaskUtils.named("blah", new PlainInstanceAwareRunnableTask("latch")), 1, TimeUnit.SECONDS);
assertOpenEventually(latch);
assertEquals(0, latch.getCount());
}
Aggregations