@Test
 public void testDestroy_WithDestroyRegistry() {
   RegistryDirectory registryDirectory = getRegistryDirectory();
   CountDownLatch latch = new CountDownLatch(1);
   registryDirectory.setRegistry(new MockRegistry(latch));
   registryDirectory.subscribe(
       URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/DemoService?category=providers"));
   registryDirectory.destroy();
   Assert.assertEquals(0, latch.getCount());
 }
  /**
   * When destroying, RegistryDirectory should: 1. be disconnected from Registry 2. destroy all
   * invokers
   */
  @Test
  public void testDestroy() {
    RegistryDirectory registryDirectory = getRegistryDirectory();

    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1,getXXX2,getXXX3"));

    registryDirectory.notify(serviceUrls);
    List<Invoker> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    Assert.assertEquals(true, invokers.get(0).isAvailable());

    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();

    Assert.assertTrue(methodInvokerMap == null);
    Assert.assertEquals(0, urlInvokerMap.size());
    // List<U> urls = mockRegistry.getSubscribedUrls();

    RpcInvocation inv = new RpcInvocation();
    try {
      registryDirectory.list(inv);
      fail();
    } catch (RpcException e) {
      Assert.assertTrue(e.getMessage().contains("already destroyed"));
    }
  }
 @Test
 public void testDestroy_WithDestroyRegistry_WithError() {
   RegistryDirectory registryDirectory = getRegistryDirectory();
   registryDirectory.setRegistry(new MockRegistry(true));
   registryDirectory.destroy();
 }