Search in sources :

Example 1 with LocalExecutorStats

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());
        }
    });
}
Also used : CancellationException(java.util.concurrent.CancellationException) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) LocalExecutorStats(com.hazelcast.monitor.LocalExecutorStats) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with LocalExecutorStats

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutorConfig(com.hazelcast.config.ExecutorConfig) LocalExecutorStats(com.hazelcast.monitor.LocalExecutorStats) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with LocalExecutorStats

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());
}
Also used : LocalExecutorStats(com.hazelcast.monitor.LocalExecutorStats) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with LocalExecutorStats

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());
}
Also used : LocalExecutorStats(com.hazelcast.monitor.LocalExecutorStats) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with LocalExecutorStats

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutorConfig(com.hazelcast.config.ExecutorConfig) LocalExecutorStats(com.hazelcast.monitor.LocalExecutorStats) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

LocalExecutorStats (com.hazelcast.monitor.LocalExecutorStats)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 Config (com.hazelcast.config.Config)2 ExecutorConfig (com.hazelcast.config.ExecutorConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IExecutorService (com.hazelcast.core.IExecutorService)2 CancellationException (java.util.concurrent.CancellationException)2 Future (java.util.concurrent.Future)2 TimeoutException (java.util.concurrent.TimeoutException)2 ICompletableFuture (com.hazelcast.core.ICompletableFuture)1 AssertTask (com.hazelcast.test.AssertTask)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1