Search in sources :

Example 96 with IExecutorService

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

the class ExecutorServiceTest method test_registerCallback_beforeFutureIsCompletedOnOtherNode.

@Test
public void test_registerCallback_beforeFutureIsCompletedOnOtherNode() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    assertTrue(instance1.getCountDownLatch("latch").trySetCount(1));
    String name = randomString();
    IExecutorService executorService = instance2.getExecutorService(name);
    ICountDownLatchAwaitCallable task = new ICountDownLatchAwaitCallable("latch");
    String key = generateKeyOwnedBy(instance1);
    ICompletableFuture<Boolean> future = (ICompletableFuture<Boolean>) executorService.submitToKeyOwner(task, key);
    CountingDownExecutionCallback<Boolean> callback = new CountingDownExecutionCallback<Boolean>(1);
    future.andThen(callback);
    instance1.getCountDownLatch("latch").countDown();
    assertTrue(future.get());
    assertOpenEventually(callback.getLatch());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICompletableFuture(com.hazelcast.core.ICompletableFuture) 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 97 with IExecutorService

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

the class ExecutorServiceCancelTest method testGetValueAfterCancel_submitToMember.

private void testGetValueAfterCancel_submitToMember(HazelcastInstance instance, Member member) throws Exception {
    IExecutorService executorService = instance.getExecutorService(randomString());
    Future<Boolean> future = executorService.submitToMember(new SleepingTask(Integer.MAX_VALUE, taskStartedLatchName), member);
    awaitTaskStart();
    future.cancel(true);
    future.get(10, TimeUnit.SECONDS);
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService)

Example 98 with IExecutorService

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

the class ExecutorServiceCancelTest method testCancel_submitToKeyOwner.

@Test
public void testCancel_submitToKeyOwner() throws ExecutionException, InterruptedException {
    IExecutorService executorService = localHz.getExecutorService(randomString());
    Future<Boolean> future = executorService.submitToKeyOwner(new SleepingTask(Integer.MAX_VALUE, taskStartedLatchName), randomString());
    awaitTaskStart();
    boolean cancelled = future.cancel(true);
    assertTrue(cancelled);
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 99 with IExecutorService

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

the class ExecutorServiceCancelTest method testGetValueAfterCancel_submitToKeyOwner.

@Test(expected = CancellationException.class)
public void testGetValueAfterCancel_submitToKeyOwner() throws Exception {
    IExecutorService executorService = localHz.getExecutorService(randomString());
    Future<Boolean> future = executorService.submitToKeyOwner(new SleepingTask(Integer.MAX_VALUE, taskStartedLatchName), randomString());
    awaitTaskStart();
    future.cancel(true);
    future.get(10, TimeUnit.SECONDS);
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 100 with IExecutorService

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

the class ClientRegressionWithMockNetworkTest method testGithubIssue3557.

@Test(expected = ExecutionException.class, timeout = 120000)
public void testGithubIssue3557() throws Exception {
    HazelcastInstance hz = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    UnDeserializable unDeserializable = new UnDeserializable(1);
    IExecutorService executorService = client.getExecutorService("default");
    Issue2509Runnable task = new Issue2509Runnable(unDeserializable);
    Future<?> future = executorService.submitToMember(task, hz.getCluster().getLocalMember());
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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