@Test public void testExecuteWithLB() throws Exception { ConfigurationManager.getConfigInstance() .setProperty("allservices.ribbon." + CommonClientConfigKey.ReadTimeout, "10000"); ConfigurationManager.getConfigInstance() .setProperty("allservices.ribbon." + CommonClientConfigKey.FollowRedirects, "true"); RestClient client = (RestClient) ClientFactory.getNamedClient("allservices"); BaseLoadBalancer lb = new BaseLoadBalancer(); Server[] servers = new Server[] {new Server("localhost", server.getServerPort())}; lb.addServers(Arrays.asList(servers)); client.setLoadBalancer(lb); Set<URI> expected = new HashSet<URI>(); expected.add(new URI(server.getServerPath("/"))); Set<URI> result = new HashSet<URI>(); HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build(); for (int i = 0; i < 5; i++) { HttpResponse response = client.executeWithLoadBalancer(request); assertStatusIsOk(response.getStatus()); assertTrue(response.isSuccess()); String content = response.getEntity(String.class); response.close(); assertFalse(content.isEmpty()); result.add(response.getRequestedURI()); } assertEquals(expected, result); request = HttpRequest.newBuilder().uri(server.getServerURI()).build(); HttpResponse response = client.executeWithLoadBalancer(request); assertEquals(200, response.getStatus()); }
@Test public void testSecureClient2() throws Exception { ConfigurationManager.getConfigInstance() .setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true"); ConfigurationManager.getConfigInstance() .setProperty( "test3.ribbon." + CommonClientConfigKey.TrustStore, secureServer.getTrustStore().getAbsolutePath()); ConfigurationManager.getConfigInstance() .setProperty( "test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD); RestClient client = (RestClient) ClientFactory.getNamedClient("test3"); BaseLoadBalancer lb = new BaseLoadBalancer(); Server[] servers = new Server[] {new Server("localhost", secureServer.getServerPort())}; lb.addServers(Arrays.asList(servers)); client.setLoadBalancer(lb); HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build(); HttpResponse response = client.executeWithLoadBalancer(request); assertStatusIsOk(response.getStatus()); assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString()); }