Search in sources :

Example 11 with IScheduledFuture

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

the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit.

@Test
public void capacity_whenPositiveLimit() {
    String schedulerName = ANY_EXECUTOR_NAME;
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(10).setCapacityPolicy(ScheduledExecutorConfig.CapacityPolicy.PER_PARTITION);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    String key = "hitSamePartitionToCheckCapacity";
    int keyOwner = getNodeEngineImpl(instances[0]).getPartitionService().getPartitionId(key);
    List<IScheduledFuture> futures = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        futures.add(service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS));
    }
    assertCapacityReached(service, key, "Maximum capacity (10) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
    // Dispose all
    for (IScheduledFuture future : futures) {
        future.dispose();
    }
    // Re-schedule to verify capacity
    for (int i = 0; i < 10; i++) {
        service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
    }
    assertCapacityReached(service, key, "Maximum capacity (10) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
}
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) ArrayList(java.util.ArrayList) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with IScheduledFuture

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

the class ScheduledExecutorServiceBasicTest method capacity_whenAutoDisposable_Callable.

@Test
public void capacity_whenAutoDisposable_Callable() throws Exception {
    String schedulerName = ANY_EXECUTOR_NAME;
    int capacity = 10;
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(capacity);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    String keyOwner = "hitSamePartitionToCheckCapacity";
    List<IScheduledFuture<Double>> futures = new ArrayList<>();
    for (int i = 0; i < capacity; i++) {
        Callable<Double> command = autoDisposable(new PlainCallableTask());
        IScheduledFuture<Double> future = service.scheduleOnKeyOwner(command, keyOwner, 0, SECONDS);
        futures.add(future);
    }
    futures.forEach(this::assertTaskHasBeenDestroyedEventually);
    for (int i = 0; i < capacity; i++) {
        service.scheduleOnKeyOwner(autoDisposable(new PlainCallableTask()), keyOwner, 0, TimeUnit.SECONDS);
    }
// no exceptions thrown
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with IScheduledFuture

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

the class ScheduledExecutorServiceBasicTest method scheduled_executor_collects_statistics_when_stats_enabled.

@Test
public void scheduled_executor_collects_statistics_when_stats_enabled() throws Exception {
    // run task
    Config config = smallInstanceConfig();
    config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(true);
    HazelcastInstance[] instances = createClusterWithCount(2, config);
    IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    Map<Member, IScheduledFuture<Double>> futureMap = s.scheduleOnAllMembers(new OneSecondSleepingTask(), 0, SECONDS);
    Set<Map.Entry<Member, IScheduledFuture<Double>>> entries = futureMap.entrySet();
    for (Map.Entry<Member, IScheduledFuture<Double>> entry : entries) {
        entry.getValue().get();
    }
    assertTrueEventually(() -> {
        // collect metrics
        Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
        // check results
        assertMetricsCollected(metrics, 1000, 0, 1, 1, 0, 1, 0);
    });
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member) Map(java.util.Map) HashMap(java.util.HashMap) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with IScheduledFuture

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

the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit_andMigration.

@Test
public void capacity_whenPositiveLimit_andMigration() throws ExecutionException, InterruptedException {
    String schedulerName = ANY_EXECUTOR_NAME;
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(1).setCapacityPolicy(ScheduledExecutorConfig.CapacityPolicy.PER_PARTITION);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(2, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    String key = generateKeyOwnedBy(instances[0]);
    int keyOwner = getNodeEngineImpl(instances[0]).getPartitionService().getPartitionId(key);
    IScheduledFuture future = service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
    future.get();
    assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
    instances[0].getLifecycleService().shutdown();
    waitAllForSafeState(instances[1]);
    // Re-assign service & future
    service = instances[1].getScheduledExecutorService(schedulerName);
    future = service.getScheduledFuture(future.getHandler());
    assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
    future.dispose();
    service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
    assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
}
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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with IScheduledFuture

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

the class ScheduledExecutorServiceBasicTest method capacity_whenDefault_perPartition.

@Test
public void capacity_whenDefault_perPartition() {
    String schedulerName = ANY_EXECUTOR_NAME;
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setCapacityPolicy(ScheduledExecutorConfig.CapacityPolicy.PER_PARTITION);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    String key = "hitSamePartitionToCheckCapacity";
    int keyOwner = getNodeEngineImpl(instances[0]).getPartitionService().getPartitionId(key);
    List<IScheduledFuture> futures = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        futures.add(service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS));
    }
    assertCapacityReached(service, key, "Maximum capacity (100) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
    // Dispose all
    for (IScheduledFuture future : futures) {
        future.dispose();
    }
    // Re-schedule to verify capacity
    for (int i = 0; i < 100; i++) {
        service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
    }
    assertCapacityReached(service, key, "Maximum capacity (100) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
}
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) ArrayList(java.util.ArrayList) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)48 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)35 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)34 Test (org.junit.Test)34 QuickTest (com.hazelcast.test.annotation.QuickTest)27 Config (com.hazelcast.config.Config)16 ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)16 Member (com.hazelcast.cluster.Member)14 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)14 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)10 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 Member (com.hazelcast.core.Member)5 TaskDefinition (com.hazelcast.scheduledexecutor.impl.TaskDefinition)5 List (java.util.List)5 Map (java.util.Map)5 Nonnull (javax.annotation.Nonnull)4 LinkedList (java.util.LinkedList)3