Search in sources :

Example 61 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method getScheduled_whenTaskDecoratedWithNamedTask.

@Test
public void getScheduled_whenTaskDecoratedWithNamedTask() {
    int delay = 1;
    String taskName = "Test";
    PlainCallableTask task = new PlainCallableTask();
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture<Double> first = executorService.schedule(named(taskName, task), delay, SECONDS);
    ScheduledTaskHandler handler = first.getHandler();
    IScheduledFuture<Double> copy = executorService.getScheduledFuture(handler);
    assertEquals(first.getHandler(), copy.getHandler());
    assertEquals(copy.getHandler().getTaskName(), taskName);
}
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 62 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method schedule_duplicate.

@Test(expected = DuplicateTaskException.class)
public void schedule_duplicate() {
    int delay = 1;
    String taskName = "Test";
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    executorService.schedule(named(taskName, new PlainCallableTask()), delay, SECONDS);
    executorService.schedule(named(taskName, new PlainCallableTask()), delay, SECONDS);
}
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 63 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method capacity_whenAutoDisposable_Runnable.

@Test
public void capacity_whenAutoDisposable_Runnable() 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++) {
        Runnable command = autoDisposable(new PlainRunnableTask());
        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 PlainRunnableTask()), 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 64 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduleOnAllMembers_getAllScheduled.

@Test
public void scheduleOnAllMembers_getAllScheduled() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(3);
    IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    s.scheduleOnAllMembers(new PlainCallableTask(), 0, SECONDS);
    Set<Member> members = instances[0].getCluster().getMembers();
    Map<Member, List<IScheduledFuture<Double>>> allScheduled = s.getAllScheduledFutures();
    assertEquals(members.size(), allScheduled.size());
    for (Member member : members) {
        assertEquals(1, allScheduled.get(member).size());
        assertEquals(25.0, allScheduled.get(member).get(0).get(), 0);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) List(java.util.List) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with IScheduledExecutorService

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_thenGet.

@Test
public void scheduleOnKeyOwner_thenGet() throws Exception {
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(new PlainCallableTask(), key, 2, SECONDS);
    assertEquals(25.0, future.get(), 0.0);
}
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)

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