Search in sources :

Example 1 with NodeContext

use of com.hazelcast.instance.NodeContext 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);
    thisAddress = getNode(instance).getThisAddress();
    partitionCount = partitionService.getPartitionCount();
}
Also used : DefaultNodeExtension(com.hazelcast.instance.DefaultNodeExtension) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) NodeContext(com.hazelcast.instance.NodeContext) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) Before(org.junit.Before)

Example 2 with NodeContext

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

the class TestHazelcastInstanceFactory method newHazelcastInstance.

/**
     * Creates a new test Hazelcast instance which is only allowed to connect to specified addresses:
     * <ul>
     *     <li>{@code blockedAddresses} are blacklisted in its {@code MockJoiner}</li>
     *     <li>connections to {@code blockedAddresses} are blocked by its {@code FirewallingConnectionManager}</li>
     * </ul>
     * This is handy in split-brain tests, when a new instance should be started on a specific network partition
     * of the split brain.
     *
     * @param address           the address to use as Member's address; if {@code null}, then uses the next address
     * @param config            the config to use; use {@code null} to get the default config
     * @param blockedAddresses  addresses to which the new instance is allowed to communicate
     */
public HazelcastInstance newHazelcastInstance(Address address, Config config, Address[] blockedAddresses) {
    final String instanceName = config != null ? config.getInstanceName() : null;
    final Address thisAddress = address != null ? address : nextAddress();
    if (mockNetwork) {
        config = initOrCreateConfig(config);
        NodeContext nodeContext = registry.createNodeContext(thisAddress, blockedAddresses == null ? EMPTY_SET : new HashSet<Address>(Arrays.asList(blockedAddresses)));
        return HazelcastInstanceFactory.newHazelcastInstance(config, instanceName, nodeContext);
    }
    throw new UnsupportedOperationException("Explicit address is only available for mock network setup!");
}
Also used : Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) NodeContext(com.hazelcast.instance.NodeContext) HashSet(java.util.HashSet)

Example 3 with NodeContext

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

the class TestHazelcastInstanceFactory method newHazelcastInstance.

/**
     * Creates a new test Hazelcast instance.
     *
     * @param config the config to use; use {@code null} to get the default config
     */
public HazelcastInstance newHazelcastInstance(Config config) {
    String instanceName = config != null ? config.getInstanceName() : null;
    if (mockNetwork) {
        config = initOrCreateConfig(config);
        NodeContext nodeContext = registry.createNodeContext(nextAddress());
        return HazelcastInstanceFactory.newHazelcastInstance(config, instanceName, nodeContext);
    }
    return HazelcastInstanceFactory.newHazelcastInstance(config);
}
Also used : NodeContext(com.hazelcast.instance.NodeContext)

Example 4 with NodeContext

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

the class TestHazelcastInstanceFactory method newHazelcastInstance.

/**
     * Creates a new test Hazelcast instance.
     *
     * @param address the address to use as Member's address instead of picking the next address
     * @param config  the config to use; use {@code null} to get the default config
     */
public HazelcastInstance newHazelcastInstance(Address address, Config config) {
    final String instanceName = config != null ? config.getInstanceName() : null;
    if (mockNetwork) {
        config = initOrCreateConfig(config);
        NodeContext nodeContext = registry.createNodeContext(address);
        return HazelcastInstanceFactory.newHazelcastInstance(config, instanceName, nodeContext);
    }
    throw new UnsupportedOperationException("Explicit address is only available for mock network setup!");
}
Also used : NodeContext(com.hazelcast.instance.NodeContext)

Aggregations

NodeContext (com.hazelcast.instance.NodeContext)4 Config (com.hazelcast.config.Config)1 DefaultNodeExtension (com.hazelcast.instance.DefaultNodeExtension)1 Node (com.hazelcast.instance.Node)1 Address (com.hazelcast.nio.Address)1 HazelcastTestSupport.getAddress (com.hazelcast.test.HazelcastTestSupport.getAddress)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 MockNodeContext (com.hazelcast.test.mocknetwork.MockNodeContext)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1