Search in sources :

Example 1 with ScheduledExecutorConfig

use of com.hazelcast.config.ScheduledExecutorConfig in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method capacity_onMember_whenPositiveLimit.

@Test
public void capacity_onMember_whenPositiveLimit() throws ExecutionException, InterruptedException {
    String schedulerName = "foobar";
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(10);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    Member member = instances[0].getCluster().getLocalMember();
    for (int i = 0; i < 10; i++) {
        service.scheduleOnMember(new PlainCallableTask(), member, 0, TimeUnit.SECONDS);
    }
    try {
        service.scheduleOnMember(new PlainCallableTask(), member, 0, TimeUnit.SECONDS);
        fail("Should have been rejected.");
    } catch (RejectedExecutionException ex) {
        assertTrue("Got wrong RejectedExecutionException", ex.getMessage().equals("Maximum capacity of tasks reached."));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Member(com.hazelcast.core.Member) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with ScheduledExecutorConfig

use of com.hazelcast.config.ScheduledExecutorConfig in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method config.

@Test
public void config() throws ExecutionException, InterruptedException {
    String schedulerName = "foobar";
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(5).setPoolSize(24);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledFuture future = instances[0].getScheduledExecutorService(schedulerName).schedule(new PlainCallableTask(), 0, SECONDS);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(instances[0]);
    ManagedExecutorService mes = (ManagedExecutorService) nodeEngine.getExecutionService().getScheduledDurable(sec.getName());
    DistributedScheduledExecutorService dses = nodeEngine.getService(DistributedScheduledExecutorService.SERVICE_NAME);
    assertNotNull(mes);
    assertEquals(24, mes.getMaximumPoolSize());
    assertEquals(5, dses.getPartition(future.getHandler().getPartitionId()).getOrCreateContainer(schedulerName).getDurability());
    assertEquals(1, dses.getPartition(future.getHandler().getPartitionId()).getOrCreateContainer("other").getDurability());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ManagedExecutorService(com.hazelcast.util.executor.ManagedExecutorService) DistributedScheduledExecutorService(com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ScheduledExecutorConfig

use of com.hazelcast.config.ScheduledExecutorConfig in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit.

@Test
public void capacity_whenPositiveLimit() throws ExecutionException, InterruptedException {
    String schedulerName = "foobar";
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(10);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    String keyOwner = "hitSamePartitionToCheckCapacity";
    for (int i = 0; i < 10; i++) {
        service.scheduleOnKeyOwner(new PlainCallableTask(), keyOwner, 0, TimeUnit.SECONDS);
    }
    try {
        service.scheduleOnKeyOwner(new PlainCallableTask(), keyOwner, 0, TimeUnit.SECONDS);
        fail("Should have been rejected.");
    } catch (RejectedExecutionException ex) {
        assertTrue("Got wrong RejectedExecutionException", ex.getMessage().equals("Maximum capacity of tasks reached."));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ScheduledExecutorConfig

use of com.hazelcast.config.ScheduledExecutorConfig in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method capacity_whenNoLimit.

@Test
public void capacity_whenNoLimit() throws ExecutionException, InterruptedException {
    String schedulerName = "foobar";
    ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(0);
    Config config = new Config().addScheduledExecutorConfig(sec);
    HazelcastInstance[] instances = createClusterWithCount(1, config);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
    String keyOwner = "hitSamePartitionToCheckCapacity";
    for (int i = 0; i < 101; i++) {
        service.scheduleOnKeyOwner(new PlainCallableTask(), keyOwner, 0, TimeUnit.SECONDS);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ScheduledExecutorConfig

use of com.hazelcast.config.ScheduledExecutorConfig in project hazelcast by hazelcast.

the class TestFullApplicationContext method testScheduledExecutorConfig.

@Test
public void testScheduledExecutorConfig() {
    ScheduledExecutorConfig testExecConfig = config.getScheduledExecutorConfig("scheduledExec");
    assertNotNull(testExecConfig);
    assertEquals("scheduledExec", testExecConfig.getName());
    assertEquals(10, testExecConfig.getPoolSize());
    assertEquals(5, testExecConfig.getDurability());
}
Also used : ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Aggregations

ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 Config (com.hazelcast.config.Config)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Member (com.hazelcast.core.Member)1 DistributedScheduledExecutorService (com.hazelcast.scheduledexecutor.impl.DistributedScheduledExecutorService)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 ManagedExecutorService (com.hazelcast.util.executor.ManagedExecutorService)1