use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_thenDisposeThenGet_onMember.
@Test(expected = StaleTaskException.class)
public void schedule_thenDisposeThenGet_onMember() throws Exception {
int delay = 1;
String taskName = "Test";
HazelcastInstance[] instances = createClusterWithCount(2);
Member localMember = instances[0].getCluster().getLocalMember();
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> first = executorService.scheduleOnMember(named(taskName, new PlainCallableTask()), localMember, delay, SECONDS);
first.dispose();
first.get();
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService 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.scheduledexecutor.IScheduledExecutorService 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.scheduledexecutor.IScheduledExecutorService 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.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleAndGet_withCallable.
@Test
public void scheduleAndGet_withCallable() throws Exception {
int delay = 5;
double expectedResult = 25.0;
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
double result = future.get();
assertEquals(expectedResult, result, 0);
assertTrue(future.isDone());
assertFalse(future.isCancelled());
}
Aggregations