@Test
@Ignore
public void testSubscribeWhenZookeeperDownAndUp() throws Exception {

    namingUrl = new BrpcURL("zookeeper://127.0.0.1:2181");
    namingService = new ZookeeperNamingService(namingUrl);
    final List<ServiceInstance> adds = new ArrayList<ServiceInstance>();
    final List<ServiceInstance> deletes = new ArrayList<ServiceInstance>();
    SubscribeInfo subscribeInfo = createSubscribeInfo(false);
    namingService.subscribe(subscribeInfo, new NotifyListener() {
        @Override
        public void notify(Collection<ServiceInstance> addList, Collection<ServiceInstance> deleteList) {
            System.out.println("receive new subscribe info time:" + System.currentTimeMillis());
            System.out.println("add size:" + addList.size());
            for (ServiceInstance instance : addList) {
                System.out.println(instance);
            }
            adds.addAll(addList);
            System.out.println("delete size:" + deleteList.size());
            for (ServiceInstance instance : deleteList) {
                System.out.println(instance);
            }
            deletes.addAll(deleteList);
        }
    });
    RegisterInfo registerInfo = createRegisterInfo("127.0.0.1", 8014);
    namingService.register(registerInfo);
    System.out.println("register time=" + System.currentTimeMillis());
    Thread.sleep(1000);
    Assert.assertTrue(adds.size() == 1);
    Assert.assertTrue(deletes.size() == 0);
    Assert.assertTrue(adds.get(0).getIp().equals("127.0.0.1"));
    Assert.assertTrue(adds.get(0).getPort() == 8014);
    adds.clear();
    deletes.clear();
    // sleep for restarting zookeeper
    Thread.sleep(30 * 1000);
    List<ServiceInstance> instances = namingService.lookup(subscribeInfo);
    Assert.assertTrue(instances.size() == 1);
    Assert.assertTrue(instances.get(0).getIp().equals("127.0.0.1"));
    Assert.assertTrue(instances.get(0).getPort() == 8014);
    namingService.unregister(registerInfo);
    System.out.println("unregister time=" + System.currentTimeMillis());
    Thread.sleep(1000);
    Assert.assertTrue(adds.size() == 0);
    Assert.assertTrue(deletes.size() == 1);
    Assert.assertTrue(deletes.get(0).getIp().equals("127.0.0.1"));
    Assert.assertTrue(deletes.get(0).getPort() == 8014);
    namingService.unsubscribe(subscribeInfo);
}