Search in sources :

Example 1 with LoadBalancerTestState

use of com.linkedin.d2.balancer.LoadBalancerTestState in project rest.li by linkedin.

the class SimpleLoadBalancerTest method testLoadBalancerWithWait.

@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithWait() throws URISyntaxException, ServiceUnavailableException, InterruptedException {
    URIRequest uriRequest = new URIRequest("d2://NonExistentService");
    LoadBalancerTestState state = new LoadBalancerTestState();
    SimpleLoadBalancer balancer = new SimpleLoadBalancer(state, 5, TimeUnit.SECONDS);
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.listenToService = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.isListeningToService = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.getServiceProperties = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.listenToCluster = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.isListeningToCluster = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.getClusterProperties = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.getUriProperties = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.getClient = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.getStrategy = true;
    try {
        balancer.getClient(uriRequest, new RequestContext());
        fail("should have received a service unavailable exception");
    } catch (ServiceUnavailableException e) {
    }
    state.getPartitionAccessor = true;
    // victory
    assertNotNull(balancer.getClient(uriRequest, new RequestContext()));
}
Also used : URIRequest(com.linkedin.d2.balancer.util.URIRequest) PartitionedLoadBalancerTestState(com.linkedin.d2.balancer.PartitionedLoadBalancerTestState) LoadBalancerTestState(com.linkedin.d2.balancer.LoadBalancerTestState) RequestContext(com.linkedin.r2.message.RequestContext) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) Test(org.testng.annotations.Test)

Aggregations

LoadBalancerTestState (com.linkedin.d2.balancer.LoadBalancerTestState)1 PartitionedLoadBalancerTestState (com.linkedin.d2.balancer.PartitionedLoadBalancerTestState)1 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 URIRequest (com.linkedin.d2.balancer.util.URIRequest)1 RequestContext (com.linkedin.r2.message.RequestContext)1 Test (org.testng.annotations.Test)1