Search in sources :

Example 81 with IExecutorService

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

the class MBeanDestroyTest method testExecutor.

@Test
public void testExecutor() throws Exception {
    IExecutorService executor = holder.getHz().getExecutorService("executor");
    executor.submit(new DummyRunnable()).get();
    holder.assertMBeanExistEventually("IExecutorService", executor.getName());
    destroyObjectAndAssert(executor, "IExecutorService");
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 82 with IExecutorService

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

the class SmallClusterTest method submitToMembers_callable.

@Test
public void submitToMembers_callable() {
    int sum = 0;
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    Set<Member> membersSet = instances[0].getCluster().getMembers();
    Member[] members = membersSet.toArray(new Member[membersSet.size()]);
    Random random = new Random();
    String name = "testSubmitToMembersCallable";
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService(name);
        int n = random.nextInt(instances.length) + 1;
        sum += n;
        Member[] m = new Member[n];
        System.arraycopy(members, 0, m, 0, n);
        service.submitToMembers(new IncrementAtomicLongCallable(name), Arrays.asList(m), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getAtomicLong(name);
    assertEquals(sum, result.get());
    assertEquals(sum, callback.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IExecutorService(com.hazelcast.core.IExecutorService) IAtomicLong(com.hazelcast.core.IAtomicLong) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 83 with IExecutorService

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

the class SmallClusterTest method submitToMembers_runnable.

@Test
public void submitToMembers_runnable() {
    int sum = 0;
    Set<Member> membersSet = instances[0].getCluster().getMembers();
    Member[] members = membersSet.toArray(new Member[membersSet.size()]);
    Random random = new Random();
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToMembersRunnable");
        int n = random.nextInt(instances.length) + 1;
        sum += n;
        Member[] m = new Member[n];
        System.arraycopy(members, 0, m, 0, n);
        service.submitToMembers(new IncrementAtomicLongRunnable("testSubmitToMembersRunnable"), Arrays.asList(m), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getAtomicLong("testSubmitToMembersRunnable");
    assertEquals(sum, result.get());
    assertEquals(sum, callback.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IExecutorService(com.hazelcast.core.IExecutorService) IAtomicLong(com.hazelcast.core.IAtomicLong) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 84 with IExecutorService

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

the class SmallClusterTest method submitToKeyOwner_callable.

@Test(timeout = TEST_TIMEOUT)
public void submitToKeyOwner_callable() throws Exception {
    List<Future> futures = new ArrayList<Future>();
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerCallable");
        Member localMember = instance.getCluster().getLocalMember();
        int key = findNextKeyForMember(instance, localMember);
        Future future = service.submitToKeyOwner(new MemberUUIDCheckCallable(localMember.getUuid()), key);
        futures.add(future);
    }
    for (Future future : futures) {
        assertTrue((Boolean) future.get(60, TimeUnit.SECONDS));
    }
}
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 85 with IExecutorService

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

the class SmallClusterTest method submitToMember_callable_withCallback.

@Test(timeout = TEST_TIMEOUT)
public void submitToMember_callable_withCallback() {
    BooleanSuccessResponseCountingCallback callback = new BooleanSuccessResponseCountingCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToMemberCallable");
        Member localMember = instance.getCluster().getLocalMember();
        service.submitToMember(new MemberUUIDCheckCallable(localMember.getUuid()), localMember, callback);
    }
    assertOpenEventually(callback.getResponseLatch());
    assertEquals(instances.length, callback.getSuccessResponseCount());
}
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)

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