use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_andCancel_onMember.
@Test
public void schedule_andCancel_onMember() {
HazelcastInstance[] instances = createClusterWithCount(2);
Member localMember = instances[0].getCluster().getLocalMember();
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture future = executorService.scheduleOnMemberAtFixedRate(new ICountdownLatchRunnableTask("latch"), localMember, 1, 1, SECONDS);
sleepSeconds(5);
assertFalse(future.isCancelled());
assertFalse(future.isDone());
future.cancel(false);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_whenAutoDisposable_thenGet.
@Test
public void schedule_whenAutoDisposable_thenGet() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> future = executorService.schedule(autoDisposable(new PlainCallableTask()), 1, SECONDS);
assertTaskHasBeenDestroyedEventually(future);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_testPartitionLostEvent.
public void schedule_testPartitionLostEvent(int replicaLostCount) {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
final IScheduledFuture future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
// Used to make sure both futures (on the same handler) get the event.
// Catching possible equal/hashcode issues in the Map
final IScheduledFuture futureCopyInstance = (IScheduledFuture) ((List) executorService.getAllScheduledFutures().values().toArray()[0]).get(0);
ScheduledTaskHandler handler = future.getHandler();
int partitionOwner = handler.getPartitionId();
IPartitionLostEvent internalEvent = new PartitionLostEventImpl(partitionOwner, replicaLostCount, null);
((InternalPartitionServiceImpl) getNodeEngineImpl(instances[0]).getPartitionService()).onPartitionLost(internalEvent);
assertTrueEventually(() -> {
try {
future.get();
fail();
} catch (IllegalStateException ex) {
try {
futureCopyInstance.get();
fail();
} catch (IllegalStateException ex2) {
assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex.getMessage());
assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex2.getMessage());
}
}
});
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withNamedInstanceAware_whenRemoteRun.
@Test
public void schedule_withNamedInstanceAware_whenRemoteRun() {
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
MemberImpl member = getNodeEngineImpl(instances[1]).getLocalMember();
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
s.scheduleOnMember(TaskUtils.named("blah", new PlainInstanceAwareRunnableTask("latch")), member, 1, TimeUnit.SECONDS);
assertOpenEventually(latch);
assertEquals(0, latch.getCount());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class AbstractScheduledExecutorNullTest method assertThrowsNPE.
private void assertThrowsNPE(ConsumerEx<IScheduledExecutorService> method) {
IScheduledExecutorService executorService = getDriver().getScheduledExecutorService(randomName());
assertThrows(NullPointerException.class, () -> method.accept(executorService));
}
Aggregations