@Test
public void testSubTwice() throws Exception {

    int timeoutPerSub = 5000;
    consumer1 = new ConsumerConfig();
    consumer1.setInterfaceId("com.alipay.xxx.TestService")
        .setUniqueId("unique123Id")
        .setApplication(new ApplicationConfig().setAppName("test-server"))
        .setProxy("javassist")
        .setSubscribe(true)
        .setSerialization("java")
        .setInvokeType("sync")
        .setTimeout(4444);
    // 订阅
    CountDownLatch latch = new CountDownLatch(2);
    MockProviderInfoListener providerInfoListener = new MockProviderInfoListener();
    providerInfoListener.setCountDownLatch(latch);
    consumer1.setProviderInfoListener(providerInfoListener);
    registry.subscribe(consumer1);
    latch.await(timeoutPerSub, TimeUnit.MILLISECONDS);
    Map<String, ProviderGroup> ps = providerInfoListener.getData();
    Assert.assertTrue(ps.size() > 0);
    Assert.assertNotNull(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP));
    Assert.assertEquals(0, ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP).size());
    // 重复订阅
    consumer2 = new ConsumerConfig();
    consumer2.setInterfaceId("com.alipay.xxx.TestService")
        .setUniqueId("unique123Id")
        .setApplication(new ApplicationConfig().setAppName("test-server"))
        .setProxy("javassist")
        .setSubscribe(true)
        .setSerialization("java")
        .setInvokeType("sync")
        .setTimeout(4444);
    CountDownLatch latch2 = new CountDownLatch(1);
    MockProviderInfoListener providerInfoListener2 = new MockProviderInfoListener();
    providerInfoListener2.setCountDownLatch(latch2);
    consumer2.setProviderInfoListener(providerInfoListener2);
    registry.subscribe(consumer2);
    latch2.await(timeoutPerSub, TimeUnit.MILLISECONDS);
    Map<String, ProviderGroup> ps2 = providerInfoListener2.getData();
    Assert.assertTrue(ps2.size() > 0);
    Assert.assertNotNull(ps2.get(RpcConstants.ADDRESS_DEFAULT_GROUP));
    Assert.assertEquals(0, ps2.get(RpcConstants.ADDRESS_DEFAULT_GROUP).size());
    Assert.assertEquals(1, registry.subscribers.size());
    Assert.assertEquals(1, registry.configurators.size());
    latch.await(timeoutPerSub * 2, TimeUnit.MILLISECONDS);
    Assert.assertTrue(ps2.size() > 0);
    Assert.assertNotNull(ps2.get(RpcConstants.ADDRESS_DEFAULT_GROUP));
    Assert.assertEquals(0, ps2.get(RpcConstants.ADDRESS_DEFAULT_GROUP).size());
    Assert.assertEquals(1, registry.subscribers.size()); // 1个服务 订阅服务列表和服务配置 2个dataId
    Assert.assertEquals(1, registry.configurators.size());
}