use of org.goldenorb.client.OrbTrackerMemberData in project goldenorb by jzachr.
the class TestLeaderGroupMonitor method testInitializing.
/**
* Test initializing a monitor on a leader group that already contains members
*
* @throws OrbZKFailure
* @throws InterruptedException
*/
@Test
public void testInitializing() throws OrbZKFailure, InterruptedException {
int num_nodes = 10;
for (int i = 0; i < num_nodes; i++) {
OrbTrackerMember otm = new OrbTrackerMember();
otm.setAvailablePartitions(1);
otm.setHostname("abc");
otm.setInUsePartitions(1);
otm.setLeader(false);
otm.setPartitionCapacity(1);
otm.setPort(1);
otm.setReservedPartitions(1);
ZookeeperUtils.tryToCreateNode(zk, leaderGroupPath + "/member", otm, CreateMode.EPHEMERAL_SEQUENTIAL);
}
CountDownLatch latch = new CountDownLatch(num_nodes);
TServer server = new TServer(latch);
Map<String, OrbTrackerMemberData> map = server.getMemberData();
assertTrue(map.size() == 0);
new LeaderGroupMonitor(leaderGroupPath, server, zk);
latch.await();
map = server.getMemberData();
assertTrue(map.size() == num_nodes);
// ZookeeperUtils.recursiveDelete(zk, leaderGroupPath);
}
use of org.goldenorb.client.OrbTrackerMemberData in project goldenorb by jzachr.
the class TestLeaderGroupMonitor method testAddingNodes.
/**
* Test adding nodes to alreading initialized watcher
*
* @throws OrbZKFailure
* @throws InterruptedException
*/
@Test
public void testAddingNodes() throws OrbZKFailure, InterruptedException {
int num_nodes = 10;
CountDownLatch latch = new CountDownLatch(num_nodes);
TServer server = new TServer(latch);
Map<String, OrbTrackerMemberData> map = server.getMemberData();
assertTrue(map.size() == 0);
new LeaderGroupMonitor(leaderGroupPath, server, zk);
for (int i = 0; i < num_nodes; i++) {
OrbTrackerMember otm = new OrbTrackerMember();
otm.setAvailablePartitions(1);
otm.setHostname("abc");
otm.setInUsePartitions(1);
otm.setLeader(false);
otm.setPartitionCapacity(1);
otm.setPort(1);
otm.setReservedPartitions(1);
ZookeeperUtils.tryToCreateNode(zk, leaderGroupPath + "/member", otm, CreateMode.EPHEMERAL_SEQUENTIAL);
}
latch.await();
map = server.getMemberData();
assertEquals(num_nodes, map.size());
// adding five new nodes
latch = new CountDownLatch(5);
server.setLatcher(latch);
for (int i = 0; i < 5; i++) {
OrbTrackerMember otm = new OrbTrackerMember();
otm.setAvailablePartitions(1);
otm.setHostname("abc");
otm.setInUsePartitions(1);
otm.setLeader(false);
otm.setPartitionCapacity(1);
otm.setPort(1);
otm.setReservedPartitions(1);
ZookeeperUtils.tryToCreateNode(zk, leaderGroupPath + "/member", otm, CreateMode.EPHEMERAL_SEQUENTIAL);
}
latch.await();
map = server.getMemberData();
assertTrue(map.size() == num_nodes + 5);
}
use of org.goldenorb.client.OrbTrackerMemberData in project goldenorb by jzachr.
the class TestOrbTrackerMemberDataServiceImpl method testEveryThingChangingAtOnce.
@Test
public void testEveryThingChangingAtOnce() throws NodeDoesNotExistException, ZooKeeperConnectionException, WatcherException, InterruptedException, KeeperException {
CountDownLatch start = new CountDownLatch(1);
CountDownLatch allDone = new CountDownLatch(3);
int cycles = 10;
MemberThread[] threads = new MemberThread[3];
for (int i = 0; i < 3; i++) {
threads[i] = new MemberThread(i, cycles, start, allDone);
threads[i].start();
}
OrbTrackerMemberDataServiceImpl server = new OrbTrackerMemberDataServiceImpl();
// initialize watchers
CountDownLatch notUsed = new CountDownLatch(1);
server.enterTestingMode(notUsed, notUsed, notUsed);
String[] jobQueue = server.getJobsInQueue();
String[] jobsInProgress = server.getJobsInProgress();
OrbTrackerMemberData[] members = server.getOrbTrackerMemberData();
System.out.println("Start");
start.countDown();
allDone.await();
List<String> mem = zk.getChildren(leaderGroupPath, false);
List<String> jq = zk.getChildren(jobQueuePath, false);
List<String> jip = zk.getChildren(jobsInProgressPath, false);
jobQueue = server.getJobsInQueue();
jobsInProgress = server.getJobsInProgress();
members = server.getOrbTrackerMemberData();
assertEquals(mem.size(), members.length);
assertEquals(jq.size(), jobQueue.length);
assertEquals(jip.size(), jobsInProgress.length);
}
use of org.goldenorb.client.OrbTrackerMemberData in project goldenorb by jzachr.
the class OrbTrackerMemberDataServiceImpl method getOrbTrackerMemberData.
/**
* Returns the data of the OrbTrackerMember nodes under the LeaderGroup node in ZooKeeper.
*/
@Override
public OrbTrackerMemberData[] getOrbTrackerMemberData() throws ZooKeeperConnectionException, WatcherException, NodeDoesNotExistException {
if (zk == null) {
try {
initializeZooKeeper();
memberDataContainer = new HashMap<String, OrbTrackerMemberData>();
} catch (Exception e) {
e.printStackTrace();
throw new ZooKeeperConnectionException(e);
}
}
// Initialize leader group watcher
if (leaderGroupWatcher == null) {
try {
initializeLeaderGroupMonitor();
} catch (OrbZKFailure e) {
throw new WatcherException(e);
}
}
return memberDataContainer.values().toArray(new OrbTrackerMemberData[0]);
}
use of org.goldenorb.client.OrbTrackerMemberData in project goldenorb by jzachr.
the class TestLeaderGroupMemberMonitor method testSingleMemberDataChange.
/**
* Test a single change to a member node
*
* @throws OrbZKFailure
* @throws InterruptedException
*/
@Test
public void testSingleMemberDataChange() throws OrbZKFailure, InterruptedException {
CountDownLatch cdlatch = new CountDownLatch(1);
TServer server = new TServer(cdlatch);
OrbTrackerMember otm = new OrbTrackerMember();
otm.setAvailablePartitions(1);
otm.setHostname("TEST");
otm.setInUsePartitions(1);
otm.setLeader(true);
otm.setPartitionCapacity(1);
otm.setPort(1);
otm.setReservedPartitions(1);
String path = ZookeeperUtils.tryToCreateNode(zk, leaderGroupPath + "/member", otm, CreateMode.EPHEMERAL_SEQUENTIAL);
new LeaderGroupMemberMonitor(path, zk, path.split("/")[3], server);
cdlatch.await();
Map<String, OrbTrackerMemberData> map = server.getMemberData();
assertTrue(map.size() == 1);
Set<String> keys = map.keySet();
assertTrue(keys.size() == 1);
String nodeName = "";
for (String key : keys) {
nodeName = key;
}
assertTrue(nodeName.equals(path.split("/")[3]));
assertTrue(map.get(nodeName).getAvailablePartitions() == otm.getAvailablePartitions());
assertTrue(map.get(nodeName).getPort() == otm.getPort());
otm.setAvailablePartitions(9);
cdlatch = new CountDownLatch(1);
server.setLatcher(cdlatch);
ZookeeperUtils.setNodeData(zk, path, otm);
cdlatch.await();
map = server.getMemberData();
assertTrue(map.size() == 1);
keys = map.keySet();
assertTrue(keys.size() == 1);
nodeName = "";
for (String key : keys) {
nodeName = key;
}
assertTrue(nodeName.equals(path.split("/")[3]));
assertTrue(map.get(nodeName).getAvailablePartitions() == otm.getAvailablePartitions());
}
Aggregations