use of com.hazelcast.instance.TestNodeContext in project hazelcast by hazelcast.
the class AbstractOutOfMemoryHandlerTest method initHazelcastInstances.
protected void initHazelcastInstances() throws Exception {
Config config = new Config();
NodeContext nodeContext = new TestNodeContext();
NodeContext nodeContextWithThrowable = new TestNodeContext(new FailingServer());
int instanceId = INSTANCE_ID_COUNTER.incrementAndGet();
String instanceName = "OutOfMemoryHandlerHelper" + instanceId;
String instanceThrowsExceptionName = "OutOfMemoryHandlerHelperThrowsException" + instanceId;
hazelcastInstance = new HazelcastInstanceImpl(instanceName, config, nodeContext);
hazelcastInstanceThrowsException = new HazelcastInstanceImpl(instanceThrowsExceptionName, config, nodeContextWithThrowable);
}
use of com.hazelcast.instance.TestNodeContext 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(true);
return nodeExtension;
}
};
Config config = new Config();
config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false);
hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
try {
hazelcastInstance.getLifecycleService().terminate();
} catch (ExpectedRuntimeException expected) {
hazelcastInstance.getLifecycleService().terminate();
throw expected;
}
}
use of com.hazelcast.instance.TestNodeContext in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeJoin.
@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failed_beforeJoin() throws Exception {
NodeContext context = new TestNodeContext() {
@Override
public NodeExtension createNodeExtension(Node node) {
NodeExtension nodeExtension = super.createNodeExtension(node);
doThrow(new ExpectedRuntimeException()).when(nodeExtension).beforeJoin();
return nodeExtension;
}
};
Config config = new Config();
config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false);
hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
use of com.hazelcast.instance.TestNodeContext in project hazelcast by hazelcast.
the class NodeExtensionTest method verifyMethods.
@Test
public void verifyMethods() throws Exception {
TestNodeContext nodeContext = new TestNodeContext();
NodeExtension nodeExtension = nodeContext.getNodeExtension();
hazelcastInstance = new HazelcastInstanceImpl(randomName(), getConfig(), nodeContext);
InOrder inOrder = inOrder(nodeExtension);
inOrder.verify(nodeExtension, times(1)).printNodeInfo();
inOrder.verify(nodeExtension, times(1)).beforeStart();
inOrder.verify(nodeExtension, times(1)).createSerializationService();
inOrder.verify(nodeExtension, times(1)).createExtensionServices();
inOrder.verify(nodeExtension, times(1)).beforeJoin();
inOrder.verify(nodeExtension, times(1)).afterStart();
hazelcastInstance.shutdown();
inOrder.verify(nodeExtension, times(1)).beforeShutdown(false);
inOrder.verify(nodeExtension, times(1)).shutdown();
}
use of com.hazelcast.instance.TestNodeContext in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeNodeStart.
@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failed_beforeNodeStart() throws Exception {
NodeContext context = new TestNodeContext() {
@Override
public NodeExtension createNodeExtension(Node node) {
NodeExtension nodeExtension = super.createNodeExtension(node);
doThrow(new ExpectedRuntimeException()).when(nodeExtension).beforeStart();
return nodeExtension;
}
};
Config config = new Config();
config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false);
hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Aggregations