Search in sources :

Example 1 with BasicTestCallable

use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceTest method test_whenRingBufferIsFull_thenClientDurableExecutorServiceCompletedFutureIsReturned.

@Test
public void test_whenRingBufferIsFull_thenClientDurableExecutorServiceCompletedFutureIsReturned() throws Exception {
    final AtomicBoolean onResponse = new AtomicBoolean();
    final CountDownLatch onFailureLatch = new CountDownLatch(1);
    String key = randomString();
    DurableExecutorService service = client.getDurableExecutorService(SINGLE_TASK + randomString());
    service.submitToKeyOwner(new SleepingTask(100), key);
    DurableExecutorServiceFuture<String> future = service.submitToKeyOwner(new BasicTestCallable(), key);
    future.andThen(new ExecutionCallback<String>() {

        @Override
        public void onResponse(String response) {
            onResponse.set(true);
        }

        @Override
        public void onFailure(Throwable t) {
            onFailureLatch.countDown();
        }
    });
    try {
        future.get(1, TimeUnit.HOURS);
        fail("We expected that future.get() throws an ExecutionException!");
    } catch (ExecutionException ignored) {
    }
    // assert TaskId
    try {
        future.getTaskId();
        fail("We expected that future.getTaskId() throws an IllegalStateException!");
    } catch (IllegalStateException ignored) {
    }
    // assert states of ClientDurableExecutorServiceCompletedFuture
    assertFalse(future.cancel(false));
    assertFalse(future.cancel(true));
    assertFalse(future.isCancelled());
    assertTrue(future.isDone());
    // assert that onFailure() has been called and not onResponse()
    onFailureLatch.await();
    assertFalse(onResponse.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with BasicTestCallable

use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceTest method testFullRingBuffer_WithExecutionCallback.

public void testFullRingBuffer_WithExecutionCallback() throws InterruptedException {
    String key = randomString();
    DurableExecutorService service = client.getDurableExecutorService(SINGLE_TASK + randomString());
    service.submitToKeyOwner(new SleepingTask(100), key);
    DurableExecutorServiceFuture<String> future = service.submitToKeyOwner(new BasicTestCallable(), key);
    final CountDownLatch latch = new CountDownLatch(1);
    future.andThen(new ExecutionCallback<String>() {

        @Override
        public void onResponse(String response) {
        }

        @Override
        public void onFailure(Throwable t) {
            if (t.getCause() instanceof RejectedExecutionException) {
                latch.countDown();
            }
        }
    });
    assertOpenEventually(latch);
    assertTrue(future.isDone());
    assertFalse(future.cancel(true));
    assertFalse(future.isCancelled());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with BasicTestCallable

use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceTest method testInvokeAll_WithTimeout.

@Test
public void testInvokeAll_WithTimeout() throws Exception {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    List<BasicTestCallable> callables = Collections.emptyList();
    expectedException.expect(UnsupportedOperationException.class);
    service.invokeAll(callables, 1, TimeUnit.SECONDS);
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with BasicTestCallable

use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.

the class ClientDurableRetrieveResultTest method testRetrieve_WhenResultOverwritten.

@Test
public void testRetrieve_WhenResultOverwritten() throws Exception {
    String name = randomString();
    DurableExecutorService executorService = client.getDurableExecutorService(name);
    DurableExecutorServiceFuture<String> future = executorService.submitToKeyOwner(new BasicTestCallable(), name);
    long taskId = future.getTaskId();
    future.get();
    for (int i = 0; i < DEFAULT_RING_BUFFER_CAPACITY; i++) {
        executorService.submitToKeyOwner(new BasicTestCallable(), name);
    }
    Future<Object> resultFuture = executorService.retrieveResult(taskId);
    try {
        resultFuture.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof StaleTaskIdException);
    }
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) StaleTaskIdException(com.hazelcast.durableexecutor.StaleTaskIdException) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with BasicTestCallable

use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.

the class ClientDurableRetrieveResultTest method testDisposeResult.

@Test
public void testDisposeResult() throws Exception {
    String name = randomString();
    String key = generateKeyOwnedBy(instance1);
    DurableExecutorService executorService = client.getDurableExecutorService(name);
    BasicTestCallable task = new BasicTestCallable();
    DurableExecutorServiceFuture<String> future = executorService.submitToKeyOwner(task, key);
    future.get();
    executorService.disposeResult(future.getTaskId());
    Future<Object> resultFuture = executorService.retrieveResult(future.getTaskId());
    assertNull(resultFuture.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)9 BasicTestCallable (com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)5 SleepingTask (com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 StaleTaskIdException (com.hazelcast.durableexecutor.StaleTaskIdException)1 RootCauseMatcher (com.hazelcast.util.RootCauseMatcher)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1