Search in sources :

Example 1 with RootCauseMatcher

use of com.hazelcast.util.RootCauseMatcher in project hazelcast by hazelcast.

the class LoggingScheduledExecutorTest method throwsExecutionException_withCallable_withFutureGetTimeout.

@Test
public void throwsExecutionException_withCallable_withFutureGetTimeout() throws Exception {
    executor = new LoggingScheduledExecutor(logger, 1, factory);
    Future<Integer> future = executor.submit(new FailedCallable());
    expectedException.expect(new RootCauseMatcher(RuntimeException.class));
    future.get(1, SECONDS);
    assertNull(logger.getThrowable());
}
Also used : RootCauseMatcher(com.hazelcast.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with RootCauseMatcher

use of com.hazelcast.util.RootCauseMatcher in project hazelcast by hazelcast.

the class LoggingScheduledExecutorTest method throwsExecutionException_withCallable.

@Test
public void throwsExecutionException_withCallable() throws Exception {
    executor = new LoggingScheduledExecutor(logger, 1, factory);
    Future<Integer> future = executor.submit(new FailedCallable());
    expectedException.expect(new RootCauseMatcher(RuntimeException.class));
    future.get();
    assertNull(logger.getThrowable());
}
Also used : RootCauseMatcher(com.hazelcast.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with RootCauseMatcher

use of com.hazelcast.util.RootCauseMatcher in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method getErroneous.

@Test
public void getErroneous() throws InterruptedException, ExecutionException {
    int delay = 2;
    String taskName = "Test";
    String completionLatchName = "completionLatch";
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    ICountDownLatch latch = instances[1].getCountDownLatch(completionLatchName);
    latch.trySetCount(1);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
    latch.await(10, SECONDS);
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) RootCauseMatcher(com.hazelcast.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with RootCauseMatcher

use of com.hazelcast.util.RootCauseMatcher in project hazelcast by hazelcast.

the class TargetTest method testConstructor_withInvalidPartitionId.

@Test
public void testConstructor_withInvalidPartitionId() throws Exception {
    // retrieve the wanted constructor and make it accessible
    Constructor<Target> constructor = Target.class.getDeclaredConstructor(Target.TargetFlag.class, Integer.class);
    constructor.setAccessible(true);
    // we expect an IllegalArgumentException to be thrown
    rule.expect(new RootCauseMatcher(IllegalArgumentException.class));
    constructor.newInstance(Target.TargetFlag.PARTITION_OWNER, null);
}
Also used : RootCauseMatcher(com.hazelcast.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with RootCauseMatcher

use of com.hazelcast.util.RootCauseMatcher in project hazelcast by hazelcast.

the class ScheduledExecutorServiceBasicTest method schedule_getHandlerDisposeThenRecreateFutureAndGet.

@Test
public void schedule_getHandlerDisposeThenRecreateFutureAndGet() throws ExecutionException, InterruptedException {
    int delay = 1;
    String taskName = "Test";
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture<Double> first = executorService.schedule(named(taskName, new PlainCallableTask()), delay, SECONDS);
    ScheduledTaskHandler handler = first.getHandler();
    first.dispose();
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(StaleTaskException.class));
    executorService.getScheduledFuture(handler).get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RootCauseMatcher(com.hazelcast.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 RootCauseMatcher (com.hazelcast.util.RootCauseMatcher)9 Test (org.junit.Test)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ICountDownLatch (com.hazelcast.core.ICountDownLatch)2 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)2 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)2 FailingCallable (com.hazelcast.client.executor.tasks.FailingCallable)1 PartitioningStrategyConfig (com.hazelcast.config.PartitioningStrategyConfig)1 BasicTestCallable (com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable)1 SleepingTask (com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1