use of org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical in project zookeeper by apache.
the class FLEZeroWeightTest method testZeroWeightQuorum.
@Test
public void testZeroWeightQuorum() throws Exception {
LOG.info("TestZeroWeightQuorum: " + getTestName() + ", " + count);
for (int i = 0; i < count; i++) {
InetSocketAddress addr1 = new InetSocketAddress("127.0.0.1", PortAssignment.unique());
InetSocketAddress addr2 = new InetSocketAddress("127.0.0.1", PortAssignment.unique());
InetSocketAddress addr3 = new InetSocketAddress("127.0.0.1", PortAssignment.unique());
port[i] = addr3.getPort();
qp.setProperty("server." + i, "127.0.0.1:" + addr1.getPort() + ":" + addr2.getPort() + ";" + port[i]);
peers.put(Long.valueOf(i), new QuorumServer(i, addr1, addr2, addr3));
tmpdir[i] = ClientBase.createTmpDir();
}
for (int i = 0; i < count; i++) {
QuorumHierarchical hq = new QuorumHierarchical(qp);
QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2, hq);
peer.startLeaderElection();
LEThread thread = new LEThread(peer, i);
thread.start();
threads.add(thread);
}
LOG.info("Started threads " + getTestName());
for (int i = 0; i < threads.size(); i++) {
threads.get(i).join(15000);
if (threads.get(i).isAlive()) {
Assert.fail("Threads didn't join");
} else {
if (threads.get(i).fail)
Assert.fail("Elected zero-weight server");
}
}
}
use of org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical in project zookeeper by apache.
the class HierarchicalQuorumTest method startServers.
/**
* Starts 5 Learners. When withObservers == false, all 5 are Followers.
* When withObservers == true, 3 are Followers and 2 Observers.
* @param withObservers
* @throws Exception
*/
void startServers(boolean withObservers) throws Exception {
int tickTime = 2000;
int initLimit = 3;
int syncLimit = 3;
HashMap<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>();
peers.put(Long.valueOf(1), new QuorumServer(1, new InetSocketAddress("127.0.0.1", port1), new InetSocketAddress("127.0.0.1", leport1), new InetSocketAddress("127.0.0.1", clientport1)));
peers.put(Long.valueOf(2), new QuorumServer(2, new InetSocketAddress("127.0.0.1", port2), new InetSocketAddress("127.0.0.1", leport2), new InetSocketAddress("127.0.0.1", clientport2)));
peers.put(Long.valueOf(3), new QuorumServer(3, new InetSocketAddress("127.0.0.1", port3), new InetSocketAddress("127.0.0.1", leport3), new InetSocketAddress("127.0.0.1", clientport3)));
peers.put(Long.valueOf(4), new QuorumServer(4, new InetSocketAddress("127.0.0.1", port4), new InetSocketAddress("127.0.0.1", leport4), new InetSocketAddress("127.0.0.1", clientport4), withObservers ? QuorumPeer.LearnerType.OBSERVER : QuorumPeer.LearnerType.PARTICIPANT));
peers.put(Long.valueOf(5), new QuorumServer(5, new InetSocketAddress("127.0.0.1", port5), new InetSocketAddress("127.0.0.1", leport5), new InetSocketAddress("127.0.0.1", clientport5), withObservers ? QuorumPeer.LearnerType.OBSERVER : QuorumPeer.LearnerType.PARTICIPANT));
LOG.info("creating QuorumPeer 1 port " + clientport1);
if (withObservers) {
qp.setProperty("server.4", "127.0.0.1:" + port4 + ":" + leport4 + ":observer" + ";" + clientport4);
qp.setProperty("server.5", "127.0.0.1:" + port5 + ":" + leport5 + ":observer" + ";" + clientport5);
}
QuorumHierarchical hq1 = new QuorumHierarchical(qp);
s1 = new QuorumPeer(peers, s1dir, s1dir, clientport1, 3, 1, tickTime, initLimit, syncLimit, hq1);
Assert.assertEquals(clientport1, s1.getClientPort());
LOG.info("creating QuorumPeer 2 port " + clientport2);
QuorumHierarchical hq2 = new QuorumHierarchical(qp);
s2 = new QuorumPeer(peers, s2dir, s2dir, clientport2, 3, 2, tickTime, initLimit, syncLimit, hq2);
Assert.assertEquals(clientport2, s2.getClientPort());
LOG.info("creating QuorumPeer 3 port " + clientport3);
QuorumHierarchical hq3 = new QuorumHierarchical(qp);
s3 = new QuorumPeer(peers, s3dir, s3dir, clientport3, 3, 3, tickTime, initLimit, syncLimit, hq3);
Assert.assertEquals(clientport3, s3.getClientPort());
LOG.info("creating QuorumPeer 4 port " + clientport4);
QuorumHierarchical hq4 = new QuorumHierarchical(qp);
s4 = new QuorumPeer(peers, s4dir, s4dir, clientport4, 3, 4, tickTime, initLimit, syncLimit, hq4);
if (withObservers) {
s4.setLearnerType(QuorumPeer.LearnerType.OBSERVER);
}
Assert.assertEquals(clientport4, s4.getClientPort());
LOG.info("creating QuorumPeer 5 port " + clientport5);
QuorumHierarchical hq5 = new QuorumHierarchical(qp);
s5 = new QuorumPeer(peers, s5dir, s5dir, clientport5, 3, 5, tickTime, initLimit, syncLimit, hq5);
if (withObservers) {
s5.setLearnerType(QuorumPeer.LearnerType.OBSERVER);
}
Assert.assertEquals(clientport5, s5.getClientPort());
// Observers are currently only compatible with LeaderElection
if (withObservers) {
s1.setElectionType(0);
s2.setElectionType(0);
s3.setElectionType(0);
s4.setElectionType(0);
s5.setElectionType(0);
}
LOG.info("start QuorumPeer 1");
s1.start();
LOG.info("start QuorumPeer 2");
s2.start();
LOG.info("start QuorumPeer 3");
s3.start();
LOG.info("start QuorumPeer 4" + (withObservers ? "(observer)" : ""));
s4.start();
LOG.info("start QuorumPeer 5" + (withObservers ? "(observer)" : ""));
s5.start();
LOG.info("started QuorumPeer 5");
LOG.info("Closing ports " + hostPort);
for (String hp : hostPort.split(",")) {
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(hp, CONNECTION_TIMEOUT));
LOG.info(hp + " is accepting client connections");
}
// interesting to see what's there...
JMXEnv.dump();
// make sure we have these 5 servers listed
Set<String> ensureNames = new LinkedHashSet<String>();
for (int i = 1; i <= 5; i++) {
ensureNames.add("InMemoryDataTree");
}
for (int i = 1; i <= 5; i++) {
ensureNames.add("name0=ReplicatedServer_id" + i + ",name1=replica." + i + ",name2=");
}
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
ensureNames.add("name0=ReplicatedServer_id" + i + ",name1=replica." + j);
}
}
for (int i = 1; i <= 5; i++) {
ensureNames.add("name0=ReplicatedServer_id" + i);
}
JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()]));
for (int i = 1; i <= 5; i++) {
String bean = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + i + ",name1=replica." + i;
JMXEnv.ensureBeanAttribute(bean, "ConfigVersion");
JMXEnv.ensureBeanAttribute(bean, "LearnerType");
JMXEnv.ensureBeanAttribute(bean, "ClientAddress");
JMXEnv.ensureBeanAttribute(bean, "ElectionAddress");
JMXEnv.ensureBeanAttribute(bean, "QuorumSystemInfo");
}
}
Aggregations