Search in sources :

Example 11 with IScheduledExecutorService

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with IScheduledExecutorService

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());
}
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 13 with IScheduledExecutorService

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());
}
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 14 with IScheduledExecutorService

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());
}
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 15 with IScheduledExecutorService

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)94 HazelcastInstance (com.hazelcast.core.HazelcastInstance)83 Test (org.junit.Test)83 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)81 QuickTest (com.hazelcast.test.annotation.QuickTest)70 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)38 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)29 Config (com.hazelcast.config.Config)21 ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)21 Member (com.hazelcast.cluster.Member)18 SlowTest (com.hazelcast.test.annotation.SlowTest)15 ArrayList (java.util.ArrayList)11 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)10 HashMap (java.util.HashMap)6 List (java.util.List)6 RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)4 ScheduledTaskStatistics (com.hazelcast.scheduledexecutor.ScheduledTaskStatistics)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 Address (com.hazelcast.cluster.Address)2 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2