use of com.linkedin.d2.balancer.util.downstreams.DownstreamServicesFetcher in project rest.li by linkedin.
the class WarmUpLoadBalancerTest method testDeletingFilesAfterShutdown.
@Test(timeOut = 10000, groups = { "ci-flaky" })
public void testDeletingFilesAfterShutdown() throws InterruptedException, ExecutionException, TimeoutException {
createDefaultServicesIniFiles();
TestLoadBalancer balancer = new TestLoadBalancer();
List<String> allServicesBeforeShutdown = getAllDownstreamServices();
List<String> partialServices = getPartialDownstreams();
DownstreamServicesFetcher returnPartialDownstreams = callback -> callback.onSuccess(partialServices);
LoadBalancer warmUpLoadBalancer = new WarmUpLoadBalancer(balancer, balancer, Executors.newSingleThreadScheduledExecutor(), _tmpdir.getAbsolutePath(), MY_SERVICES_FS, returnPartialDownstreams, WarmUpLoadBalancer.DEFAULT_SEND_REQUESTS_TIMEOUT_SECONDS, WarmUpLoadBalancer.DEFAULT_CONCURRENT_REQUESTS);
FutureCallback<None> callback = new FutureCallback<>();
warmUpLoadBalancer.start(callback);
callback.get(5000, TimeUnit.MILLISECONDS);
FutureCallback<None> shutdownCallback = new FutureCallback<>();
warmUpLoadBalancer.shutdown(() -> shutdownCallback.onSuccess(None.none()));
shutdownCallback.get(5000, TimeUnit.MILLISECONDS);
List<String> allServicesAfterShutdown = getAllDownstreamServices();
Assert.assertTrue(allServicesBeforeShutdown.size() > partialServices.size(), "After shutdown the unused services should have been deleted. Expected lower number of:" + allServicesBeforeShutdown.size() + ", actual " + partialServices.size());
Assert.assertTrue(partialServices.containsAll(allServicesAfterShutdown) && allServicesAfterShutdown.containsAll(partialServices), "There should be just the services that were passed by the partial fetcher");
}
use of com.linkedin.d2.balancer.util.downstreams.DownstreamServicesFetcher in project rest.li by linkedin.
the class WarmUpLoadBalancerTest method testNotDeletingFilesGetClient.
/**
* Since the list might from the fetcher might not be complete (update service, old data, etc.., and the user might
* require additional services at runtime, we have to check that those services are not cleared from the cache
* otherwise it would incur in a penalty at the next deployment
*/
@Test(timeOut = 10000)
public void testNotDeletingFilesGetClient() throws InterruptedException, ExecutionException, TimeoutException, ServiceUnavailableException {
createDefaultServicesIniFiles();
TestLoadBalancer balancer = new TestLoadBalancer();
List<String> allServicesBeforeShutdown = getAllDownstreamServices();
DownstreamServicesFetcher returnNoDownstreams = callback -> callback.onSuccess(Collections.emptyList());
String pickOneService = allServicesBeforeShutdown.get(0);
LoadBalancer warmUpLoadBalancer = new WarmUpLoadBalancer(balancer, balancer, Executors.newSingleThreadScheduledExecutor(), _tmpdir.getAbsolutePath(), MY_SERVICES_FS, returnNoDownstreams, WarmUpLoadBalancer.DEFAULT_SEND_REQUESTS_TIMEOUT_SECONDS, WarmUpLoadBalancer.DEFAULT_CONCURRENT_REQUESTS);
FutureCallback<None> callback = new FutureCallback<>();
warmUpLoadBalancer.start(callback);
callback.get(5000, TimeUnit.MILLISECONDS);
warmUpLoadBalancer.getClient(new URIRequest("d2://" + pickOneService), new RequestContext());
FutureCallback<None> shutdownCallback = new FutureCallback<>();
warmUpLoadBalancer.shutdown(() -> shutdownCallback.onSuccess(None.none()));
shutdownCallback.get(5000, TimeUnit.MILLISECONDS);
List<String> allServicesAfterShutdown = getAllDownstreamServices();
Assert.assertEquals(1, allServicesAfterShutdown.size(), "After shutdown there should be just one service, the one that we 'get the client' on");
}
Aggregations