Search in sources :

Example 1 with ConsulServerList

use of org.springframework.cloud.consul.discovery.ConsulServerList in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationCustomizedInstanceGroupTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-WithGroup");
    assertNotNull("service was null", service);
    assertNotEquals("service port is 0", 0, service.getPort().intValue());
    assertEquals("service id was wrong", "myTestService1-WithGroup", service.getId());
    assertTrue("service group was wrong", service.getTags().contains("group=test"));
    ConsulServerList serverList = new ConsulServerList(consul, properties);
    DefaultClientConfigImpl config = new DefaultClientConfigImpl();
    config.setClientName("myTestService-WithGroup");
    serverList.initWithNiwsConfig(config);
    List<ConsulServer> servers = serverList.getInitialListOfServers();
    assertEquals("servers was wrong size", 1, servers.size());
    assertEquals("service group was wrong", "test", servers.get(0).getMetaInfo().getServerGroup());
}
Also used : ConsulServerList(org.springframework.cloud.consul.discovery.ConsulServerList) Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) ConsulServer(org.springframework.cloud.consul.discovery.ConsulServer) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Service (com.ecwid.consul.v1.agent.model.Service)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 Map (java.util.Map)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ConsulServer (org.springframework.cloud.consul.discovery.ConsulServer)1 ConsulServerList (org.springframework.cloud.consul.discovery.ConsulServerList)1