Search in sources :

Example 6 with TestNodeContext

use of com.hazelcast.instance.TestNodeContext 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().getAutoDetectionConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) TestNodeContext(com.hazelcast.instance.TestNodeContext) Config(com.hazelcast.config.Config) TestNodeContext(com.hazelcast.instance.TestNodeContext) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 7 with TestNodeContext

use of com.hazelcast.instance.TestNodeContext in project hazelcast by hazelcast.

the class HazelcastInstanceFactoryTest method test_NewInstance_terminateInstance_afterNodeStart.

@Test(expected = IllegalStateException.class)
public void test_NewInstance_terminateInstance_afterNodeStart() throws Exception {
    NodeContext context = new TestNodeContext() {

        @Override
        public NodeExtension createNodeExtension(final Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doAnswer(invocation -> {
                node.hazelcastInstance.shutdown();
                return null;
            }).when(nodeExtension).afterStart();
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : TestNodeContext(com.hazelcast.instance.TestNodeContext) Config(com.hazelcast.config.Config) TestNodeContext(com.hazelcast.instance.TestNodeContext) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

TestNodeContext (com.hazelcast.instance.TestNodeContext)7 Config (com.hazelcast.config.Config)6 Test (org.junit.Test)6 SlowTest (com.hazelcast.test.annotation.SlowTest)5 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 InOrder (org.mockito.InOrder)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1