Search in sources :

Example 76 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method submitCallableToMember_withMultiExecutionCallback.

@Test
public void submitCallableToMember_withMultiExecutionCallback() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
    final String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    Collection<Member> collection = server.getCluster().getMembers();
    service.submitToMembers(callable, collection, new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            if (value.equals(msg + AppendCallable.APPENDAGE)) {
                responseLatch.countDown();
            }
        }

        public void onComplete(Map<Member, Object> values) {
            for (Member member : values.keySet()) {
                Object value = values.get(member);
                if (value.equals(msg + AppendCallable.APPENDAGE)) {
                    completeLatch.countDown();
                }
            }
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 77 with IExecutorService

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

the class ExecutorServiceLiteMemberTest method test_executeRunnable_failsWhenNoLiteMemberExists.

@Test(expected = RejectedExecutionException.class)
public void test_executeRunnable_failsWhenNoLiteMemberExists() {
    factory.newHazelcastInstance();
    final HazelcastInstance client = factory.newHazelcastClient();
    final String name = randomString();
    final IExecutorService executor = client.getExecutorService(name);
    executor.execute(new ResultSettingRunnable(name), LITE_MEMBER_SELECTOR);
}
Also used : ResultSettingRunnable(com.hazelcast.executor.ExecutorServiceTestSupport.ResultSettingRunnable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorServiceTestSupport.randomString(com.hazelcast.executor.ExecutorServiceTestSupport.randomString) IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 78 with IExecutorService

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

the class ExecutorServiceLiteMemberTest method test_executeRunnable_onLiteMember.

@Test
public void test_executeRunnable_onLiteMember() {
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    factory.newHazelcastInstance();
    final HazelcastInstance client = factory.newHazelcastClient();
    final String name = randomString();
    final IExecutorService executor = client.getExecutorService(name);
    executor.execute(new ResultSettingRunnable(name), LITE_MEMBER_SELECTOR);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final IMap<Object, Object> results = lite1.getMap(name);
            assertEquals(1, results.size());
            final boolean executedOnLite1 = results.containsKey(lite1.getCluster().getLocalMember());
            final boolean executedOnLite2 = results.containsKey(lite2.getCluster().getLocalMember());
            assertTrue(executedOnLite1 || executedOnLite2);
        }
    });
}
Also used : ResultSettingRunnable(com.hazelcast.executor.ExecutorServiceTestSupport.ResultSettingRunnable) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ExecutorServiceTestSupport.randomString(com.hazelcast.executor.ExecutorServiceTestSupport.randomString) IExecutorService(com.hazelcast.core.IExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 79 with IExecutorService

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

the class ExecutorServiceLiteMemberTest method test_submitCallable_onLiteMembers.

@Test
public void test_submitCallable_onLiteMembers() throws ExecutionException, InterruptedException {
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    factory.newHazelcastInstance();
    final HazelcastInstance client = factory.newHazelcastClient();
    final IExecutorService executor = client.getExecutorService(randomString());
    final Map<Member, Future<Member>> results = executor.submitToMembers(new LocalMemberReturningCallable(), LITE_MEMBER_SELECTOR);
    assertEquals(2, results.size());
    final Member liteMember1 = lite1.getCluster().getLocalMember();
    final Member liteMember2 = lite2.getCluster().getLocalMember();
    assertEquals(liteMember1, results.get(liteMember1).get());
    assertEquals(liteMember2, results.get(liteMember2).get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) LocalMemberReturningCallable(com.hazelcast.executor.ExecutorServiceTestSupport.LocalMemberReturningCallable) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 80 with IExecutorService

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

the class Invocation_RegressionTest method testIssue2509.

@Test(expected = ExecutionException.class, timeout = 120000)
public void testIssue2509() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    UnDeserializable unDeserializable = new UnDeserializable(1);
    IExecutorService executorService = h1.getExecutorService("default");
    Issue2509Runnable task = new Issue2509Runnable(unDeserializable);
    Future<?> future = executorService.submitToMember(task, h2.getCluster().getLocalMember());
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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