Search in sources :

Example 1 with DurableExecutorConfig

use of com.hazelcast.config.DurableExecutorConfig in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceTest method setup.

@Before
public void setup() {
    Config config = new Config();
    DurableExecutorConfig durableExecutorConfig = config.getDurableExecutorConfig(SINGLE_TASK + "*");
    durableExecutorConfig.setCapacity(1);
    hazelcastFactory.newHazelcastInstance(config);
    hazelcastFactory.newHazelcastInstance(config);
    hazelcastFactory.newHazelcastInstance(config);
    hazelcastFactory.newHazelcastInstance(config);
    client = hazelcastFactory.newHazelcastClient();
}
Also used : Config(com.hazelcast.config.Config) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) Before(org.junit.Before)

Example 2 with DurableExecutorConfig

use of com.hazelcast.config.DurableExecutorConfig in project hazelcast by hazelcast.

the class TestFullApplicationContext method testDurableExecutorConfig.

@Test
public void testDurableExecutorConfig() {
    DurableExecutorConfig testExecConfig = config.getDurableExecutorConfig("durableExec");
    assertNotNull(testExecConfig);
    assertEquals("durableExec", testExecConfig.getName());
    assertEquals(10, testExecConfig.getPoolSize());
    assertEquals(5, testExecConfig.getDurability());
    assertEquals(200, testExecConfig.getCapacity());
}
Also used : DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 3 with DurableExecutorConfig

use of com.hazelcast.config.DurableExecutorConfig in project hazelcast by hazelcast.

the class DurableExecutorServiceTest method hazelcastInstanceAwareAndLocal.

@Test
public void hazelcastInstanceAwareAndLocal() throws Exception {
    Config config = new Config();
    config.addDurableExecutorConfig(new DurableExecutorConfig("test").setPoolSize(1));
    HazelcastInstance instance = createHazelcastInstance(config);
    DurableExecutorService executor = instance.getDurableExecutorService("test");
    HazelcastInstanceAwareRunnable task = new HazelcastInstanceAwareRunnable();
    // if setHazelcastInstance() not called we expect a RuntimeException
    executor.submit(task).get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with DurableExecutorConfig

use of com.hazelcast.config.DurableExecutorConfig in project hazelcast by hazelcast.

the class DurableSpecificSetupTest method managedContext_mustInitializeRunnable.

@Test
public void managedContext_mustInitializeRunnable() throws Exception {
    final AtomicBoolean initialized = new AtomicBoolean();
    Config config = new Config().addDurableExecutorConfig(new DurableExecutorConfig("test").setPoolSize(1)).setManagedContext(new ManagedContext() {

        @Override
        public Object initialize(Object obj) {
            if (obj instanceof RunnableWithManagedContext) {
                initialized.set(true);
            }
            return obj;
        }
    });
    DurableExecutorService executor = createHazelcastInstance(config).getDurableExecutorService("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) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) ManagedContext(com.hazelcast.core.ManagedContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with DurableExecutorConfig

use of com.hazelcast.config.DurableExecutorConfig in project hazelcast by hazelcast.

the class DurableExecutorServiceTest method testStatsIssue2039.

@Test
public //    @Repeat(100)
void testStatsIssue2039() throws Exception {
    Config config = new Config();
    String name = "testStatsIssue2039";
    config.addDurableExecutorConfig(new DurableExecutorConfig(name).setPoolSize(1).setCapacity(1));
    HazelcastInstance instance = createHazelcastInstance(config);
    DurableExecutorService executorService = instance.getDurableExecutorService(name);
    executorService.execute(new SleepLatchRunnable());
    assertOpenEventually(SleepLatchRunnable.startLatch, 30);
    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();
    }
// FIXME as soon as executorService.getLocalExecutorStats() is implemented
//LocalExecutorStats stats = executorService.getLocalExecutorStats();
//assertEquals(2, stats.getStartedTaskCount());
//assertEquals(0, stats.getPendingTaskCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

DurableExecutorConfig (com.hazelcast.config.DurableExecutorConfig)9 Config (com.hazelcast.config.Config)6 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 ManagedContext (com.hazelcast.core.ManagedContext)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ExecutorConfig (com.hazelcast.config.ExecutorConfig)1 ICompletableFuture (com.hazelcast.core.ICompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Before (org.junit.Before)1