use of org.goldenorb.jet.OrbTrackerMember in project goldenorb by jzachr.
the class TestOrbTrackerMember method testOrbTrackerMember.
/*
* Start of user / non-generated code -- any code written outside of this block will be
* removed in subsequent code generations.
*/
/* End of user / non-generated code */
@Before
public void testOrbTrackerMember() throws IOException {
/*
* Start of user / non-generated code -- any code written outside of this block will be
* removed in subsequent code generations.
*/
/* End of user / non-generated code */
orbTrackerMember = new OrbTrackerMember();
orbTrackerMember.setPartitionCapacity(INT_PARTITIONCAPACITY_VALUE);
orbTrackerMember.setAvailablePartitions(INT_AVAILABLEPARTITIONS_VALUE);
orbTrackerMember.setReservedPartitions(INT_RESERVEDPARTITIONS_VALUE);
orbTrackerMember.setInUsePartitions(INT_INUSEPARTITIONS_VALUE);
orbTrackerMember.setHostname(STRING_HOSTNAME_VALUE);
orbTrackerMember.setLeader(BOOLEAN_LEADER_VALUE);
orbTrackerMember.setPort(INT_PORT_VALUE);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(baos);
orbTrackerMember.write(out);
DataInput in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
orbTrackerMemberOut = new OrbTrackerMember();
orbTrackerMemberOut.readFields(in);
/*
* Start of user / non-generated code -- any code written outside of this block will be
* removed in subsequent code generations.
*/
/* End of user / non-generated code */
}
use of org.goldenorb.jet.OrbTrackerMember 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());
}
use of org.goldenorb.jet.OrbTrackerMember in project goldenorb by jzachr.
the class TestLeaderGroupMemberMonitor method testMulitpleChanges.
/**
* Test multiple changes to a single member node
*
* @throws OrbZKFailure
* @throws InterruptedException
*/
public void testMulitpleChanges() 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());
cdlatch = new CountDownLatch(1);
server.setLatcher(cdlatch);
otm.setHostname("Hostname");
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).getHostname() == otm.getHostname());
cdlatch = new CountDownLatch(1);
server.setLatcher(cdlatch);
otm.setHostname("Host");
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).getHostname() == otm.getHostname());
}
use of org.goldenorb.jet.OrbTrackerMember in project goldenorb by jzachr.
the class TestLeaderGroupMonitor method testDeleteAndAdd.
@Test
public void testDeleteAndAdd() throws OrbZKFailure, InterruptedException, KeeperException {
int num_created = 10;
int num_deleted = 7;
CountDownLatch latch = new CountDownLatch(num_created);
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_created; 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_created);
latch = new CountDownLatch(num_deleted);
server.setLatcher(latch);
List<String> children = zk.getChildren(leaderGroupPath, false);
int i = 0;
for (String child : children) {
if (i < num_deleted) {
ZookeeperUtils.deleteNodeIfEmpty(zk, leaderGroupPath + "/" + child);
}
i++;
}
latch.await();
map = server.getMemberData();
assertEquals(num_created - num_deleted, map.size());
}
use of org.goldenorb.jet.OrbTrackerMember in project goldenorb by jzachr.
the class TestOrbTrackerMemberDataServiceImpl method testGetOrbTrackerMemberData.
@Test
public void testGetOrbTrackerMemberData() throws OrbZKFailure, ZooKeeperConnectionException, WatcherException, NodeDoesNotExistException, InterruptedException, KeeperException {
int num_nodes = 10;
OrbTrackerMember[] members = new OrbTrackerMember[num_nodes];
for (int i = 0; i < num_nodes; i++) {
members[i] = new OrbTrackerMember();
members[i].setAvailablePartitions(i);
members[i].setHostname("host");
members[i].setInUsePartitions(i);
members[i].setLeader(false);
members[i].setPartitionCapacity(i);
members[i].setPort(i);
members[i].setReservedPartitions(i);
ZookeeperUtils.tryToCreateNode(zk, leaderGroupPath + "/member", members[i], CreateMode.EPHEMERAL_SEQUENTIAL);
}
OrbTrackerMemberDataServiceImpl server = new OrbTrackerMemberDataServiceImpl();
CountDownLatch jobs = new CountDownLatch(1);
CountDownLatch update = new CountDownLatch(num_nodes);
CountDownLatch remove = new CountDownLatch(3);
server.enterTestingMode(jobs, remove, update);
OrbTrackerMemberData[] memberData = server.getOrbTrackerMemberData();
update.await();
List<String> nodes = zk.getChildren(leaderGroupPath, false);
assertEquals(nodes.size(), memberData.length);
update = new CountDownLatch(2);
server.setUpdateLatch(update);
for (int i = 0; i < 2; i++) {
members[i] = new OrbTrackerMember();
members[i].setAvailablePartitions(i);
members[i].setHostname("host");
members[i].setInUsePartitions(i);
members[i].setLeader(false);
members[i].setPartitionCapacity(i);
members[i].setPort(i);
members[i].setReservedPartitions(i);
ZookeeperUtils.tryToCreateNode(zk, leaderGroupPath + "/member", members[i], CreateMode.EPHEMERAL_SEQUENTIAL);
}
update.await();
memberData = server.getOrbTrackerMemberData();
nodes = zk.getChildren(leaderGroupPath, false);
assertEquals(nodes.size(), memberData.length);
remove = new CountDownLatch(4);
server.setRemoveLatch(remove);
int i = 0;
for (String node : nodes) {
if (i < 4) {
ZookeeperUtils.deleteNodeIfEmpty(zk, leaderGroupPath + "/" + node);
}
i++;
}
remove.await();
memberData = server.getOrbTrackerMemberData();
nodes = zk.getChildren(leaderGroupPath, false);
assertEquals(nodes.size(), memberData.length);
}
Aggregations