Search in sources :

Example 26 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method schedule_getHandlerDisposeThenRecreateFutureAndGet.

@Test
public void schedule_getHandlerDisposeThenRecreateFutureAndGet() 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, SECONDS);
    ScheduledTaskHandler handler = first.getHandler();
    first.dispose();
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(StaleTaskException.class));
    executorService.getScheduledFuture(handler).get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withCallable.

@Test
public void scheduleOnKeyOwner_withCallable() throws Exception {
    int delay = 1;
    String key = "TestKey";
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    Callable<Double> task = new PlainPartitionAwareCallableTask();
    IScheduledFuture<Double> first = executorService.scheduleOnKeyOwner(task, key, delay, SECONDS);
    ScheduledTaskHandler handler = first.getHandler();
    int expectedPartition = instances[0].getPartitionService().getPartition(key).getPartitionId();
    assertEquals(expectedPartition, handler.getPartitionId());
    assertEquals(25, first.get(), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 28 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method schedule_partitionAware.

@Test
public void schedule_partitionAware() {
    int delay = 1;
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    Callable<Double> task = new PlainPartitionAwareCallableTask();
    IScheduledFuture<Double> first = executorService.schedule(task, delay, SECONDS);
    ScheduledTaskHandler handler = first.getHandler();
    int expectedPartition = getPartitionIdFromPartitionAwareTask(instances[0], (PartitionAware) task);
    assertEquals(expectedPartition, handler.getPartitionId());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with IScheduledExecutorService

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

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

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