ListNamingService implements NamingService { @Override public List<ServiceInstance> lookup(SubscribeInfo subscribeInfo) { for (ServiceInstance instance : instances) { if (subscribeInfo != null && StringUtils.isNoneBlank(subscribeInfo.getServiceId())) { instance.setServiceName(subscribeInfo.getServiceId()); } } return instances; } ListNamingService(BrpcURL namingUrl); @Override List<ServiceInstance> lookup(SubscribeInfo subscribeInfo); @Override void subscribe(SubscribeInfo subscribeInfo, final NotifyListener listener); @Override void unsubscribe(SubscribeInfo subscribeInfo); @Override void register(RegisterInfo registerInfo); @Override void unregister(RegisterInfo registerInfo); @Override void destroy();  }
@Test public void testUpdateServerList() { String serverList = "list: ListNamingService namingService = new ListNamingService(new BrpcURL(serverList)); List<ServiceInstance> instances = namingService.lookup(null); assertThat(instances, hasItems( new ServiceInstance("1.1.1.1", 1111), new ServiceInstance("2.2.2.2", 2222) )); assertThat(instances.size(), is(2)); }
@Test(expected = IllegalArgumentException.class) public void testUpdateServerListInvalid1() { ListNamingService namingService = new ListNamingService(new BrpcURL("")); namingService.lookup(null); }
@Test(expected = IllegalArgumentException.class) public void testUpdateServerListInvalid2() { ListNamingService namingService = new ListNamingService(new BrpcURL("1.1.1.1,2.2.2.2")); namingService.lookup(null); }