use of com.hazelcast.instance.impl.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;
if (isMockNetwork) {
config = initOrCreateConfig(config);
Address thisAddress = address != null ? address : nextAddress(config.getNetworkConfig().getPort());
NodeContext nodeContext = registry.createNodeContext(thisAddress, blockedAddresses == null ? Collections.emptySet() : new HashSet<>(asList(blockedAddresses)));
HazelcastInstance hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, instanceName, nodeContext);
registerTestMetricsPublisher(hazelcastInstance);
return hazelcastInstance;
}
throw new UnsupportedOperationException("Explicit address is only available for mock network setup!");
}
use of com.hazelcast.instance.impl.NodeContext in project hazelcast by hazelcast.
the class CustomNodeExtensionTestInstanceFactory method newHazelcastInstance.
@Override
public HazelcastInstance newHazelcastInstance(Config config) {
String instanceName = config != null ? config.getInstanceName() : null;
NodeContext nodeContext;
if (TestEnvironment.isMockNetwork()) {
config = initOrCreateConfig(config);
nodeContext = this.registry.createNodeContext(this.nextAddress(config.getNetworkConfig().getPort()));
} else {
nodeContext = new DefaultNodeContext();
}
return HazelcastInstanceFactory.newHazelcastInstance(config, instanceName, new WanServiceMockingNodeContext(nodeContext, nodeExtensionFn));
}
use of com.hazelcast.instance.impl.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);
localMember = getClusterService(instance).getLocalMember();
partitionCount = partitionService.getPartitionCount();
}
use of com.hazelcast.instance.impl.NodeContext in project hazelcast by hazelcast.
the class MembershipUpdateTest method memberJoinsEventually_whenMemberRestartedWithSameUuid_butMasterDoesNotNoticeItsLeave.
@Test
public void memberJoinsEventually_whenMemberRestartedWithSameUuid_butMasterDoesNotNoticeItsLeave() throws Exception {
ruleStaleJoinPreventionDuration.setOrClearProperty("5");
Config configMaster = new Config();
HazelcastInstance hz1 = factory.newHazelcastInstance(configMaster);
HazelcastInstance hz2 = factory.newHazelcastInstance();
HazelcastInstance hz3 = factory.newHazelcastInstance();
assertClusterSizeEventually(3, hz2, hz3);
MemberImpl member3 = getNode(hz3).getLocalMember();
// A new member is restarted with member3's UUID.
// Then after some time, member3 is terminated.
// This is to emulate the case, member3 is restarted with preserving its UUID (using hot-restart),
// but master does not realize its leave in time.
// When master realizes, member3 is terminated,
// new member should eventually join the cluster.
Future<HazelcastInstance> future = spawn(() -> {
NodeContext nodeContext = new StaticMemberNodeContext(factory, member3.getUuid(), factory.nextAddress());
return newHazelcastInstance(initOrCreateConfig(new Config()), randomName(), nodeContext);
});
spawn(() -> {
sleepSeconds(5);
hz3.getLifecycleService().terminate();
});
HazelcastInstance hz4 = future.get();
assertClusterSize(3, hz1, hz4);
assertClusterSizeEventually(3, hz2);
}
use of com.hazelcast.instance.impl.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 (isMockNetwork) {
config = initOrCreateConfig(config);
NodeContext nodeContext = registry.createNodeContext(nextAddress(config.getNetworkConfig().getPort()));
HazelcastInstance hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, instanceName, nodeContext);
registerTestMetricsPublisher(hazelcastInstance);
return hazelcastInstance;
}
HazelcastInstance hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config);
registerTestMetricsPublisher(hazelcastInstance);
return hazelcastInstance;
}
Aggregations