Search in sources :

Example 91 with IExecutorService

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

the class ExecutorServiceLiteMemberTest method test_submitCallableWithCallback_onLiteMember.

@Test
public void test_submitCallableWithCallback_onLiteMember() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance other = factory.newHazelcastInstance();
    final CountingDownExecutionCallback<Member> callback = new CountingDownExecutionCallback<Member>(1);
    final IExecutorService executor = other.getExecutorService(randomString());
    executor.submit(new LocalMemberReturningCallable(), LITE_MEMBER_SELECTOR, callback);
    assertOpenEventually(callback.getLatch());
    final Object result = callback.getResult();
    final boolean executedOnLite1 = lite1.getCluster().getLocalMember().equals(result);
    final boolean executedOnLite2 = lite2.getCluster().getLocalMember().equals(result);
    assertTrue(executedOnLite1 || executedOnLite2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 92 with IExecutorService

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

the class ExecutorServiceLiteMemberTest method test_submitCallableWithCallback_onLiteMembers.

@Test
public void test_submitCallableWithCallback_onLiteMembers() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance other = factory.newHazelcastInstance();
    final ResultHoldingMultiExecutionCallback callback = new ResultHoldingMultiExecutionCallback();
    final IExecutorService executor = other.getExecutorService(randomString());
    executor.submitToMembers(new LocalMemberReturningCallable(), LITE_MEMBER_SELECTOR, callback);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final Map<Member, Object> results = callback.getResults();
            assertNotNull(results);
            final Member liteMember1 = lite1.getCluster().getLocalMember();
            final Member liteMember2 = lite2.getCluster().getLocalMember();
            assertEquals(liteMember1, results.get(liteMember1));
            assertEquals(liteMember2, results.get(liteMember2));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) IMap(com.hazelcast.core.IMap) Map(java.util.Map) Member(com.hazelcast.core.Member) 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)

Example 93 with IExecutorService

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

the class ExecutorServiceLiteMemberTest method test_submitCallable_onLiteMember.

@Test
public void test_submitCallable_onLiteMember() throws ExecutionException, InterruptedException {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance other = factory.newHazelcastInstance();
    final IExecutorService executor = other.getExecutorService(randomString());
    final Future<Member> future = executor.submit(new LocalMemberReturningCallable(), LITE_MEMBER_SELECTOR);
    final Member executedMember = future.get();
    final boolean executedOnLite1 = lite1.getCluster().getLocalMember().equals(executedMember);
    final boolean executedOnLite2 = lite2.getCluster().getLocalMember().equals(executedMember);
    assertTrue(executedOnLite1 || executedOnLite2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 94 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() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance();
    final String name = randomString();
    final IExecutorService executor = instance.getExecutorService(name);
    executor.execute(new ResultSettingRunnable(name), LITE_MEMBER_SELECTOR);
}
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)

Example 95 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 TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance other = factory.newHazelcastInstance();
    final String name = randomString();
    final IExecutorService executor = other.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 : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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

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