kezhuw commented on code in PR #2200:
URL: https://github.com/apache/zookeeper/pull/2200#discussion_r1800328858


##########
zookeeper-server/src/test/java/org/apache/zookeeper/test/ReadOnlyModeWithSSLTest.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.ByteArrayOutputStream;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+import java.util.regex.Pattern;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.ZKTestCase;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.common.ClientX509Util;
+import org.apache.zookeeper.common.StringUtils;
+import org.apache.zookeeper.server.NettyServerCnxnFactory;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.LoggerFactory;
+
+public class ReadOnlyModeWithSSLTest extends ZKTestCase {
+
+    private static final org.slf4j.Logger LOG = 
LoggerFactory.getLogger(ReadOnlyModeWithSSLTest.class);
+    private static int CONNECTION_TIMEOUT = QuorumBase.CONNECTION_TIMEOUT;
+    private QuorumUtil qu = new QuorumUtil(1);
+    private ClientX509Util clientX509Util;
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        System.setProperty("readonlymode.enabled", "true");
+        System.setProperty(NettyServerCnxnFactory.PORT_UNIFICATION_KEY, 
Boolean.TRUE.toString());
+        clientX509Util = new ClientX509Util();
+        String testDataPath = System.getProperty("test.data.dir", 
"src/test/resources/data");
+        System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, 
"org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, 
"org.apache.zookeeper.ClientCnxnSocketNetty");
+        System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
+        System.setProperty(clientX509Util.getSslKeystoreLocationProperty(), 
testDataPath + "/ssl/testKeyStore.jks");

Review Comment:
   These properties are mixed between client and server. I think we should 
build a `ZKClientConfig` for client usage prior to set them up for server(there 
is ZOOKEEPER-2139 counterpart in server) as  `ZKClientConfig` will inherit 
properties from system.
   
   
https://github.com/apache/zookeeper/blob/75884ec1f4a680f46bcc0a6257df413955eda4e8/zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java#L95-L136



##########
zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java:
##########
@@ -1301,44 +1300,19 @@ private void cleanAndNotifyState() {
         private void pingRwServer() throws RWServerFoundException {
             String result = null;
             InetSocketAddress addr = hostProvider.next(0);
+            boolean useSecure = 
clientConfig.getBoolean(ZKClientConfig.SECURE_CLIENT);
 
             LOG.info("Checking server {} for being r/w. Timeout {}", addr, 
pingRwTimeout);
-
-            Socket sock = null;
-            BufferedReader br = null;
             try {
-                sock = new Socket(addr.getHostString(), addr.getPort());
-                sock.setSoLinger(false, -1);
-                sock.setSoTimeout(1000);
-                sock.setTcpNoDelay(true);
-                sock.getOutputStream().write("isro".getBytes());
-                sock.getOutputStream().flush();
-                sock.shutdownOutput();
-                br = new BufferedReader(new 
InputStreamReader(sock.getInputStream()));
-                result = br.readLine();
+                result = 
FourLetterWordMain.send4LetterWord(addr.getHostString(), addr.getPort(), 
"isro", useSecure, 1000);

Review Comment:
   I think we should add a overloading `send4LetterWord` to accept `ZKConfig`, 
so we can sure that we are not mixed with external properties. Currently, 
`send4LetterWord` uses `new ZkConfig` which is not suitable for `ClientCnxn` 
after ZOOKEEPER-2139.
   
   
https://github.com/apache/zookeeper/blob/75884ec1f4a680f46bcc0a6257df413955eda4e8/zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java#L340-L347



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to