本文整理汇总了Java中org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical类的典型用法代码示例。如果您正苦于以下问题:Java QuorumHierarchical类的具体用法?Java QuorumHierarchical怎么用?Java QuorumHierarchical使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QuorumHierarchical类属于org.apache.zookeeper.server.quorum.flexible包,在下文中一共展示了QuorumHierarchical类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testZeroWeightQuorum
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@Test
public void testZeroWeightQuorum() throws Exception {
FastLeaderElection le[] = new FastLeaderElection[count];
LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0", PortAssignment.unique(), PortAssignment.unique(), null));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
for(int i = 0; i < le.length; 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");
}
}
}
示例2: createQuorumVerifier
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
private static QuorumVerifier createQuorumVerifier(Properties dynamicConfigProp, boolean isHierarchical) throws ConfigException{
if(isHierarchical){
return new QuorumHierarchical(dynamicConfigProp);
} else {
/*
* The default QuorumVerifier is QuorumMaj
*/
//LOG.info("Defaulting to majority quorums");
return new QuorumMaj(dynamicConfigProp);
}
}
示例3: testZeroWeightQuorum
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@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");
}
}
}
示例4: testZeroWeightQuorum
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@Test
public void testZeroWeightQuorum() throws Exception {
FastLeaderElection le[] = new FastLeaderElection[count];
LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i,
new InetSocketAddress(PortAssignment.unique()),
new InetSocketAddress(PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
for(int i = 0; i < le.length; 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");
}
}
}
示例5: testZeroWeightQuorum
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@Test
public void testZeroWeightQuorum() throws Exception {
FastLeaderElection le[] = new FastLeaderElection[count];
LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i,
new InetSocketAddress(PortAssignment.unique()),
new InetSocketAddress(PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
for(int i = 0; i < le.length; i++) {
QuorumHierarchical hq = new QuorumHierarchical(qp);
QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 2, 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");
}
}
}
示例6: testZeroWeightQuorum
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@Test
public void testZeroWeightQuorum() throws Exception {
FastLeaderElection le[] = new FastLeaderElection[count];
LOG.info("TestZeroWeightQuorum: " + getName()+ ", " + count);
for(int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i,
new InetSocketAddress(PortAssignment.unique()),
new InetSocketAddress(PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
for(int i = 0; i < le.length; 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 " + getName());
for(int i = 0; i < threads.size(); i++) {
threads.get(i).join(15000);
if (threads.get(i).isAlive()) {
fail("Threads didn't join");
} else {
if(threads.get(i).fail)
fail("Elected zero-weight server");
}
}
}
示例7: testQuorumSystemChange
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@Test
public void testQuorumSystemChange() throws Exception {
qu = new QuorumUtil(3); // create 7 servers
qu.disableJMXTest = true;
qu.startAll();
ZooKeeper[] zkArr = createHandles(qu);
ZooKeeperAdmin[] zkAdminArr = createAdminHandles(qu);
ArrayList<String> members = new ArrayList<String>();
members.add("group.1=3:4:5");
members.add("group.2=1:2");
members.add("weight.1=0");
members.add("weight.2=0");
members.add("weight.3=1");
members.add("weight.4=1");
members.add("weight.5=1");
for (int i = 1; i <= 5; i++) {
members.add("server." + i + "=127.0.0.1:"
+ qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
+ qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
+ "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
}
reconfig(zkAdminArr[1], null, null, members, -1);
// this should flush the config to servers 2, 3, 4 and 5
testNormalOperation(zkArr[2], zkArr[3]);
testNormalOperation(zkArr[4], zkArr[5]);
for (int i = 1; i <= 5; i++) {
if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumHierarchical))
Assert.fail("peer " + i
+ " doesn't think the quorum system is Hieararchical!");
}
qu.shutdown(1);
qu.shutdown(2);
qu.shutdown(3);
qu.shutdown(7);
qu.shutdown(6);
// servers 4 and 5 should be able to work independently
testNormalOperation(zkArr[4], zkArr[5]);
qu.restart(1);
qu.restart(2);
members.clear();
for (int i = 1; i <= 3; i++) {
members.add("server." + i + "=127.0.0.1:"
+ qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
+ qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
+ "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
}
reconfig(zkAdminArr[1], null, null, members, -1);
// flush the config to server 2
testNormalOperation(zkArr[1], zkArr[2]);
qu.shutdown(4);
qu.shutdown(5);
// servers 1 and 2 should be able to work independently
testNormalOperation(zkArr[1], zkArr[2]);
for (int i = 1; i <= 2; i++) {
if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumMaj))
Assert.fail("peer "
+ i
+ " doesn't think the quorum system is a majority quorum system!");
}
closeAllHandles(zkArr, zkAdminArr);
}
示例8: testQuorumSystemChange
import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; //导入依赖的package包/类
@Test
public void testQuorumSystemChange() throws Exception {
qu = new QuorumUtil(3); // create 7 servers
qu.disableJMXTest = true;
qu.startAll();
ZooKeeper[] zkArr = createHandles(qu);
ArrayList<String> members = new ArrayList<String>();
members.add("group.1=3:4:5");
members.add("group.2=1:2");
members.add("weight.1=0");
members.add("weight.2=0");
members.add("weight.3=1");
members.add("weight.4=1");
members.add("weight.5=1");
for (int i = 1; i <= 5; i++) {
members.add("server." + i + "=127.0.0.1:"
+ qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
+ qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
+ "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
}
reconfig(zkArr[1], null, null, members, -1);
// this should flush the config to servers 2, 3, 4 and 5
testNormalOperation(zkArr[2], zkArr[3]);
testNormalOperation(zkArr[4], zkArr[5]);
for (int i = 1; i <= 5; i++) {
if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumHierarchical))
Assert.fail("peer " + i
+ " doesn't think the quorum system is Hieararchical!");
}
qu.shutdown(1);
qu.shutdown(2);
qu.shutdown(3);
qu.shutdown(7);
qu.shutdown(6);
// servers 4 and 5 should be able to work independently
testNormalOperation(zkArr[4], zkArr[5]);
qu.restart(1);
qu.restart(2);
members.clear();
for (int i = 1; i <= 3; i++) {
members.add("server." + i + "=127.0.0.1:"
+ qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
+ qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
+ "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
}
reconfig(zkArr[1], null, null, members, -1);
// flush the config to server 2
testNormalOperation(zkArr[1], zkArr[2]);
qu.shutdown(4);
qu.shutdown(5);
// servers 1 and 2 should be able to work independently
testNormalOperation(zkArr[1], zkArr[2]);
for (int i = 1; i <= 2; i++) {
if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumMaj))
Assert.fail("peer "
+ i
+ " doesn't think the quorum system is a majority quorum system!");
}
closeAllHandles(zkArr);
}