Search in sources :

Example 6 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method schedule_withStatefulRunnable.

@Test
public void schedule_withStatefulRunnable() {
    HazelcastInstance[] instances = createClusterWithCount(4);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    latch.trySetCount(1);
    executorService.schedule(new StatefulRunnableTask("latch", "runC", "loadC"), 2, SECONDS);
    assertOpenEventually(latch);
}
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 7 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method scheduleRandomPartitions_getAllScheduled.

@Test
public void scheduleRandomPartitions_getAllScheduled() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    int expectedTotal = 11;
    IScheduledFuture[] futures = new IScheduledFuture[expectedTotal];
    for (int i = 0; i < expectedTotal; i++) {
        futures[i] = s.schedule(new PlainCallableTask(i), 0, SECONDS);
    }
    assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
    // dispose 1 task
    futures[0].dispose();
    // recount
    assertEquals(expectedTotal - 1, countScheduledTasksOn(s), 0);
    // verify all tasks
    for (int i = 1; i < expectedTotal; i++) {
        assertEquals(25.0 + i, futures[i].get());
    }
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) 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)

Example 8 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_getDelay.

@Test
public void scheduleOnKeyOwner_getDelay() {
    int delay = 20;
    String taskName = "Test";
    HazelcastInstance[] instances = createClusterWithCount(2);
    Object key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture<Double> first = executorService.scheduleOnKeyOwner(named(taskName, new PlainCallableTask()), key, delay, MINUTES);
    assertEquals(19, first.getDelay(MINUTES));
}
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)

Example 9 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method schedule_getDelay.

@Test
public void schedule_getDelay() {
    int delay = 20;
    String taskName = "Test";
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture<Double> first = executorService.schedule(named(taskName, new PlainCallableTask()), delay, MINUTES);
    assertEquals(19, first.getDelay(MINUTES));
}
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)

Example 10 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService 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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) IAtomicLong(com.hazelcast.cp.IAtomicLong) 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