use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class LETest method testLE.
@Test
public void testLE() throws Exception {
int count = 30;
HashMap<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>(count);
ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
File[] tmpdir = new File[count];
int[] port = new int[count];
votes = new Vote[count];
for (int i = 0; i < count; i++) {
peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
LeaderElection[] le = new LeaderElection[count];
leaderDies = true;
boolean allowOneBadLeader = leaderDies;
for (int i = 0; i < le.length; i++) {
QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 0, i, 1000, 2, 2);
peer.startLeaderElection();
le[i] = new LeaderElection(peer);
LEThread thread = new LEThread(le[i], peer, i);
thread.start();
threads.add(thread);
}
for (int i = 0; i < threads.size(); i++) {
threads.get(i).join(15000);
if (threads.get(i).isAlive()) {
Assert.fail("Threads didn't join");
}
}
long id = votes[0].getId();
for (int i = 1; i < votes.length; i++) {
if (votes[i] == null) {
Assert.fail("Thread " + i + " had a null vote");
}
if (votes[i].getId() != id) {
if (allowOneBadLeader && votes[i].getId() == i) {
allowOneBadLeader = false;
} else {
Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
}
}
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class CnxManagerTest method setUp.
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long, QuorumServer>(count);
peerTmpdir = new File[count];
peerQuorumPort = new int[count];
peerClientPort = new int[count];
for (int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress("127.0.0.1", peerQuorumPort[i]), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", peerClientPort[i])));
peerTmpdir[i] = ClientBase.createTmpDir();
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class Zab1_0Test method createQuorumPeer.
private QuorumPeer createQuorumPeer(File tmpDir) throws IOException, FileNotFoundException {
HashMap<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>();
QuorumPeer peer = new QuorumPeer();
peer.syncLimit = SYNC_LIMIT;
peer.initLimit = 2;
peer.tickTime = 2000;
peers.put(0L, new QuorumServer(0, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
peers.put(1L, new QuorumServer(1, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
peers.put(2L, new QuorumServer(2, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
peer.setQuorumVerifier(new QuorumMaj(peers), false);
peer.setCnxnFactory(new NullServerCnxnFactory());
File version2 = new File(tmpDir, "version-2");
version2.mkdir();
ClientBase.createInitializeFile(tmpDir);
FileOutputStream fos;
fos = new FileOutputStream(new File(version2, "currentEpoch"));
fos.write("0\n".getBytes());
fos.close();
fos = new FileOutputStream(new File(version2, "acceptedEpoch"));
fos.write("0\n".getBytes());
fos.close();
return peer;
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class QuorumServerTest method constructionUnderstandsIpv6LiteralsInClientConfig.
@Test
public void constructionUnderstandsIpv6LiteralsInClientConfig() throws ConfigException {
String config = "127.0.0.1:1234:1236:participant;[::1]:1237";
QuorumServer qs = new QuorumServer(0, config);
assertEquals("127.0.0.1:1234:1236:participant;[0:0:0:0:0:0:0:1]:1237", qs.toString());
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class QuorumServerTest method constructionUnderstandsIpv6LiteralsInServerConfig.
@Test
public void constructionUnderstandsIpv6LiteralsInServerConfig() throws ConfigException {
String config = "[::1]:1234:1236:participant";
QuorumServer qs = new QuorumServer(0, config);
assertEquals("[0:0:0:0:0:0:0:1]:1234:1236:participant", qs.toString());
}
Aggregations