Search in sources :

Example 86 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method schedule_withLongSleepingCallable_blockingOnGet.

@Test
public void schedule_withLongSleepingCallable_blockingOnGet() throws Exception {
    int delay = 0;
    double expectedResult = 169.4;
    HazelcastInstance[] instances = createClusterWithCount(2);
    ICountDownLatch initCountLatch = instances[0].getCPSubsystem().getCountDownLatch("initCountLatchName");
    initCountLatch.trySetCount(1);
    ICountDownLatch waitCountLatch = instances[0].getCPSubsystem().getCountDownLatch("waitCountLatchName");
    waitCountLatch.trySetCount(1);
    ICountDownLatch doneCountLatch = instances[0].getCPSubsystem().getCountDownLatch("doneCountLatchName");
    doneCountLatch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture<Double> future = executorService.schedule(new ICountdownLatchCallableTask(initCountLatch.getName(), waitCountLatch.getName(), doneCountLatch.getName()), delay, SECONDS);
    assertOpenEventually(initCountLatch);
    int sleepPeriod = 10000;
    long start = System.currentTimeMillis();
    new Thread(() -> {
        sleepAtLeastMillis(sleepPeriod);
        waitCountLatch.countDown();
    }).start();
    double result = future.get();
    assertTrue(System.currentTimeMillis() - start > sleepPeriod);
    assertTrue(doneCountLatch.await(0, SECONDS));
    assertEquals(expectedResult, result, 0);
    assertTrue(future.isDone());
    assertFalse(future.isCancelled());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 87 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method schedule_thenDisposeLeakTest.

@Test(timeout = 1800000)
public void schedule_thenDisposeLeakTest() {
    Config config = new Config().addScheduledExecutorConfig(new ScheduledExecutorConfig().setName("s").setCapacity(10000));
    HazelcastInstance[] instances = createClusterWithCount(2, config);
    final IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    final AtomicBoolean running = new AtomicBoolean(true);
    long counter = 0;
    long limit = 2000000;
    Executors.newSingleThreadExecutor().submit(new Runnable() {

        @Override
        public void run() {
            while (running.get()) {
                for (Collection<IScheduledFuture<Object>> collection : executorService.getAllScheduledFutures().values()) {
                    for (IScheduledFuture future : collection) {
                        if (future.getStats().getTotalRuns() >= 1) {
                            future.dispose();
                        }
                    }
                }
            }
        }
    });
    while (running.get()) {
        try {
            executorService.schedule(new PlainCallableTask(), 1, SECONDS);
            Thread.yield();
            if (counter++ % 1000 == 0) {
                System.out.println("Tasks: " + counter);
            }
            if (counter >= limit) {
                running.set(false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            running.set(false);
        }
    }
    // wait for running tasks to finish, keeping log clean of PassiveMode exceptions
    sleepSeconds(5);
}
Also used : IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 88 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method cancelUninterruptedTask_waitUntilRunCompleted_checkStatusIsCancelled.

@Test
public void cancelUninterruptedTask_waitUntilRunCompleted_checkStatusIsCancelled() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(1);
    String runFinishedLatchName = "runFinishedLatch";
    ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch(runFinishedLatchName);
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleAtFixedRate(new HotLoopBusyTask(runFinishedLatchName), 0, 1, SECONDS);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
    // wait till the task is actually done, since even though we cancelled the task is current task is still running
    latch.await(60, SECONDS);
    // make sure SyncState goes through
    sleepSeconds(10);
    // check once more that the task status is consistent
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 89 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method scheduleRandomPartitions_periodicTask_getAllScheduled_durable.

@Test
public void scheduleRandomPartitions_periodicTask_getAllScheduled_durable() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(3);
    IScheduledExecutorService s = getScheduledExecutor(instances, "s");
    String key = generateKeyOwnedBy(instances[1]);
    String runsCounterName = "runs";
    ICountDownLatch runsLatch = instances[0].getCPSubsystem().getCountDownLatch(runsCounterName);
    runsLatch.trySetCount(2);
    int expectedTotal = 11;
    for (int i = 0; i < expectedTotal; i++) {
        s.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask(runsCounterName), key, 0, 2, SECONDS);
    }
    runsLatch.await(10, SECONDS);
    instances[1].getLifecycleService().shutdown();
    assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 90 with IScheduledExecutorService

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

the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_killMember_thenGetAllScheduled.

@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_killMember_thenGetAllScheduled() throws Exception {
    String runsCounterName = "runs";
    HazelcastInstance[] instances = createClusterWithCount(10);
    ICountDownLatch runsLatch = instances[0].getCPSubsystem().getCountDownLatch(runsCounterName);
    int numOfSchedulers = 20;
    int numOfTasks = 10;
    int expectedTotal = numOfSchedulers * numOfTasks;
    runsLatch.trySetCount(expectedTotal);
    for (int i = 0; i < numOfSchedulers; i++) {
        IScheduledExecutorService s = getScheduledExecutor(instances, "scheduler_" + i);
        String key = generateKeyOwnedBy(instances[i % instances.length]);
        for (int k = 0; k < numOfTasks; k++) {
            s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask(runsCounterName), key, 0, SECONDS);
        }
    }
    runsLatch.await(10, SECONDS);
    instances[1].getLifecycleService().terminate();
    int actualTotal = 0;
    for (int i = 0; i < numOfSchedulers; i++) {
        actualTotal += countScheduledTasksOn(getScheduledExecutor(instances, "scheduler_" + i));
    }
    assertEquals(expectedTotal, actualTotal, 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

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