Search in sources :

Example 71 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method stats.

@Test
public void stats() throws Exception {
    double delay = 2.0;
    HazelcastInstance[] instances = createClusterWithCount(2);
    Object key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(new PlainCallableTask(), key, (int) delay, SECONDS);
    future.get();
    ScheduledTaskStatistics stats = future.getStats();
    assertEquals(1, stats.getTotalRuns());
    assertEquals(0, stats.getLastRunDuration(SECONDS));
    assertEquals(0, stats.getTotalRunTime(SECONDS));
    assertNotEquals(0, stats.getLastIdleTime(SECONDS));
    assertNotEquals(0, stats.getTotalIdleTime(SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskStatistics(com.hazelcast.scheduledexecutor.ScheduledTaskStatistics) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduleOnMember_getDelay.

@Test
public void scheduleOnMember_getDelay() {
    int delay = 20;
    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, MINUTES);
    assertEquals(19, first.getDelay(MINUTES));
}
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 73 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduledAtFixedRate_does_not_generate_statistics_when_stats_disabled.

@Test
public void scheduledAtFixedRate_does_not_generate_statistics_when_stats_disabled() {
    // run task
    Config config = smallInstanceConfig();
    config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(false);
    long now = System.currentTimeMillis();
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    CountDownLatch progress = new CountDownLatch(3);
    Semaphore suspend = new Semaphore(0);
    s.scheduleAtFixedRate(new CountableRunTask(progress, suspend), 1, 1, SECONDS);
    assertOpenEventually(progress);
    assertTrueAllTheTime(() -> {
        // collect metrics
        Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
        // check results
        assertTrue("No metrics collection expected but " + metrics, metrics.isEmpty());
    }, 5);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) List(java.util.List) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method schedule_thenCancelAndGet.

@Test(expected = CancellationException.class)
public void schedule_thenCancelAndGet() throws Exception {
    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(false);
    first.get();
}
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 75 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduled_executor_does_not_collect_statistics_when_stats_disabled.

@Test
public void scheduled_executor_does_not_collect_statistics_when_stats_disabled() throws Exception {
    // run task
    Config config = smallInstanceConfig();
    config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(false);
    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();
    }
    assertTrueAllTheTime(() -> {
        // collect metrics
        Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
        // check results
        assertTrue("No metrics collection expected but " + metrics, metrics.isEmpty());
    }, 5);
}
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