You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/06/25 03:48:28 UTC

[GitHub] [zookeeper] hanm commented on a change in pull request #1387: ZOOKEEPER-3870: Avoid out of order response and txns created with ReadOnlyZooKeeperServer

hanm commented on a change in pull request #1387:
URL: https://github.com/apache/zookeeper/pull/1387#discussion_r445290522



##########
File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/ReadOnlyZooKeeperServerTest.java
##########
@@ -0,0 +1,253 @@
+/**
+ * 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.server;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooKeeper.States;
+import org.apache.zookeeper.AsyncCallback.DataCallback;
+import org.apache.zookeeper.AsyncCallback.StatCallback;
+import org.apache.zookeeper.common.X509Exception.SSLContextException;
+import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.quorum.QuorumPeerTestBase;
+import org.apache.zookeeper.test.ClientBase;
+import org.apache.zookeeper.test.QuorumBase;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
+
+public class ReadOnlyZooKeeperServerTest extends QuorumPeerTestBase {
+    private static final org.slf4j.Logger LOG = LoggerFactory
+            .getLogger(ReadOnlyZooKeeperServerTest.class);
+
+    private static int CONNECTION_TIMEOUT = QuorumBase.CONNECTION_TIMEOUT;
+    public static int WAIT_TIMEOUT = 60000;
+
+    Vector<MainThread> servers = new Vector<MainThread>();
+    Vector<ServerConfig> configs = new Vector<ServerConfig>();
+
+    int[] SERVERS = { 0, 1, 2, 3 };
+    int[] PARTICIPANTS = { 0, 1, 2 };
+    int[] OBSERVER = { 3 };
+
+    int OBSERVER_ID = 3;
+    int OBSERVER_PORT;
+
+    /**
+     * Make sure the response is returned in order in RO mode.
+     */
+    @Test
+    public void testResponseOrder() throws Exception {
+        System.setProperty("readonlymode.enabled", "true");
+
+        ClientBase.setupTestEnv();
+        setupServers(true);
+
+        startup(OBSERVER, false);
+        waitForISRO("ro", OBSERVER_PORT, 60);
+
+        final ZooKeeper rozk = new ZooKeeper("127.0.0.1:" +
+            OBSERVER_PORT, ClientBase.CONNECTION_TIMEOUT, this, true);
+        waitForOne(rozk, States.CONNECTEDREADONLY);
+
+        final int requestCount = 1000;
+        final AtomicInteger successGetResponseCount = new AtomicInteger();
+        final CountDownLatch getResponseLatch = new CountDownLatch(requestCount);
+        Thread getDataThread = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                int requestIssued = 0;
+                while (requestIssued++ < requestCount) {
+                    rozk.getData("/", null, new DataCallback() {
+                        @Override
+                        public void processResult(int rc, String path,
+                                Object ctx, byte data[], Stat stat) {
+                              if (rc == 0) {
+                                  successGetResponseCount.incrementAndGet();
+                              }
+                              getResponseLatch.countDown();
+                        }
+                    }, null);
+                }
+            }
+        });
+        final CountDownLatch setResponseLatch = new CountDownLatch(requestCount);
+        Thread setDataThread = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                int requestIssued = 0;
+                while (requestIssued++ < requestCount) {
+                    rozk.setData("/test", new byte[0], -1, new StatCallback() {
+                        @Override
+                        public void processResult(int rc, String path,
+                                Object ctx, Stat stat) {
+                            setResponseLatch.countDown();
+                        }
+                    }, null);
+                }
+            }
+        });
+
+        getDataThread.start();
+        setDataThread.start();
+
+        Assert.assertTrue(getResponseLatch.await(2, TimeUnit.SECONDS));
+        Assert.assertTrue(setResponseLatch.await(2, TimeUnit.SECONDS));
+        Assert.assertEquals(requestCount, successGetResponseCount.get());
+

Review comment:
       How would these three Assert verify the order of the responses? 




----------------------------------------------------------------
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.

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