use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testClusterMerge_when_split_not_detected_by_master.
private void testClusterMerge_when_split_not_detected_by_master(boolean multicastEnabled) throws InterruptedException {
Config config = new Config();
String groupName = generateRandomString(10);
config.getGroupConfig().setName(groupName);
config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "15");
config.setProperty(GroupProperty.MAX_JOIN_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MAX_JOIN_MERGE_TARGET_SECONDS.getName(), "10");
NetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.getJoin().getMulticastConfig().setEnabled(multicastEnabled);
networkConfig.getJoin().getTcpIpConfig().setEnabled(!multicastEnabled).addMember("127.0.0.1");
HazelcastInstance hz1 = newHazelcastInstance(config, "test-node1", new FirewallingNodeContext());
HazelcastInstance hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
HazelcastInstance hz3 = newHazelcastInstance(config, "test-node3", new FirewallingNodeContext());
final Node n1 = TestUtil.getNode(hz1);
Node n2 = TestUtil.getNode(hz2);
Node n3 = TestUtil.getNode(hz3);
final CountDownLatch splitLatch = new CountDownLatch(2);
MembershipAdapter membershipAdapter = new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent event) {
if (n1.getLocalMember().equals(event.getMember())) {
splitLatch.countDown();
}
}
};
hz2.getCluster().addMembershipListener(membershipAdapter);
hz3.getCluster().addMembershipListener(membershipAdapter);
final CountDownLatch mergeLatch = new CountDownLatch(1);
hz1.getLifecycleService().addLifecycleListener(new MergedEventLifeCycleListener(mergeLatch));
FirewallingTcpIpConnectionManager cm1 = getFireWalledConnectionManager(hz1);
FirewallingTcpIpConnectionManager cm2 = getFireWalledConnectionManager(hz2);
FirewallingTcpIpConnectionManager cm3 = getFireWalledConnectionManager(hz3);
// block n2 & n3 on n1
cm1.block(n2.address);
cm1.block(n3.address);
// remove and block n1 on n2 & n3
n2.clusterService.removeAddress(n1.address, null);
n3.clusterService.removeAddress(n1.address, null);
cm2.block(n1.address);
cm3.block(n1.address);
assertTrue(splitLatch.await(120, TimeUnit.SECONDS));
assertEquals(3, hz1.getCluster().getMembers().size());
assertEquals(2, hz2.getCluster().getMembers().size());
assertEquals(2, hz3.getCluster().getMembers().size());
// unblock n2 on n1 and n1 on n2 & n3
// n1 still blocks access to n3
cm1.unblock(n2.address);
cm2.unblock(n1.address);
cm3.unblock(n1.address);
assertTrue(mergeLatch.await(120, TimeUnit.SECONDS));
assertEquals(3, hz1.getCluster().getMembers().size());
assertEquals(3, hz2.getCluster().getMembers().size());
assertEquals(3, hz3.getCluster().getMembers().size());
assertEquals(n2.getThisAddress(), n1.getMasterAddress());
assertEquals(n2.getThisAddress(), n2.getMasterAddress());
assertEquals(n2.getThisAddress(), n3.getMasterAddress());
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class MemberListTest method testOutOfSyncMemberList.
/*
* Sets up a situation where node3 removes the master and sets node2 as the
* master but none of the other nodes do. This means that node3 thinks node2
* is master but node2 thinks node1 is master.
*/
@Test
public void testOutOfSyncMemberList() throws Exception {
List<HazelcastInstance> instanceList = buildInstances(3, 25701);
final HazelcastInstance h1 = instanceList.get(0);
final HazelcastInstance h2 = instanceList.get(1);
final HazelcastInstance h3 = instanceList.get(2);
// All three nodes join into one cluster
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
// This simulates each node reading from the other nodes in the list at regular intervals
// This prevents the heart beat code from timing out
final HazelcastInstance[] instances = new HazelcastInstance[] { h1, h2, h3 };
final AtomicBoolean doingWork = new AtomicBoolean(true);
Thread[] workThreads = new Thread[instances.length];
for (int i = 0; i < instances.length; i++) {
final int threadNum = i;
workThreads[threadNum] = new Thread(new Runnable() {
public void run() {
while (doingWork.get()) {
final HazelcastInstance hz = instances[threadNum];
Set<Member> members = new HashSet<Member>(hz.getCluster().getMembers());
members.remove(hz.getCluster().getLocalMember());
final Map<Member, Future<String>> futures = hz.getExecutorService("test").submitToMembers(new PingCallable(), members);
for (Future<String> f : futures.values()) {
try {
f.get();
} catch (MemberLeftException ignored) {
} catch (Exception e) {
e.printStackTrace();
}
}
sleepSeconds(2);
}
}
});
workThreads[threadNum].start();
}
final Node n3 = TestUtil.getNode(h3);
n3.clusterService.removeAddress(h1.getCluster().getLocalMember().getAddress(), null);
// Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
sleepSeconds(30);
doingWork.set(false);
for (Thread t : workThreads) {
t.join();
}
assertClusterSize(3, h1);
assertClusterSize(3, h2);
assertClusterSize(3, h3);
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class MemberListTest method testOutOfSyncMemberListTwoMasters.
/*
* Sets up a situation where the member list is out of order on node2. Both
* node2 and node1 think they are masters and both think each other are in
* their clusters.
*/
@Test
public void testOutOfSyncMemberListTwoMasters() throws Exception {
List<HazelcastInstance> instanceList = buildInstances(3, 35701);
final HazelcastInstance h1 = instanceList.get(0);
final HazelcastInstance h2 = instanceList.get(1);
final HazelcastInstance h3 = instanceList.get(2);
final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
final MemberImpl m3 = (MemberImpl) h3.getCluster().getLocalMember();
// All three nodes join into one cluster
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
final Node n2 = TestUtil.getNode(h2);
// Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
List<MemberInfo> members = new ArrayList<MemberInfo>();
members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
members.add(new MemberInfo(m3.getAddress(), m3.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
n2.clusterService.updateMembers(members, n2.getMasterAddress());
n2.setMasterAddress(m2.getAddress());
// Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
sleepSeconds(30);
assertMasterEquals(m1, h1);
assertMasterEquals(m1, h2);
assertMasterEquals(m1, h3);
assertClusterSize(3, h1);
assertClusterSize(3, h2);
assertClusterSize(3, h3);
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class MemberListTest method testSameMasterDifferentMemberList.
/*
* Sets up situation where all nodes have the same master, but node 2's list
* doesn't contain node 3.
*/
@Test
public void testSameMasterDifferentMemberList() throws Exception {
List<HazelcastInstance> instanceList = buildInstances(3, 45701);
final HazelcastInstance h1 = instanceList.get(0);
final HazelcastInstance h2 = instanceList.get(1);
final HazelcastInstance h3 = instanceList.get(2);
final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
// All three nodes join into one cluster
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
final Node n2 = TestUtil.getNode(h2);
// Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
List<MemberInfo> members = new ArrayList<MemberInfo>();
members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
n2.clusterService.updateMembers(members, n2.getMasterAddress());
// Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
sleepSeconds(30);
assertMasterEquals(m1, h1);
assertMasterEquals(m1, h2);
assertMasterEquals(m1, h3);
assertClusterSize(3, h1);
assertClusterSize(3, h2);
assertClusterSize(3, h3);
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.
@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
HazelcastInstance instance = factory.newHazelcastInstance();
factory.newHazelcastClient();
factory.newHazelcastClient();
Node node = TestUtil.getNode(instance);
Operation operation = new GetConnectedClientsOperation();
OperationService operationService = node.nodeEngine.getOperationService();
Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
Map<String, ClientType> clients = future.get();
assertEquals(2, clients.size());
}
Aggregations