Search in sources :

Example 26 with ExecutorConfig

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutorConfig(com.hazelcast.config.ExecutorConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with ExecutorConfig

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

Example 28 with ExecutorConfig

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Config(com.hazelcast.config.Config) ExecutorConfig(com.hazelcast.config.ExecutorConfig) IExecutorService(com.hazelcast.core.IExecutorService) ExecutorConfig(com.hazelcast.config.ExecutorConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with ExecutorConfig

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);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Config(com.hazelcast.config.Config) ExecutorConfig(com.hazelcast.config.ExecutorConfig) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Before(org.junit.Before)

Example 30 with ExecutorConfig

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig)

Aggregations

ExecutorConfig (com.hazelcast.config.ExecutorConfig)30 DurableExecutorConfig (com.hazelcast.config.DurableExecutorConfig)15 ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)15 Config (com.hazelcast.config.Config)12 Test (org.junit.Test)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 IExecutorService (com.hazelcast.core.IExecutorService)6 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)5 CardinalityEstimatorConfig (com.hazelcast.config.CardinalityEstimatorConfig)5 FlakeIdGeneratorConfig (com.hazelcast.config.FlakeIdGeneratorConfig)5 ListConfig (com.hazelcast.config.ListConfig)5 MapConfig (com.hazelcast.config.MapConfig)5 MultiMapConfig (com.hazelcast.config.MultiMapConfig)5 PNCounterConfig (com.hazelcast.config.PNCounterConfig)5 QueueConfig (com.hazelcast.config.QueueConfig)5 ReliableTopicConfig (com.hazelcast.config.ReliableTopicConfig)5 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)5 RingbufferConfig (com.hazelcast.config.RingbufferConfig)5