|
@@ -16,14 +16,16 @@
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
-package org.apache.zookeeper.test;
|
|
|
+package org.apache.zookeeper.server.quorum;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.DataInputStream;
|
|
|
import java.io.DataOutputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.net.InetSocketAddress;
|
|
|
+import java.net.SocketAddress;
|
|
|
import java.nio.ByteBuffer;
|
|
|
import java.nio.channels.SocketChannel;
|
|
|
import java.util.ArrayList;
|
|
@@ -31,9 +33,14 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.net.Socket;
|
|
|
+import javax.net.ssl.SSLSession;
|
|
|
+import javax.net.ssl.SSLSocket;
|
|
|
+import javax.net.ssl.HandshakeCompletedListener;
|
|
|
|
|
|
+import org.apache.zookeeper.common.QuorumX509Util;
|
|
|
import org.apache.zookeeper.common.Time;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -46,6 +53,8 @@ import org.apache.zookeeper.server.quorum.QuorumPeer;
|
|
|
import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
|
|
|
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
|
|
|
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
|
|
|
+import org.apache.zookeeper.test.ClientBase;
|
|
|
+import org.apache.zookeeper.test.FLENewEpochTest;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
@@ -363,6 +372,81 @@ public class CnxManagerTest extends ZKTestCase {
|
|
|
Assert.assertFalse(cnxManager.listener.isAlive());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test the SSLSocket is explicitly closed when there is IOException
|
|
|
+ * happened during connect.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testSSLSocketClosedWhenHandshakeTimeout() throws Exception {
|
|
|
+ final CountDownLatch closeLatch = new CountDownLatch(1);
|
|
|
+ QuorumX509Util mockedX509Util = new QuorumX509Util() {
|
|
|
+ @Override
|
|
|
+ public SSLSocket createSSLSocket() {
|
|
|
+ return new SSLSocket() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void connect(SocketAddress endpoint, int timeout) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void startHandshake() throws IOException {
|
|
|
+ throw new IOException();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void close() {
|
|
|
+ closeLatch.countDown();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String [] getSupportedCipherSuites() {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String [] getEnabledCipherSuites() {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String [] getSupportedProtocols() {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String [] getEnabledProtocols() {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public SSLSession getSession() {
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setEnabledCipherSuites(String suites []) {}
|
|
|
+ public void setEnabledProtocols(String protocols[]) {}
|
|
|
+ public void addHandshakeCompletedListener(HandshakeCompletedListener listener) {}
|
|
|
+ public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {}
|
|
|
+ public void setUseClientMode(boolean mode) {}
|
|
|
+ public boolean getUseClientMode() { return true; }
|
|
|
+ public void setNeedClientAuth(boolean need) {}
|
|
|
+ public boolean getNeedClientAuth() { return true; }
|
|
|
+ public void setWantClientAuth(boolean want) {}
|
|
|
+ public boolean getWantClientAuth() { return true; }
|
|
|
+ public void setEnableSessionCreation(boolean flag) {}
|
|
|
+ public boolean getEnableSessionCreation() { return true; }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0],
|
|
|
+ peerClientPort[0], 3, 0, 2000, 2, 2) {
|
|
|
+ @Override
|
|
|
+ public QuorumX509Util createX509Util() {
|
|
|
+ return mockedX509Util;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ peer.setSslQuorum(true);
|
|
|
+ QuorumCnxManager cnxManager = peer.createCnxnManager();
|
|
|
+ cnxManager.connectOne(1, peers.get(1L).electionAddr);
|
|
|
+ Assert.assertTrue(closeLatch.await(1, TimeUnit.SECONDS));
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* Test if Worker threads are getting killed after connection loss
|
|
|
*/
|