/** 测试清除override规则,只下发override清除规则 测试是否能够恢复到推送时的providerUrl */
  @Test
  public void testNofityOverrideUrls_CleanOnly() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();

    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
    registryDirectory.notify(durls);
    Assert.assertEquals(null, registryDirectory.getUrl().getParameter("mock"));

    // override
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1000&mock=fail"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Assert.assertEquals("1000", aInvoker.getUrl().getParameter("timeout"));
    Assert.assertEquals("fail", registryDirectory.getUrl().getParameter("mock"));

    // override clean
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0/dubbo.test.api.HelloService"));
    registryDirectory.notify(durls);
    invokers = registryDirectory.list(invocation);
    aInvoker = invokers.get(0);
    // 需要恢复到最初的providerUrl
    Assert.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));

    Assert.assertEquals(null, registryDirectory.getUrl().getParameter("mock"));
  }
 @Test
 public void test_Constructor_CheckStatus() throws Exception {
   URL url =
       URL.valueOf("notsupported://10.20.30.40/" + service + "?a=b")
           .addParameterAndEncoded(Constants.REFER_KEY, "foo=bar");
   RegistryDirectory reg = getRegistryDirectory(url);
   Field field = reg.getClass().getDeclaredField("queryMap");
   field.setAccessible(true);
   Map<String, String> queryMap = (Map<String, String>) field.get(reg);
   Assert.assertEquals("bar", queryMap.get("foo"));
   Assert.assertEquals(url.clearParameters().addParameter("foo", "bar"), reg.getUrl());
 }
  @Test
  public void testParametersMerge() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    URL regurl =
        noMeaningUrl
            .addParameter("test", "reg")
            .addParameterAndEncoded(
                Constants.REFER_KEY,
                "key=query&" + Constants.LOADBALANCE_KEY + "=" + LeastActiveLoadBalance.NAME);
    RegistryDirectory<RegistryDirectoryTest> registryDirectory2 =
        new RegistryDirectory(RegistryDirectoryTest.class, regurl);
    registryDirectory2.setProtocol(protocol);

    List<URL> serviceUrls = new ArrayList<URL>();
    // 检验注册中心的参数需要被清除
    {
      serviceUrls.clear();
      serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
      registryDirectory.notify(serviceUrls);

      invocation = new RpcInvocation();
      List invokers = registryDirectory.list(invocation);

      Invoker invoker = (Invoker) invokers.get(0);
      URL url = invoker.getUrl();
      Assert.assertEquals(null, url.getParameter("key"));
    }
    // 检验服务提供方的参数需要merge
    {
      serviceUrls.clear();
      serviceUrls.add(
          SERVICEURL.addParameter("methods", "getXXX2").addParameter("key", "provider"));

      registryDirectory.notify(serviceUrls);
      invocation = new RpcInvocation();
      List invokers = registryDirectory.list(invocation);

      Invoker invoker = (Invoker) invokers.get(0);
      URL url = invoker.getUrl();
      Assert.assertEquals("provider", url.getParameter("key"));
    }
    // 检验服务query的参数需要与providermerge 。
    {
      serviceUrls.clear();
      serviceUrls.add(
          SERVICEURL.addParameter("methods", "getXXX3").addParameter("key", "provider"));

      registryDirectory2.notify(serviceUrls);
      invocation = new RpcInvocation();
      List invokers = registryDirectory2.list(invocation);

      Invoker invoker = (Invoker) invokers.get(0);
      URL url = invoker.getUrl();
      Assert.assertEquals("query", url.getParameter("key"));
    }

    {
      serviceUrls.clear();
      serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
      registryDirectory.notify(serviceUrls);

      invocation = new RpcInvocation();
      List invokers = registryDirectory.list(invocation);

      Invoker invoker = (Invoker) invokers.get(0);
      URL url = invoker.getUrl();
      Assert.assertEquals(false, url.getParameter(Constants.CHECK_KEY, false));
    }
    {
      serviceUrls.clear();
      serviceUrls.add(
          SERVICEURL.addParameter(Constants.LOADBALANCE_KEY, RoundRobinLoadBalance.NAME));
      registryDirectory2.notify(serviceUrls);

      invocation = new RpcInvocation();
      invocation.setMethodName("get");
      List invokers = registryDirectory2.list(invocation);

      Invoker invoker = (Invoker) invokers.get(0);
      URL url = invoker.getUrl();
      Assert.assertEquals(
          LeastActiveLoadBalance.NAME, url.getMethodParameter("get", Constants.LOADBALANCE_KEY));
    }
    // test geturl
    {
      Assert.assertEquals(null, registryDirectory2.getUrl().getParameter("mock"));
      serviceUrls.clear();
      serviceUrls.add(SERVICEURL.addParameter(Constants.MOCK_KEY, "true"));
      registryDirectory2.notify(serviceUrls);

      Assert.assertEquals("true", registryDirectory2.getUrl().getParameter("mock"));
    }
  }