From 1ca67968c6f4d97ad77bab09d83e916bc35e06f1 Mon Sep 17 00:00:00 2001 From: tswstarplanet Date: Mon, 1 Oct 2018 00:34:30 +0800 Subject: [PATCH 1/4] FailbackRegistry Test: recover method --- .../support/FailbackRegistryTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java index 5e50c311474..b354ea67000 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.registry.NotifyListener; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -180,6 +181,27 @@ public void notify(List urls) { assertEquals(2, count.get()); } + @Test + public void testRecover() throws Exception { + CountDownLatch countDownLatch = new CountDownLatch(2); + final AtomicReference notified = new AtomicReference(false); + + NotifyListener listner = new NotifyListener() { + @Override + public void notify(List urls) { + notified.set(Boolean.TRUE); + } + }; + + MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch); + mockRegistry.register(serviceUrl); + mockRegistry.subscribe(serviceUrl, listner); + Assert.assertEquals(mockRegistry.getRegistered().size(), 1); + Assert.assertEquals(mockRegistry.getSubscribed().size(), 1); + mockRegistry.recover(); + Assert.assertEquals(mockRegistry.getFailedSubscribed().size(), 1); + Assert.assertEquals(countDownLatch.getCount(), 0); + } private static class MockRegistry extends FailbackRegistry { CountDownLatch latch; From 32e4c3e09726ed8a7f35321f713ac8e03f4c669d Mon Sep 17 00:00:00 2001 From: tswstarplanet Date: Mon, 1 Oct 2018 19:16:33 +0800 Subject: [PATCH 2/4] fix the type error, and use CountDownLatch await method to fix the unstable problom --- .../registry/support/FailbackRegistryTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java index b354ea67000..e48892e226d 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java @@ -183,10 +183,10 @@ public void notify(List urls) { @Test public void testRecover() throws Exception { - CountDownLatch countDownLatch = new CountDownLatch(2); + CountDownLatch countDownLatch = new CountDownLatch(4); final AtomicReference notified = new AtomicReference(false); - NotifyListener listner = new NotifyListener() { + NotifyListener listener = new NotifyListener() { @Override public void notify(List urls) { notified.set(Boolean.TRUE); @@ -195,11 +195,13 @@ public void notify(List urls) { MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch); mockRegistry.register(serviceUrl); - mockRegistry.subscribe(serviceUrl, listner); - Assert.assertEquals(mockRegistry.getRegistered().size(), 1); - Assert.assertEquals(mockRegistry.getSubscribed().size(), 1); + mockRegistry.subscribe(serviceUrl, listener); + Assert.assertEquals(1, mockRegistry.getRegistered().size()); + Assert.assertEquals(1, mockRegistry.getSubscribed().size()); mockRegistry.recover(); - Assert.assertEquals(mockRegistry.getFailedSubscribed().size(), 1); + countDownLatch.await(); + Assert.assertEquals(0, mockRegistry.getFailedRegistered().size()); + Assert.assertEquals(null, mockRegistry.getFailedSubscribed().get(registryUrl)); Assert.assertEquals(countDownLatch.getCount(), 0); } From d5a2e538f6d5b5393b4512e157027b5c959c7efb Mon Sep 17 00:00:00 2001 From: tswstarplanet Date: Thu, 4 Oct 2018 08:45:22 +0800 Subject: [PATCH 3/4] trigger the travis ci test retry --- .../org/apache/dubbo/registry/support/FailbackRegistryTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java index e48892e226d..90ef8d245a0 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java @@ -185,14 +185,12 @@ public void notify(List urls) { public void testRecover() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(4); final AtomicReference notified = new AtomicReference(false); - NotifyListener listener = new NotifyListener() { @Override public void notify(List urls) { notified.set(Boolean.TRUE); } }; - MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch); mockRegistry.register(serviceUrl); mockRegistry.subscribe(serviceUrl, listener); From 1f5229b8f4da680bb8ce7323e303ed7b848b587f Mon Sep 17 00:00:00 2001 From: tswstarplanet Date: Tue, 16 Oct 2018 22:21:41 +0800 Subject: [PATCH 4/4] trigger the code static check again --- .../org/apache/dubbo/registry/support/FailbackRegistryTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java index 90ef8d245a0..7f3ac3a6be0 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java @@ -191,6 +191,7 @@ public void notify(List urls) { notified.set(Boolean.TRUE); } }; + MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch); mockRegistry.register(serviceUrl); mockRegistry.subscribe(serviceUrl, listener);