Example #1
0
  @Test
  public void test() throws NotRegisteredException {
    Consul consul =
        Consul.builder().withHostAndPort(HostAndPort.fromParts("192.168.1.245", 8500)).build();
    AgentClient agentClient = consul.agentClient();

    ImmutableRegistration regist =
        ImmutableRegistration.builder()
            .id("1")
            .name("MyService")
            .address("192.168.1.99")
            .port(8888)
            .addTags("mok")
            .build();

    ImmutableRegistration regist2 =
        ImmutableRegistration.builder()
            .id("2")
            .name("MyService")
            .address("192.168.1.100")
            .port(8888)
            .addTags("mok")
            .build();

    consul.agentClient().register(regist);

    agentClient.register(regist2);
  }
  @Override
  protected void doPreSetup() throws Exception {
    client = getConsul().agentClient();

    registrations = new ArrayList<>(SERVICE_COUNT);
    expectedBodies = new ArrayList<>(SERVICE_COUNT);

    for (int i = 0; i < SERVICE_COUNT; i++) {
      Registration r =
          ImmutableRegistration.builder()
              .id("service-" + i)
              .name(SERVICE_NAME)
              .address("127.0.0.1")
              .port(SERVICE_PORT_BASE + i)
              .build();

      client.register(r);

      registrations.add(r);
      expectedBodies.add("ping on " + r.getPort().get());
    }
  }
 @Override
 public void tearDown() throws Exception {
   super.tearDown();
   registrations.forEach(r -> client.deregister(r.getId()));
 }