Переглянути джерело

ZOOKEEPER-4345: Avoid NoSunchMethodException caused by shaded zookeeper jar

Author: Bo <cuibo0108@163.com>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Mohammad Arshad <arshad@apache.org>

Closes #1736 from cuibo01/zookeeper-4345 and squashes the following commits:

3965f2e8d [Bo] [ZOOKEEPER-4345]Avoid NoSunchMethodException caused by shaded
970972971 [Bo] [ZOOKEEPER-4345]Avoid NoSunchMethodException caused by shaded
Bo Cui 3 роки тому
батько
коміт
5f6ec6cc7f

+ 4 - 1
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java

@@ -3028,9 +3028,12 @@ public class ZooKeeper implements AutoCloseable {
 
     private ClientCnxnSocket getClientCnxnSocket() throws IOException {
         String clientCnxnSocketName = getClientConfig().getProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET);
-        if (clientCnxnSocketName == null) {
+        if (clientCnxnSocketName == null || clientCnxnSocketName.equals(ClientCnxnSocketNIO.class.getSimpleName())) {
             clientCnxnSocketName = ClientCnxnSocketNIO.class.getName();
+        } else if (clientCnxnSocketName.equals(ClientCnxnSocketNetty.class.getSimpleName())) {
+            clientCnxnSocketName = ClientCnxnSocketNetty.class.getName();
         }
+
         try {
             Constructor<?> clientCxnConstructor = Class.forName(clientCnxnSocketName)
                                                        .getDeclaredConstructor(ZKClientConfig.class);

+ 12 - 0
zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientSSLTest.java

@@ -84,6 +84,18 @@ public class ClientSSLTest extends QuorumPeerTestBase {
         testClientServerSSL(false);
     }
 
+    @Test
+    public void testClientServerUnifiedPortWithCnxnClassName() throws Exception {
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "ClientCnxnSocketNIO");
+        testClientServerSSL(false);
+    }
+
+    @Test
+    public void testClientServerSSLWithCnxnClassName() throws Exception {
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "ClientCnxnSocketNetty");
+        testClientServerSSL(true);
+    }
+
     /**
      * This test checks that client - server SSL works in cluster setup of ZK servers, which includes:
      * 1. setting "secureClientPort" in "zoo.cfg" file.