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);
}
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));
}
});
}
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);
}
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);
}
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);
}
});
}
Aggregations