Search in sources :

Example 86 with IExecutorService

use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.

the class SmallClusterTest method submitToSeveralNodes_callable.

@Test
public void submitToSeveralNodes_callable() throws Exception {
    for (int i = 0; i < instances.length; i++) {
        IExecutorService service = instances[i].getExecutorService("testSubmitMultipleNode");
        Future future = service.submit(new IncrementAtomicLongCallable("testSubmitMultipleNode"));
        assertEquals((long) (i + 1), future.get());
    }
}
Also used : Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 87 with IExecutorService

use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.

the class SmallClusterTest method submitToMember_callable.

@Test(timeout = TEST_TIMEOUT)
public void submitToMember_callable() throws Exception {
    List<Future> futures = new ArrayList<Future>();
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToMemberCallable");
        Member localMember = instance.getCluster().getLocalMember();
        Future future = service.submitToMember(new MemberUUIDCheckCallable(localMember.getUuid()), localMember);
        futures.add(future);
    }
    for (Future future : futures) {
        assertTrue((Boolean) future.get());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 88 with IExecutorService

use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.

the class SmallClusterTest method submitToAllMembers_callable.

@Test
public void submitToAllMembers_callable() {
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToAllMembersCallable");
        service.submitToAllMembers(new IncrementAtomicLongCallable("testSubmitToAllMembersCallable"), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getAtomicLong("testSubmitToAllMembersCallable");
    assertEquals(instances.length * instances.length, result.get());
    assertEquals(instances.length * instances.length, callback.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 89 with IExecutorService

use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.

the class SmallClusterTest method submitToKeyOwner_runnable.

@Test
public void submitToKeyOwner_runnable() {
    NullResponseCountingCallback callback = new NullResponseCountingCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerRunnable");
        Member localMember = instance.getCluster().getLocalMember();
        int key = findNextKeyForMember(instance, localMember);
        service.submitToKeyOwner(new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(localMember.getUuid(), "testSubmitToKeyOwnerRunnable"), key, callback);
    }
    assertOpenEventually(callback.getResponseLatch());
    assertEquals(0, instances[0].getAtomicLong("testSubmitToKeyOwnerRunnable").get());
    assertEquals(instances.length, callback.getNullResponseCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 90 with IExecutorService

use of com.hazelcast.core.IExecutorService 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)

Aggregations

IExecutorService (com.hazelcast.core.IExecutorService)152 QuickTest (com.hazelcast.test.annotation.QuickTest)138 Test (org.junit.Test)138 ParallelTest (com.hazelcast.test.annotation.ParallelTest)137 HazelcastInstance (com.hazelcast.core.HazelcastInstance)66 Member (com.hazelcast.core.Member)57 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)46 Future (java.util.concurrent.Future)36 IMap (com.hazelcast.core.IMap)32 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 CountDownLatch (java.util.concurrent.CountDownLatch)28 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)25 ExecutorConfig (com.hazelcast.config.ExecutorConfig)20 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)20 Config (com.hazelcast.config.Config)19 ExecutionException (java.util.concurrent.ExecutionException)18 AppendCallable (com.hazelcast.client.executor.tasks.AppendCallable)16 AssertTask (com.hazelcast.test.AssertTask)16 ICompletableFuture (com.hazelcast.core.ICompletableFuture)13 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)11