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."));
}
}
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());
}
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."));
}
}
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);
}
}
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());
}
Aggregations