From a0de8e050eda2c214aaf501a382217afdd2c6281 Mon Sep 17 00:00:00 2001 From: "chao.liuc" Date: Tue, 1 Nov 2011 08:29:38 +0000 Subject: [PATCH] =?UTF-8?q?DUBBO-22=20=E8=A1=A5=E5=85=85testcase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@162 1a56cb94-b969-4eaa-88fa-be21384802f2 --- .../registry/dubbo/RegistryDirectoryTest.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/RegistryDirectoryTest.java b/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/RegistryDirectoryTest.java index efcebf2f65..41e979f993 100644 --- a/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/RegistryDirectoryTest.java +++ b/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/RegistryDirectoryTest.java @@ -349,8 +349,8 @@ public class RegistryDirectoryTest { registryDirectory.destroy(); Assert.assertEquals(false, registryDirectory.isAvailable()); Assert.assertEquals(false, invokers.get(0).isAvailable()); - registryDirectory.destroy(); + Map>> methodInvokerMap = registryDirectory.getMethodInvokerMap(); Map> urlInvokerMap = registryDirectory.getUrlInvokerMap(); @@ -366,7 +366,22 @@ public class RegistryDirectoryTest { } catch (RpcException e) { Assert.assertTrue(e.getMessage().contains("already destroyed")); } - + } + + @Test + public void testDestroy_WithDestroyRegistry(){ + RegistryDirectory registryDirectory = getRegistryDirectory(); + CountDownLatch latch = new CountDownLatch(1); + registryDirectory.setRegistry(new MockRegistry(latch)); + registryDirectory.destroy(); + Assert.assertEquals(0, latch.getCount()); + } + + @Test + public void testDestroy_WithDestroyRegistry_WithError(){ + RegistryDirectory registryDirectory = getRegistryDirectory(); + registryDirectory.setRegistry(new MockRegistry(true)); + registryDirectory.destroy(); } @Test @@ -490,9 +505,13 @@ public class RegistryDirectoryTest { private static interface DemoService {} private static class MockRegistry implements Registry{ CountDownLatch latch ; + boolean destroyWithError ; public MockRegistry(CountDownLatch latch) { this.latch = latch; } + public MockRegistry(boolean destroyWithError) { + this.destroyWithError = destroyWithError; + } public void register(URL url) { } @@ -512,10 +531,12 @@ public class RegistryDirectoryTest { return null; } public boolean isAvailable() { - return false; + return true; } public void destroy() { - + if (destroyWithError){ + throw new RpcException("test exception ignore."); + } } } } \ No newline at end of file