htynkn closed pull request #1671: add unit test for remoting zookeeper module
URL: https://github.com/apache/incubator-dubbo/pull/1671
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java
 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java
index a3d8a169cc..e708790917 100644
--- 
a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java
+++ 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java
@@ -18,38 +18,68 @@
 
 import com.alibaba.dubbo.common.URL;
 import com.alibaba.dubbo.common.utils.NetUtils;
+import org.apache.curator.framework.api.CuratorWatcher;
 import org.apache.curator.test.TestingServer;
+import org.apache.zookeeper.WatchedEvent;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
 import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
 
-@Ignore
 public class CuratorZookeeperClientTest {
     private TestingServer zkServer;
-    private int zkServerPort;
+    private CuratorZookeeperClient curatorClient;
 
     @Before
     public void setUp() throws Exception {
-        zkServerPort = NetUtils.getAvailablePort();
-        zkServer = new TestingServer(this.zkServerPort, true);
+        int zkServerPort = NetUtils.getAvailablePort();
+        zkServer = new TestingServer(zkServerPort, true);
+        curatorClient = new 
CuratorZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:" +
+                zkServerPort + "/com.alibaba.dubbo.registry.RegistryService"));
     }
 
     @Test
     public void testCheckExists() {
-        CuratorZookeeperClient curatorClient = new 
CuratorZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:" + this.zkServerPort 
+ "/com.alibaba.dubbo.registry.RegistryService"));
         String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
         curatorClient.create(path, false);
-        Assert.assertThat(curatorClient.checkExists(path), is(true));
-        Assert.assertThat(curatorClient.checkExists(path + "/noneexits"), 
is(false));
+        assertThat(curatorClient.checkExists(path), is(true));
+        assertThat(curatorClient.checkExists(path + "/noneexits"), is(false));
     }
 
+    @Test
+    public void testChildrenPath() {
+        String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
+        curatorClient.create(path, false);
+        curatorClient.create(path + "/provider1", false);
+        curatorClient.create(path + "/provider2", false);
+
+        List<String> children = curatorClient.getChildren(path);
+        assertThat(children.size(), is(2));
+    }
+
+    @Test
+    public void testChildrenListener() throws InterruptedException {
+        String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
+        curatorClient.create(path, false);
+        final CountDownLatch countDownLatch = new CountDownLatch(1);
+        curatorClient.addTargetChildListener(path, new CuratorWatcher() {
+            @Override
+            public void process(WatchedEvent watchedEvent) throws Exception {
+                countDownLatch.countDown();
+            }
+        });
+        curatorClient.createPersistent(path + "/provider1");
+        countDownLatch.await();
+    }
 
     @After
     public void tearDown() throws Exception {
+        curatorClient.close();
         zkServer.stop();
     }
 }
diff --git 
a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java
 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java
new file mode 100644
index 0000000000..7f29752be2
--- /dev/null
+++ 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 com.alibaba.dubbo.remoting.zookeeper.curator;
+
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubbo.common.utils.NetUtils;
+import com.alibaba.dubbo.remoting.zookeeper.ZookeeperClient;
+import org.apache.curator.test.TestingServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+
+public class CuratorZookeeperTransporterTest {
+    private TestingServer zkServer;
+    private ZookeeperClient zookeeperClient;
+
+    @Before
+    public void setUp() throws Exception {
+        int zkServerPort = NetUtils.getAvailablePort();
+        zkServer = new TestingServer(zkServerPort, true);
+        zookeeperClient = new 
CuratorZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
+                zkServerPort + "/service"));
+    }
+
+    @Test
+    public void testZookeeperClient() {
+        assertThat(zookeeperClient, not(nullValue()));
+        zookeeperClient.close();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        zkServer.stop();
+    }
+}
\ No newline at end of file
diff --git 
a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperClientTest.java
 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperClientTest.java
new file mode 100644
index 0000000000..bc1a8bb718
--- /dev/null
+++ 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperClientTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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 com.alibaba.dubbo.remoting.zookeeper.zkclient;
+
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubbo.common.utils.NetUtils;
+import com.alibaba.dubbo.remoting.zookeeper.StateListener;
+import org.I0Itec.zkclient.IZkChildListener;
+import org.apache.curator.test.TestingServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class ZkclientZookeeperClientTest {
+    private TestingServer zkServer;
+    private ZkclientZookeeperClient zkclientZookeeperClient;
+
+    @Before
+    public void setUp() throws Exception {
+        int zkServerPort = NetUtils.getAvailablePort();
+        zkServer = new TestingServer(zkServerPort, true);
+        zkclientZookeeperClient = new 
ZkclientZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:" +
+                zkServerPort + "/com.alibaba.dubbo.registry.RegistryService"));
+    }
+
+    @Test
+    public void testCheckExists() {
+        String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
+        zkclientZookeeperClient.create(path, false);
+        assertThat(zkclientZookeeperClient.checkExists(path), is(true));
+        assertThat(zkclientZookeeperClient.checkExists(path + "/noneexits"), 
is(false));
+    }
+
+    @Test
+    public void testDeletePath() {
+        String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
+        zkclientZookeeperClient.create(path, false);
+        assertThat(zkclientZookeeperClient.checkExists(path), is(true));
+
+        zkclientZookeeperClient.delete(path);
+        assertThat(zkclientZookeeperClient.checkExists(path), is(false));
+    }
+
+    @Test
+    public void testConnectState() throws Exception {
+        assertThat(zkclientZookeeperClient.isConnected(), is(true));
+        final CountDownLatch stopLatch = new CountDownLatch(1);
+        zkclientZookeeperClient.addStateListener(new StateListener() {
+            @Override
+            public void stateChanged(int connected) {
+                stopLatch.countDown();
+            }
+        });
+        zkServer.stop();
+        stopLatch.await();
+        assertThat(zkclientZookeeperClient.isConnected(), is(false));
+    }
+
+    @Test
+    public void testChildrenListener() throws InterruptedException {
+        String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
+        zkclientZookeeperClient.create(path, false);
+        final CountDownLatch countDownLatch = new CountDownLatch(1);
+        zkclientZookeeperClient.addTargetChildListener(path, new 
IZkChildListener() {
+            @Override
+            public void handleChildChange(String s, List<String> list) throws 
Exception {
+                countDownLatch.countDown();
+            }
+        });
+        zkclientZookeeperClient.createPersistent(path + "/provider1");
+        countDownLatch.await();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        zkclientZookeeperClient.close();
+        zkServer.stop();
+    }
+}
\ No newline at end of file
diff --git 
a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporterTest.java
 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporterTest.java
new file mode 100644
index 0000000000..bc3cef4126
--- /dev/null
+++ 
b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/com/alibaba/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporterTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 com.alibaba.dubbo.remoting.zookeeper.zkclient;
+
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubbo.common.utils.NetUtils;
+import com.alibaba.dubbo.remoting.zookeeper.ZookeeperClient;
+import org.apache.curator.test.TestingServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+
+public class ZkclientZookeeperTransporterTest {
+    private TestingServer zkServer;
+    private ZookeeperClient zookeeperClient;
+
+    @Before
+    public void setUp() throws Exception {
+        int zkServerPort = NetUtils.getAvailablePort();
+        zkServer = new TestingServer(zkServerPort, true);
+        zookeeperClient = new 
ZkclientZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
+                zkServerPort + "/service"));
+    }
+
+    @Test
+    public void testZookeeperClient() {
+        assertThat(zookeeperClient, not(nullValue()));
+        zookeeperClient.close();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        zkServer.stop();
+    }
+}
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to