Search in sources :

Example 1 with MockNodeContext

use of com.hazelcast.test.mocknetwork.MockNodeContext in project hazelcast by hazelcast.

the class ClientAuthenticationTest method testAuthentication_with_mcModeEnabled_when_clusterStart_isNotComplete.

@Test
public void testAuthentication_with_mcModeEnabled_when_clusterStart_isNotComplete() {
    HazelcastInstanceFactory.newHazelcastInstance(new Config(), randomName(), new MockNodeContext(hazelcastFactory.getRegistry(), hazelcastFactory.nextAddress()) {

        @Override
        public NodeExtension createNodeExtension(Node node) {
            return new DefaultNodeExtension(node) {

                @Override
                public boolean isStartCompleted() {
                    return false;
                }
            };
        }
    });
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(MC_CLIENT_MODE_PROP.getName(), "true");
    // if the client is able to connect, it's a pass
    hazelcastFactory.newHazelcastClient(clientConfig);
}
Also used : DefaultNodeExtension(com.hazelcast.instance.impl.DefaultNodeExtension) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) Node(com.hazelcast.instance.impl.Node) NodeExtension(com.hazelcast.instance.impl.NodeExtension) DefaultNodeExtension(com.hazelcast.instance.impl.DefaultNodeExtension) ClientConfig(com.hazelcast.client.config.ClientConfig) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with MockNodeContext

use of com.hazelcast.test.mocknetwork.MockNodeContext in project hazelcast by hazelcast.

the class InternalPartitionServiceImplTest method setup.

@Before
public void setup() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    NodeContext nodeContext = new MockNodeContext(factory.getRegistry(), factory.nextAddress()) {

        @Override
        public NodeExtension createNodeExtension(Node node) {
            return new DefaultNodeExtension(node) {

                @Override
                public boolean isStartCompleted() {
                    return startupDone.get();
                }
            };
        }
    };
    instance = HazelcastInstanceFactory.newHazelcastInstance(new Config(), randomName(), nodeContext);
    partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
    localMember = getClusterService(instance).getLocalMember();
    partitionCount = partitionService.getPartitionCount();
}
Also used : DefaultNodeExtension(com.hazelcast.instance.impl.DefaultNodeExtension) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) NodeContext(com.hazelcast.instance.impl.NodeContext) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.impl.Node) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) Before(org.junit.Before)

Example 3 with MockNodeContext

use of com.hazelcast.test.mocknetwork.MockNodeContext in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method changeClusterState_shouldFail_whenStartupIsNotCompleted.

@Test
public void changeClusterState_shouldFail_whenStartupIsNotCompleted() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    AtomicBoolean startupDone = new AtomicBoolean(false);
    HazelcastInstance instance = HazelcastInstanceFactory.newHazelcastInstance(new Config(), randomName(), new MockNodeContext(factory.getRegistry(), new Address("127.0.0.1", 5555)) {

        @Override
        public NodeExtension createNodeExtension(Node node) {
            return new DefaultNodeExtension(node) {

                @Override
                public boolean isStartCompleted() {
                    return startupDone.get() && super.isStartCompleted();
                }
            };
        }
    });
    try {
        instance.getCluster().changeClusterState(ClusterState.FROZEN);
        fail("Should not be able to change cluster state when startup is not completed yet!");
    } catch (IllegalStateException expected) {
    }
    startupDone.set(true);
    instance.getCluster().changeClusterState(ClusterState.FROZEN);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultNodeExtension(com.hazelcast.instance.impl.DefaultNodeExtension) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) NodeExtension(com.hazelcast.instance.impl.NodeExtension) DefaultNodeExtension(com.hazelcast.instance.impl.DefaultNodeExtension) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

Config (com.hazelcast.config.Config)3 DefaultNodeExtension (com.hazelcast.instance.impl.DefaultNodeExtension)3 Node (com.hazelcast.instance.impl.Node)3 MockNodeContext (com.hazelcast.test.mocknetwork.MockNodeContext)3 NodeExtension (com.hazelcast.instance.impl.NodeExtension)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 Test (org.junit.Test)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 Address (com.hazelcast.cluster.Address)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 NodeContext (com.hazelcast.instance.impl.NodeContext)1 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)1 Accessors.getNode (com.hazelcast.test.Accessors.getNode)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Before (org.junit.Before)1