Search in sources :

Example 1 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method scheduleRandomPartitions_getAllScheduled_durable.

@Test
public void scheduleRandomPartitions_getAllScheduled_durable() throws Exception {
    ScheduledExecutorConfig scheduledExecutorConfig = new ScheduledExecutorConfig().setName("s").setDurability(2);
    Config config = new Config().setProperty("hazelcast.partition.count", "10").addScheduledExecutorConfig(scheduledExecutorConfig);
    HazelcastInstance[] instances = createClusterWithCount(4, config);
    IScheduledExecutorService s = getScheduledExecutor(instances, "s");
    int expectedTotal = 11;
    IScheduledFuture[] futures = new IScheduledFuture[expectedTotal];
    for (int i = 0; i < expectedTotal; i++) {
        futures[i] = s.schedule(new PlainCallableTask(i), 0, SECONDS);
    }
    instances[1].shutdown();
    assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
    // verify all tasks
    for (int i = 0; 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) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method stats_longRunningTask_durable.

@Test
public void stats_longRunningTask_durable() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(4);
    String key = generateKeyOwnedBy(instances[1]);
    ICountDownLatch firstLatch = instances[0].getCPSubsystem().getCountDownLatch("firstLatch");
    firstLatch.trySetCount(2);
    ICountDownLatch lastLatch = instances[0].getCPSubsystem().getCountDownLatch("lastLatch");
    lastLatch.trySetCount(6);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("firstLatch", "lastLatch"), key, 0, 10, SECONDS);
    firstLatch.await(12, SECONDS);
    instances[1].getLifecycleService().shutdown();
    lastLatch.await(70, SECONDS);
    // wait for run-cycle to finish before cancelling, in order for stats to get updated
    sleepSeconds(4);
    future.cancel(false);
    ScheduledTaskStatistics stats = future.getStats();
    assertEquals(6, stats.getTotalRuns(), 1);
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskStatistics(com.hazelcast.scheduledexecutor.ScheduledTaskStatistics) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method reschedulingAfterMigration_whenCurrentNodePreviouslyOwnedTask.

@Test
public void reschedulingAfterMigration_whenCurrentNodePreviouslyOwnedTask() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    Config config = new Config();
    config.addScheduledExecutorConfig(new ScheduledExecutorConfig("scheduler").setCapacity(1000));
    HazelcastInstance first = factory.newHazelcastInstance(config);
    int tasksCount = 1000;
    final IScheduledExecutorService scheduler = first.getScheduledExecutorService("scheduler");
    for (int i = 1; i <= tasksCount; i++) {
        scheduler.scheduleAtFixedRate(named(valueOf(i), new EchoTask()), 5, 10, SECONDS);
    }
    assertTrueEventually(new AllTasksRunningWithinNumOfNodes(scheduler, 1));
    // start a second member
    HazelcastInstance second = factory.newHazelcastInstance();
    waitAllForSafeState(first, second);
    assertTrueEventually(new AllTasksRunningWithinNumOfNodes(scheduler, 2));
    // kill the second member, tasks should now get rescheduled back in first member
    second.getLifecycleService().terminate();
    waitAllForSafeState(first);
    assertTrueEventually(new AllTasksRunningWithinNumOfNodes(scheduler, 1));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method schedule_withStatefulRunnable_durable.

@Test
public void schedule_withStatefulRunnable_durable() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(4);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    int waitStateSyncPeriodToAvoidPassiveState = 2000;
    String key = generateKeyOwnedBy(instances[1]);
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
    IAtomicLong runC = instances[0].getCPSubsystem().getAtomicLong("runC");
    IAtomicLong loadC = instances[0].getCPSubsystem().getAtomicLong("loadC");
    latch.trySetCount(1);
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new StatefulRunnableTask("latch", "runC", "loadC"), key, 10, 10, SECONDS);
    // wait for task to get scheduled and start
    latch.await(11, SECONDS);
    Thread.sleep(waitStateSyncPeriodToAvoidPassiveState);
    instances[1].getLifecycleService().shutdown();
    // reset latch - task should be running on a replica now
    latch.trySetCount(7);
    latch.await(70, SECONDS);
    future.cancel(false);
    assertEquals(getPartitionService(instances[0]).getPartitionId(key), future.getHandler().getPartitionId());
    assertEquals(8, runC.get(), 1);
    assertEquals(1, loadC.get());
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) 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) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 5 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_whenAutoDisposable_thenGet.

@Test
public void scheduleOnKeyOwner_whenAutoDisposable_thenGet() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(autoDisposable(new PlainCallableTask()), key, 1, SECONDS);
    assertTaskHasBeenDestroyedEventually(future);
}
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