补充testcase

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@162 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
chao.liuc 2011-11-01 08:29:38 +00:00
parent eda6a55816
commit a0de8e050e
1 changed files with 25 additions and 4 deletions

View File

@ -349,8 +349,8 @@ public class RegistryDirectoryTest {
registryDirectory.destroy();
Assert.assertEquals(false, registryDirectory.isAvailable());
Assert.assertEquals(false, invokers.get(0).isAvailable());
registryDirectory.destroy();
Map<String, List<Invoker<RegistryDirectoryTest>>> methodInvokerMap = registryDirectory.getMethodInvokerMap();
Map<String, Invoker<RegistryDirectoryTest>> 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.");
}
}
}
}