You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/08/15 02:39:05 UTC

[GitHub] beiwei30 closed pull request #2261: Baiji 269 team 9 add unit test

beiwei30 closed pull request #2261: Baiji 269  team 9 add unit test
URL: https://github.com/apache/incubator-dubbo/pull/2261
 
 
   

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-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 2167512630..1193ef3978 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 @@
 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 void testNotifyThreeArgs() {
         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


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org