use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.
the class PartitioningStrategyFactoryTest method whenStrategyInstantiationThrowsException_getPartitioningStrategy_rethrowsException.
// when an exception is thrown while attempting to instantiate a partitioning strategy
// then the exception is rethrown (the same if it is a RuntimeException, otherwise it is peeled,
// see ExceptionUtil.rethrow for all the details).
@Test
public void whenStrategyInstantiationThrowsException_getPartitioningStrategy_rethrowsException() {
PartitioningStrategyConfig cfg = new PartitioningStrategyConfig();
cfg.setPartitioningStrategyClass("NonExistentPartitioningStrategy");
// while attempting to get partitioning strategy, ClassNotFound exception will be thrown and wrapped in HazelcastException
expectedException.expect(new RootCauseMatcher(ClassNotFoundException.class));
// use a random UUID as map name, to avoid obtaining the PartitioningStrategy from cache.
partitioningStrategyFactory.getPartitioningStrategy(UUID.randomUUID().toString(), cfg);
}
use of com.hazelcast.internal.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.TargetMode.class, PartitionIdSet.class);
constructor.setAccessible(true);
// we expect an IllegalArgumentException to be thrown
rule.expect(new RootCauseMatcher(IllegalArgumentException.class));
constructor.newInstance(Target.TargetMode.PARTITION_OWNER, null);
}
use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getErroneous_durable.
@Test
public void getErroneous_durable() throws Exception {
int delay = 2;
String taskName = "Test";
String completionLatchName = "completionLatch";
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
latch.trySetCount(1);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
assertOpenEventually(latch);
instances[1].getLifecycleService().shutdown();
Thread.sleep(2000);
expected.expect(ExecutionException.class);
expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
future.get();
}
use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getErroneous.
@Test
public void getErroneous() throws Exception {
int delay = 2;
String taskName = "Test";
String completionLatchName = "completionLatch";
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
latch.trySetCount(1);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
assertOpenEventually(latch);
expected.expect(ExecutionException.class);
expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
future.get();
}
use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method exception_suppressesFutureExecutions.
@Test
public void exception_suppressesFutureExecutions() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(ANY_EXECUTOR_NAME);
final IScheduledFuture f = service.scheduleAtFixedRate(new ErroneousRunnableTask(), 1, 1, TimeUnit.SECONDS);
assertTrueEventually(() -> assertTrue(f.isDone()));
assertEquals(1L, f.getStats().getTotalRuns());
expected.expect(ExecutionException.class);
expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
f.get();
}
Aggregations