@Test
public void testRegisterAndSubscribe() throws InterruptedException {

    RegisterInfo registerInfo = createRegisterInfo("127.0.0.1", 8015);
    RegisterInfo anotherRegisterInfo = createRegisterInfo("127.0.0.1", 8016);
    consulNamingService.register(registerInfo);
    consulNamingService.register(anotherRegisterInfo);
    Thread.sleep(3 * 1000);
    SubscribeInfo subscribeInfo = createSubscribeInfo(false);
    final List<ServiceInstance> adds = consulNamingService.lookup(subscribeInfo);
    Assert.assertTrue(adds.size() == 2);
    adds.clear();
    final List<ServiceInstance> deletes = new ArrayList<ServiceInstance>();
    consulNamingService.subscribe(subscribeInfo, new NotifyListener() {
        @Override public void notify(Collection<ServiceInstance> addList,
                                     Collection<ServiceInstance> deleteList) {
            adds.addAll(addList);
            deletes.addAll(deleteList);
            log.info("notify: {}, {}", addList, deleteList);
        }
    });
    consulNamingService.unregister(registerInfo);
    Thread.sleep(3 * 1000);
    Assert.assertTrue(adds.size() == 0);
    Assert.assertTrue(deletes.size() == 1);
    Assert.assertTrue(deletes.get(0).equals(new ServiceInstance("127.0.0.1", 8015)));
    adds.clear();
    deletes.clear();
    consulNamingService.register(registerInfo);
    Thread.sleep(3 * 1000);
    Assert.assertTrue(adds.size() == 1);
    Assert.assertTrue(deletes.size() == 0);
    Assert.assertTrue(adds.get(0).equals(new ServiceInstance("127.0.0.1", 8015)));
}