*
* @throws Exception
*/
@Test
public void testCnxFromFutureVersion() throws Exception {
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
TestCnxManager cnxManager = new TestCnxManager(peer);
QuorumCnxManager.Listener listener = cnxManager.listener;
if(listener != null){
listener.start();
} else {
Assert.fail("Null listener when initializing cnx manager");
}
int port = peers.get(peer.getId()).electionAddr.getPort();
LOG.info("Election port: " + port);
Thread.sleep(1000);
SocketChannel sc = SocketChannel.open();
sc.socket().connect(peers.get(new Long(1)).electionAddr, 5000);
InetSocketAddress otherAddr = peers.get(new Long(2)).electionAddr;
DataOutputStream dout = new DataOutputStream(sc.socket().getOutputStream());
// protocol version - a negative number
dout.writeLong(0xffff0000);
// server id
dout.writeLong(new Long(2));
// other stuff that a 3.5.0 server will send - not important for 3.4.6
// the 3.4.6 server should just skip it
String addr = otherAddr.getHostName()+ ":" + otherAddr.getPort();
byte[] addr_bytes = addr.getBytes();
dout.writeInt(addr_bytes.length);
dout.write(addr_bytes);
dout.flush();
Thread.sleep(1000);
Assert.assertEquals("Server 1 got connection request from server 2",
true, cnxManager.senderWorkerMapContains(new Long(2)));
// send another message to make sure the connection message was processed
// properly (mainly that its suffix was removed from the stream)
String testStr = "this is a test message string";
byte[] testStr_bytes = testStr.getBytes();
dout.writeInt(testStr_bytes.length);
dout.write(testStr_bytes);
dout.flush();
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
if(numRetries > THRESHOLD){
Assert.fail("Test message hasn't been found in recvQueue");
}
//Assert.assertEquals("Message sender should be 2", 2, m.sid);
Assert.assertEquals("Message sender should be 2", 2, cnxManager.getSid(m));
Assert.assertEquals("Message from 2 doesn't match test sring", testStr,
cnxManager.getMsgString(m));
peer.shutdown();
cnxManager.halt();
}