HttpDiscoveryLookupClient implements DiscoveryLookupClient { @Override public ListenableFuture<ServiceDescriptors> getServices(String type) { requireNonNull(type, "type is null"); return lookup(type, null, null); } @Inject  HttpDiscoveryLookupClient(NodeInfo nodeInfo,
            JsonCodec<ServiceDescriptorsRepresentation> serviceDescriptorsCodec,
            @ForDiscoveryClient HttpClient httpClient,
            ServiceInventory serviceInventory); @Flatten RequestStats getStats(); @Override ListenableFuture<ServiceDescriptors> getServices(String type); @Override ListenableFuture<ServiceDescriptors> getServices(String type, String pool); @Override ListenableFuture<ServiceDescriptors> refreshServices(ServiceDescriptors serviceDescriptors);  }
@Test public void testGetServicesPool() throws Exception { ServiceDescriptors descriptors = createClient(createProcessor(null, null, "testingenvironment")) .getServices("testService", "testPool") .get(); assertDescriptorsExpected(descriptors, null, DEFAULT_DELAY); }
@Test public void testReturnedEtag() throws Exception { ServiceDescriptors descriptors = createClient(createProcessor(ImmutableListMultimap.of("ETag", "testEtagValue"), null, "testingenvironment")) .getServices("testService", "testPool") .get(); assertDescriptorsExpected(descriptors, "testEtagValue", DEFAULT_DELAY); }
@Test public void testReturnedMaxAge() throws Exception { ServiceDescriptors descriptors = createClient(createProcessor(ImmutableListMultimap.of("Cache-Control", "max-age=671"), null, "testingenvironment")) .getServices("testService", "testPool") .get(); assertDescriptorsExpected(descriptors, null, new Duration(671, SECONDS)); }
@Test public void testGetServicesNotModified() { ListenableFuture<ServiceDescriptors> future = createClient( request -> mockResponse() .status(NOT_MODIFIED) .header("ETag", "newEtag") .header("Cache-Control", "max-age=123") .build()) .getServices("testService", "testPool"); try { future.get(); fail("Expected ExecutionException"); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { assertInstanceOf(e.getCause(), DiscoveryException.class); assertNull(e.getCause().getCause()); assertEquals(e.getCause().getMessage(), "Lookup of testService failed with status code 304"); } }
@Test public void testGetServicesInputStreamException() throws Exception { final IOException testingException = new IOException("testing exception"); ListenableFuture<ServiceDescriptors> future = createClient( request -> mockResponse() .contentType(MediaType.JSON_UTF_8) .body(new InputStream() { @Override public int read() throws IOException { throw testingException; } }) .build()) .getServices("testService", "testPool"); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException e) { assertInstanceOf(e.getCause(), DiscoveryException.class); assertSame(e.getCause().getCause(), testingException); assertEquals(e.getCause().getMessage(), "Lookup of testService failed"); } }
@Test public void testGetServicesWrongEnvironment() throws Exception { ListenableFuture<ServiceDescriptors> future = createClient(createProcessor(null, null, "wrongenvironment")) .getServices("testService", "testPool"); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException e) { assertInstanceOf(e.getCause(), DiscoveryException.class); assertNull(e.getCause().getCause()); assertEquals(e.getCause().getMessage(), "Expected environment to be testingenvironment, but was wrongenvironment"); } }
@Test public void testGetServicesHttpException() throws Exception { final Exception testingException = new Exception("testing exception"); ListenableFuture<ServiceDescriptors> future = createClient( request -> { throw testingException; }) .getServices("testService", "testPool"); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException e) { assertInstanceOf(e.getCause(), DiscoveryException.class); assertEquals(e.getCause().getCause(), testingException); assertEquals(e.getCause().getMessage(), "Lookup of testService failed"); } }