Search in sources :

Example 11 with IExecutorService

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

the class SmallClusterTest method submitToAllMembers_runnable.

@Test
public void submitToAllMembers_runnable() {
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToAllMembersRunnable");
        service.submitToAllMembers(new IncrementAtomicLongRunnable("testSubmitToAllMembersRunnable"), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getAtomicLong("testSubmitToAllMembersRunnable");
    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 12 with IExecutorService

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

the class SmallClusterTest method submitToKeyOwner_callable_withCallback.

@Test(timeout = TEST_TIMEOUT)
public void submitToKeyOwner_callable_withCallback() {
    BooleanSuccessResponseCountingCallback callback = new BooleanSuccessResponseCountingCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerCallable");
        Member localMember = instance.getCluster().getLocalMember();
        int key = findNextKeyForMember(instance, localMember);
        service.submitToKeyOwner(new MemberUUIDCheckCallable(localMember.getUuid()), key, 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)

Example 13 with IExecutorService

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

the class SmallClusterTest method executionCallback_notified.

@Test
public void executionCallback_notified() throws Exception {
    IExecutorService executorService = instances[1].getExecutorService(randomString());
    BasicTestCallable task = new BasicTestCallable();
    String key = generateKeyOwnedBy(instances[0]);
    ICompletableFuture<String> future = (ICompletableFuture<String>) executorService.submitToKeyOwner(task, key);
    CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<String>(1);
    future.andThen(callback);
    future.get();
    assertOpenEventually(callback.getLatch(), 10);
}
Also used : 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 14 with IExecutorService

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

the class SpecificSetupTest method operationTimeoutConfigProp.

@Test
public void operationTimeoutConfigProp() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    Config config = new Config();
    int timeoutSeconds = 3;
    config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(SECONDS.toMillis(timeoutSeconds)));
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    IExecutorService executor = hz1.getExecutorService(randomString());
    Future<Boolean> future = executor.submitToMember(new SleepingTask(3 * timeoutSeconds), hz2.getCluster().getLocalMember());
    Boolean result = future.get(1, MINUTES);
    assertTrue(result);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with IExecutorService

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

the class DistributedExecutorServiceTest method testExecutorConfigCache_whenUsedExecutorShutdown_thenConfigRemoved.

@Test
public void testExecutorConfigCache_whenUsedExecutorShutdown_thenConfigRemoved() throws Exception {
    final IExecutorService executorService = hz.getExecutorService(EXECUTOR_NAME);
    Future future = executorService.submit(new EmptyRunnable());
    future.get();
    executorService.shutdown();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(executorService.isShutdown());
        }
    });
    assertTrue("Executor config cache should not contain cached configuration for executor that was already shutdown", distributedExecutorService.executorConfigCache.isEmpty());
}
Also used : Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) 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