use of com.hazelcast.monitor.LocalExecutorStats in project hazelcast by hazelcast.
the class SingleNodeTest method executorServiceStats.
@Test
public void executorServiceStats() throws InterruptedException, ExecutionException {
final int iterations = 10;
LatchRunnable.latch = new CountDownLatch(iterations);
LatchRunnable runnable = new LatchRunnable();
for (int i = 0; i < iterations; i++) {
executor.execute(runnable);
}
assertOpenEventually(LatchRunnable.latch);
Future<Boolean> future = executor.submit(new SleepingTask(10));
future.cancel(true);
try {
future.get();
} catch (CancellationException ignored) {
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
LocalExecutorStats stats = executor.getLocalExecutorStats();
assertEquals(iterations + 1, stats.getStartedTaskCount());
assertEquals(iterations, stats.getCompletedTaskCount());
assertEquals(0, stats.getPendingTaskCount());
assertEquals(1, stats.getCancelledTaskCount());
}
});
}
use of com.hazelcast.monitor.LocalExecutorStats in project hazelcast by hazelcast.
the class SpecificSetupTest method statsIssue2039.
@Test
public void statsIssue2039() throws Exception {
Config config = new Config();
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.monitor.LocalExecutorStats in project hazelcast by hazelcast.
the class ExecutorServiceTest method testExecutorServiceStats_whenStatsAreDisabled.
@Test
public void testExecutorServiceStats_whenStatsAreDisabled() throws Exception {
LocalExecutorStats stats = executeTasksForStats("testExecutorServiceStats_whenStatsDisabled", 10, false);
assertEquals(0, stats.getStartedTaskCount());
assertEquals(0, stats.getCompletedTaskCount());
assertEquals(0, stats.getPendingTaskCount());
assertEquals(0, stats.getCancelledTaskCount());
}
use of com.hazelcast.monitor.LocalExecutorStats in project hazelcast by hazelcast.
the class ExecutorServiceTest method testExecutorServiceStats.
@Test
public void testExecutorServiceStats() throws Exception {
int i = 10;
LocalExecutorStats stats = executeTasksForStats("testExecutorServiceStats", i, true);
assertEquals(i + 1, stats.getStartedTaskCount());
assertEquals(i, stats.getCompletedTaskCount());
assertEquals(0, stats.getPendingTaskCount());
assertEquals(1, stats.getCancelledTaskCount());
}
use of com.hazelcast.monitor.LocalExecutorStats in project hazelcast by hazelcast.
the class ExecutorServiceTest method testStatsIssue2039.
@Test
public void testStatsIssue2039() throws Exception {
Config config = new Config();
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());
}
Aggregations