use of com.hazelcast.config.ExecutorConfig in project hazelcast by hazelcast.
the class ExecutorServiceTest method testStatsIssue2039.
@Test
public void testStatsIssue2039() throws Exception {
Config config = smallInstanceConfig();
String name = "testStatsIssue2039";
config.addExecutorConfig(new ExecutorConfig(name).setQueueCapacity(1).setPoolSize(1));
HazelcastInstance instance = createHazelcastInstance(config);
IExecutorService executorService = instance.getExecutorService(name);
executorService.execute(new SleepLatchRunnable());
assertOpenEventually(SleepLatchRunnable.startLatch, 30);
Future<?> waitingInQueue = executorService.submit(new EmptyRunnable());
Future<?> rejected = executorService.submit(new EmptyRunnable());
try {
rejected.get(1, TimeUnit.MINUTES);
} catch (Exception e) {
boolean isRejected = e.getCause() instanceof RejectedExecutionException;
if (!isRejected) {
fail(e.toString());
}
} finally {
SleepLatchRunnable.sleepLatch.countDown();
}
waitingInQueue.get(1, TimeUnit.MINUTES);
LocalExecutorStats stats = executorService.getLocalExecutorStats();
assertEquals(2, stats.getStartedTaskCount());
assertEquals(0, stats.getPendingTaskCount());
}
use of com.hazelcast.config.ExecutorConfig in project hazelcast by hazelcast.
the class SpecificSetupTest method statsIssue2039.
@Test
public void statsIssue2039() throws Exception {
Config config = smallInstanceConfig();
String name = "testStatsIssue2039";
config.addExecutorConfig(new ExecutorConfig(name).setQueueCapacity(1).setPoolSize(1));
HazelcastInstance instance = createHazelcastInstance(config);
IExecutorService executorService = instance.getExecutorService(name);
SleepLatchRunnable runnable = new SleepLatchRunnable();
executorService.execute(runnable);
assertTrue(SleepLatchRunnable.startLatch.await(30, SECONDS));
Future<?> waitingInQueue = executorService.submit(new EmptyRunnable());
Future<?> rejected = executorService.submit(new EmptyRunnable());
try {
rejected.get(1, MINUTES);
} catch (Exception e) {
if (!(e.getCause() instanceof RejectedExecutionException)) {
fail(e.toString());
}
} finally {
SleepLatchRunnable.sleepLatch.countDown();
}
waitingInQueue.get(1, MINUTES);
LocalExecutorStats stats = executorService.getLocalExecutorStats();
assertEquals(2, stats.getStartedTaskCount());
assertEquals(0, stats.getPendingTaskCount());
}
use of com.hazelcast.config.ExecutorConfig in project hazelcast by hazelcast.
the class SpecificSetupTest method managedContext_mustInitializeRunnable.
@Test
public void managedContext_mustInitializeRunnable() throws Exception {
final AtomicBoolean initialized = new AtomicBoolean();
Config config = smallInstanceConfig().addExecutorConfig(new ExecutorConfig("test", 1)).setManagedContext(obj -> {
if (obj instanceof RunnableWithManagedContext) {
initialized.set(true);
}
return obj;
});
IExecutorService executor = createHazelcastInstance(config).getExecutorService("test");
executor.submit(new RunnableWithManagedContext()).get();
assertTrue("The task should have been initialized by the ManagedContext", initialized.get());
}
use of com.hazelcast.config.ExecutorConfig in project hazelcast by hazelcast.
the class DistributedExecutorServiceTest method setup.
@Before
public void setup() {
Config config = new Config();
config.addExecutorConfig(new ExecutorConfig().setName(EXECUTOR_NAME).setStatisticsEnabled(false));
hz = createHazelcastInstance(config);
NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
distributedExecutorService = nodeEngine.getService(DistributedExecutorService.SERVICE_NAME);
}
use of com.hazelcast.config.ExecutorConfig in project hazelcast by hazelcast.
the class DynamicConfigTest method assertConfigurationsEqualOnAllMembers.
private void assertConfigurationsEqualOnAllMembers(ExecutorConfig executorConfig) {
String name = executorConfig.getName();
for (HazelcastInstance instance : members) {
ExecutorConfig registeredConfig = instance.getConfig().getExecutorConfig(name);
assertEquals(executorConfig, registeredConfig);
}
}
Aggregations