Search in sources :

Example 26 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method submitRunnable_withExecutionCallback.

@Test
public void submitRunnable_withExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(1);
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    MemberSelector selector = new SelectAllMembers();
    service.submit(runnable, selector, new ExecutionCallback() {

        public void onResponse(Object response) {
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    });
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(1, map.size());
}
Also used : IMap(com.hazelcast.core.IMap) MemberSelector(com.hazelcast.core.MemberSelector) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) SelectAllMembers(com.hazelcast.client.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with IExecutorService

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

the class ClientExecutorServiceTest method testGetFutureAfterCancel.

@Test(expected = CancellationException.class)
public void testGetFutureAfterCancel() throws InterruptedException, ExecutionException, TimeoutException {
    IExecutorService service = client.getExecutorService(randomString());
    CancellationAwareTask task = new CancellationAwareTask(Long.MAX_VALUE);
    Future future = service.submit(task);
    try {
        future.get(1, TimeUnit.SECONDS);
    } catch (TimeoutException ignored) {
    }
    future.cancel(true);
    future.get();
}
Also used : Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) CancellationAwareTask(com.hazelcast.client.executor.tasks.CancellationAwareTask) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with IExecutorService

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

the class ClientExecutorServiceTest method testSubmitFailingCallableReasonExceptionCause.

@Test(expected = IllegalStateException.class)
public void testSubmitFailingCallableReasonExceptionCause() throws Throwable {
    IExecutorService service = client.getExecutorService(randomString());
    Future<String> failingFuture = service.submit(new FailingCallable());
    try {
        failingFuture.get();
    } catch (ExecutionException e) {
        throw e.getCause();
    }
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) FailingCallable(com.hazelcast.client.executor.tasks.FailingCallable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with IExecutorService

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

the class ClientExecutorServiceTest method testShutdownMultipleTimes.

@Test
public void testShutdownMultipleTimes() throws InterruptedException, ExecutionException, TimeoutException {
    final IExecutorService service = client.getExecutorService(randomString());
    service.shutdownNow();
    service.shutdown();
    assertTrueEventually(new AssertTask() {

        public void run() throws Exception {
            assertTrue(service.isShutdown());
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with IExecutorService

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

the class ClientExecutorServiceTest method testCallableSerializedOnce_submitToAddress.

@Test
public void testCallableSerializedOnce_submitToAddress() throws ExecutionException, InterruptedException {
    String name = randomString();
    IExecutorService service = client.getExecutorService(name);
    SerializedCounterCallable counterCallable = new SerializedCounterCallable();
    Future future = service.submitToMember(counterCallable, instance.getCluster().getLocalMember());
    assertEquals(2, future.get());
}
Also used : Future(java.util.concurrent.Future) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) 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