You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by il...@apache.org on 2018/08/15 02:39:06 UTC

[incubator-dubbo] branch master updated: Baiji 269 team 9 add unit test (#2261)

This is an automated email from the ASF dual-hosted git repository.

iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 92c566a  Baiji 269  team 9 add unit test (#2261)
92c566a is described below

commit 92c566a381f44c685139a399aad21981bea71ea9
Author: suyan <79...@qq.com>
AuthorDate: Wed Aug 15 10:39:02 2018 +0800

    Baiji 269  team 9 add unit test (#2261)
    
    * issues #2177
    
    * issues #217 modifed
---
 .../registry/support/AbstractRegistryTest.java     | 87 +++++++++++++++++++++-
 1 file changed, 86 insertions(+), 1 deletion(-)

diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java
index 2167512..1193ef3 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java
@@ -19,6 +19,7 @@ package org.apache.dubbo.registry.support;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.registry.NotifyListener;
+import org.apache.dubbo.common.Constants;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.After;
@@ -432,4 +433,88 @@ public class AbstractRegistryTest {
         abstractRegistry.notify(testUrl, listener, urls);
         Assert.assertTrue(notifySuccess);
     }
-}
+
+    @Test
+    public void filterEmptyTest() {
+        // check parameters
+        try {
+            AbstractRegistry.filterEmpty(null, null);
+            Assert.fail();
+        } catch (Exception e) {
+            Assert.assertTrue(e instanceof NullPointerException);
+        }
+
+        // check parameters
+        List<URL> urls = new ArrayList<>();
+        try {
+            AbstractRegistry.filterEmpty(null, urls);
+            Assert.fail();
+        } catch (Exception e) {
+            Assert.assertTrue(e instanceof NullPointerException);
+        }
+
+        // check if the output is generated by a fixed way
+        urls.add(testUrl.setProtocol(Constants.EMPTY_PROTOCOL));
+        Assert.assertEquals(AbstractRegistry.filterEmpty(testUrl, null), urls);
+
+        List<URL> testUrls = new ArrayList<>();
+        Assert.assertEquals(AbstractRegistry.filterEmpty(testUrl, testUrls), urls);
+
+        // check if the output equals the input urls
+        testUrls.add(testUrl);
+        Assert.assertEquals(AbstractRegistry.filterEmpty(testUrl, testUrls), testUrls);
+
+    }
+
+
+    @Test
+    public void lookupTest(){
+        // loop up before registry
+        try {
+            abstractRegistry.lookup(null);
+            Assert.fail();
+        } catch (Exception e) {
+            Assert.assertTrue(e instanceof NullPointerException);
+        }
+        List<URL> urlList1 = abstractRegistry.lookup(testUrl);
+        Assert.assertFalse(urlList1.contains(testUrl));
+        // loop up after registry
+        List<URL> urls = new ArrayList<>();
+        urls.add(testUrl);
+        abstractRegistry.notify(urls);
+        List<URL> urlList2 = abstractRegistry.lookup(testUrl);
+        Assert.assertTrue(urlList2.contains(testUrl));
+
+    }
+
+    @Test
+    public void destroyTest(){
+        abstractRegistry.register(testUrl);
+        abstractRegistry.subscribe(testUrl, listener);
+        Assert.assertEquals(1,abstractRegistry.getRegistered().size());
+        Assert.assertEquals(1,abstractRegistry.getSubscribed().get(testUrl).size());
+        // delete listener and register
+        abstractRegistry.destroy();
+        Assert.assertEquals(0,abstractRegistry.getRegistered().size());
+        Assert.assertEquals(0,abstractRegistry.getSubscribed().get(testUrl).size());
+    }
+
+    @Test
+    public void allTest(){
+        // test all methods
+        List<URL> urls = new ArrayList<>();
+        urls.add(testUrl);
+        // register, subscribe, notify, unsubscribe, unregister
+        abstractRegistry.register(testUrl);
+        Assert.assertTrue(abstractRegistry.getRegistered().contains(testUrl));
+        abstractRegistry.subscribe(testUrl,listener);
+        Assert.assertTrue(abstractRegistry.getSubscribed().containsKey(testUrl));
+        Assert.assertFalse(notifySuccess);
+        abstractRegistry.notify(urls);
+        Assert.assertTrue(notifySuccess);
+        abstractRegistry.unsubscribe(testUrl,listener);
+        Assert.assertFalse(abstractRegistry.getSubscribed().containsKey(listener));
+        abstractRegistry.unregister(testUrl);
+        Assert.assertFalse(abstractRegistry.getRegistered().contains(testUrl));
+    }
+}
\ No newline at end of file