use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class BaseSysTest method fakeConfigureServers.
private void fakeConfigureServers(int count) throws IOException {
peers = new HashMap<Long, QuorumServer>();
qps = new QuorumPeer[count];
qpsDirs = new File[count];
for (int i = 1; i <= count; i++) {
InetSocketAddress peerAddress = new InetSocketAddress("127.0.0.1", fakeBasePort + i);
InetSocketAddress electionAddr = new InetSocketAddress("127.0.0.1", serverCount + fakeBasePort + i);
peers.put(Long.valueOf(i), new QuorumServer(i, peerAddress, electionAddr));
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
//make that testData exists otherwise it fails on windows
testData.mkdirs();
qpsDirs[i] = File.createTempFile("sysTest", ".tmp", testData);
qpsDirs[i].delete();
qpsDirs[i].mkdir();
int port = fakeBasePort + 10 + i;
if (sb.length() > 0) {
sb.append(',');
}
sb.append("localhost:");
sb.append(port);
}
serverHostPort = sb.toString();
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class FLEBackwardElectionRoundTest method testBackwardElectionRound.
/**
* This test is checking the following case. A server S is
* currently LOOKING and it receives notifications from
* a quorum indicating they are following S. The election
* round E of S is higher than the election round E' in the
* notification messages, so S becomes the leader and sets
* its epoch back to E'. In the meanwhile, one or more
* followers turn to LOOKING and elect S in election round E.
* Having leader and followers with different election rounds
* might prevent other servers from electing a leader because
* they can't get a consistent set of notifications from a
* quorum.
*
* {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1514}
*
*
* @throws Exception
*/
@Test
public void testBackwardElectionRound() throws Exception {
LOG.info("TestLE: {}, {}", getTestName(), count);
for (int i = 0; i < count; i++) {
int clientport = PortAssignment.unique();
peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress(clientport), new InetSocketAddress(PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = clientport;
}
ByteBuffer initialMsg = FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 0, 0, 1);
/*
* Start server 0
*/
QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
peer.startLeaderElection();
FLETestUtils.LEThread thread = new FLETestUtils.LEThread(peer, 0);
thread.start();
/*
* Start mock server 1
*/
QuorumPeer mockPeer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2);
cnxManagers[0] = new QuorumCnxManager(mockPeer);
cnxManagers[0].listener.start();
cnxManagers[0].toSend(0l, initialMsg);
/*
* Start mock server 2
*/
mockPeer = new QuorumPeer(peers, tmpdir[2], tmpdir[2], port[2], 3, 2, 1000, 2, 2);
cnxManagers[1] = new QuorumCnxManager(mockPeer);
cnxManagers[1].listener.start();
cnxManagers[1].toSend(0l, initialMsg);
/*
* Run another instance of leader election.
*/
thread.join(5000);
thread = new FLETestUtils.LEThread(peer, 0);
thread.start();
/*
* Send the same messages, this time should not make 0 the leader.
*/
cnxManagers[0].toSend(0l, initialMsg);
cnxManagers[1].toSend(0l, initialMsg);
thread.join(5000);
if (!thread.isAlive()) {
Assert.fail("Should not have joined");
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class FLELostMessageTest method testLostMessage.
@Test
public void testLostMessage() throws Exception {
LOG.info("TestLE: {}, {}", getTestName(), count);
for (int i = 0; i < count; i++) {
int clientport = PortAssignment.unique();
peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress(clientport), new InetSocketAddress(PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = clientport;
}
/*
* Start server 0
*/
QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2);
peer.startLeaderElection();
FLETestUtils.LEThread thread = new FLETestUtils.LEThread(peer, 1);
thread.start();
/*
* Start mock server 1
*/
mockServer();
thread.join(5000);
if (thread.isAlive()) {
Assert.fail("Threads didn't join");
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class QuorumPeerTest method testQuorumPeerListendOnSpecifiedClientIP.
/**
* Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2301
*/
@Test
public void testQuorumPeerListendOnSpecifiedClientIP() throws IOException {
long myId = 1;
File dataDir = ClientBase.createTmpDir();
int clientPort = PortAssignment.unique();
Map<Long, QuorumServer> peersView = new HashMap<Long, QuorumServer>();
InetAddress clientIP = InetAddress.getLoopbackAddress();
peersView.put(Long.valueOf(myId), new QuorumServer(myId, new InetSocketAddress(clientIP, PortAssignment.unique()), new InetSocketAddress(clientIP, PortAssignment.unique()), new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT));
/**
* QuorumPeer constructor without QuorumVerifier
*/
QuorumPeer peer1 = new QuorumPeer(peersView, dataDir, dataDir, clientPort, electionAlg, myId, tickTime, initLimit, syncLimit);
String hostString1 = peer1.cnxnFactory.getLocalAddress().getHostString();
assertEquals(clientIP.getHostAddress(), hostString1);
// cleanup
peer1.shutdown();
/**
* QuorumPeer constructor with QuorumVerifier
*/
peersView.clear();
clientPort = PortAssignment.unique();
peersView.put(Long.valueOf(myId), new QuorumServer(myId, new InetSocketAddress(clientIP, PortAssignment.unique()), new InetSocketAddress(clientIP, PortAssignment.unique()), new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT));
QuorumPeer peer2 = new QuorumPeer(peersView, dataDir, dataDir, clientPort, electionAlg, myId, tickTime, initLimit, syncLimit);
String hostString2 = peer2.cnxnFactory.getLocalAddress().getHostString();
assertEquals(clientIP.getHostAddress(), hostString2);
// cleanup
peer2.shutdown();
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class QuorumServerTest method testToString.
@Test
public void testToString() throws ConfigException {
String config = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
String expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
QuorumServer qs = new QuorumServer(0, config);
Assert.assertEquals("Use IP address", expected, qs.toString());
config = "127.0.0.1:1234:1236;0.0.0.0:1237";
expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
qs = new QuorumServer(0, config);
Assert.assertEquals("Type unspecified", expected, qs.toString());
config = "127.0.0.1:1234:1236:observer;0.0.0.0:1237";
expected = "127.0.0.1:1234:1236:observer;0.0.0.0:1237";
qs = new QuorumServer(0, config);
Assert.assertEquals("Observer type", expected, qs.toString());
config = "127.0.0.1:1234:1236:participant;1237";
expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
qs = new QuorumServer(0, config);
Assert.assertEquals("Client address unspecified", expected, qs.toString());
config = "127.0.0.1:1234:1236:participant;1.2.3.4:1237";
expected = "127.0.0.1:1234:1236:participant;1.2.3.4:1237";
qs = new QuorumServer(0, config);
Assert.assertEquals("Client address specified", expected, qs.toString());
config = "example.com:1234:1236:participant;1237";
expected = "example.com:1234:1236:participant;0.0.0.0:1237";
qs = new QuorumServer(0, config);
Assert.assertEquals("Use hostname", expected, qs.toString());
}
Aggregations