Search in sources :

Example 21 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method schedule_withNegativeDelay.

@Test
public void schedule_withNegativeDelay() throws Exception {
    int delay = -2;
    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)

Example 22 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduleOnMember.

@Test
public void scheduleOnMember() throws Exception {
    int delay = 1;
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    MemberImpl member = getNodeEngineImpl(instances[0]).getLocalMember();
    IScheduledFuture<Double> future = executorService.scheduleOnMember(new PlainCallableTask(), member, delay, SECONDS);
    assertTrue(future.getHandler().isAssignedToMember());
    assertEquals(25.0, future.get(), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService 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 24 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method schedule_thenCancelInterrupted.

@Test(expected = UnsupportedOperationException.class)
public void schedule_thenCancelInterrupted() {
    int delay = 1;
    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);
    first.cancel(true);
}
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 25 with IScheduledExecutorService

use of com.hazelcast.scheduledexecutor.IScheduledExecutorService 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)

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