use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeNodeShutdown.
@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failed_beforeNodeShutdown() throws Exception {
NodeContext context = new TestNodeContext() {
@Override
public NodeExtension createNodeExtension(Node node) {
NodeExtension nodeExtension = super.createNodeExtension(node);
doAnswer(new Answer() {
final AtomicBoolean throwException = new AtomicBoolean(false);
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (throwException.compareAndSet(false, true)) {
throw new ExpectedRuntimeException();
}
return null;
}
}).when(nodeExtension).beforeShutdown();
return nodeExtension;
}
};
Config config = new Config();
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
try {
hazelcastInstance.getLifecycleService().terminate();
} catch (ExpectedRuntimeException expected) {
hazelcastInstance.getLifecycleService().terminate();
throw expected;
}
}
use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method test_NewInstance_failed_afterNodeStart.
@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failed_afterNodeStart() throws Exception {
NodeContext context = new TestNodeContext() {
@Override
public NodeExtension createNodeExtension(Node node) {
NodeExtension nodeExtension = super.createNodeExtension(node);
doThrow(new ExpectedRuntimeException()).when(nodeExtension).afterStart();
return nodeExtension;
}
};
Config config = new Config();
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.
the class NonBlockingIOThreadAbstractTest method whenHandlerThrowException_thenHandlerOnFailureCalledWithThatException.
@Test
public void whenHandlerThrowException_thenHandlerOnFailureCalledWithThatException() throws Exception {
startThread();
SelectionKey selectionKey = mock(SelectionKey.class);
selectionKey.attach(handler);
when(selectionKey.isValid()).thenReturn(true);
doThrow(new ExpectedRuntimeException()).when(handler).handle();
selector.scheduleSelectAction(selectionKey);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
verify(handler).onFailure(isA(ExpectedRuntimeException.class));
}
});
assertStillRunning();
}
use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.
the class AsyncInboundResponseHandlerTest method whenPacketThrowsException.
@Test
public void whenPacketThrowsException() throws Exception {
final Packet badPacket = new Packet(serializationService.toBytes(new NormalResponse("bad", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
final Packet goodPacket = new Packet(serializationService.toBytes(new NormalResponse("good", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
doThrow(new ExpectedRuntimeException()).when(responsePacketHandler).handle(badPacket);
asyncHandler.handle(badPacket);
asyncHandler.handle(goodPacket);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
verify(responsePacketHandler).handle(goodPacket);
}
});
}
use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.
the class ClientDelegatingFutureTest_CompletionStageTest method newCompletableFuture.
@Override
protected CompletableFuture<Object> newCompletableFuture(boolean exceptional, long completeAfterMillis) {
invocation.getCallIdSequence().next();
ClientInvocationFuture cf = invocation.getClientInvocationFuture();
ClientDelegatingFuture<Object> future = new ClientDelegatingFuture<>(cf, serializationService, MapGetCodec::decodeResponse);
Executor completionExecutor;
if (completeAfterMillis <= 0) {
completionExecutor = CALLER_RUNS;
} else {
completionExecutor = command -> new Thread(() -> {
sleepAtLeastMillis(completeAfterMillis);
command.run();
}, "test-completion-thread").start();
}
if (exceptional) {
completionExecutor.execute(() -> invocation.completeExceptionally(new ExpectedRuntimeException()));
} else {
completionExecutor.execute(completeNormally(invocation));
}
return future;
}
Aggregations