Search in sources :

Example 1 with TestNodeContext

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);
}
Also used : TestNodeContext(com.hazelcast.instance.TestNodeContext) Config(com.hazelcast.config.Config) TestNodeContext(com.hazelcast.instance.TestNodeContext)

Example 2 with TestNodeContext

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;
    }
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) TestNodeContext(com.hazelcast.instance.TestNodeContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Config(com.hazelcast.config.Config) TestNodeContext(com.hazelcast.instance.TestNodeContext) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with TestNodeContext

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);
}
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 4 with TestNodeContext

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();
}
Also used : InOrder(org.mockito.InOrder) TestNodeContext(com.hazelcast.instance.TestNodeContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with TestNodeContext

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);
}
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)

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