Search in sources :

Example 1 with StickyLoadBalancer

use of io.fabric8.gateway.loadbalancer.StickyLoadBalancer in project fabric8 by jboss-fuse.

the class LoadBalancerTest method testStickyLoadBalancer.

@Test
public void testStickyLoadBalancer() throws Exception {
    assertLoadBalancerWorksOnEmptyOrSingletonServices(new StickyLoadBalancer());
    LoadBalancer loadBalancer = new StickyLoadBalancer();
    Set<String> allRequests = new HashSet<String>();
    int numberOfClients = 10;
    for (int i = 0; i < numberOfClients; i++) {
        clientRequestKey = "newClient:" + i;
        List<String> results = performRequests(loadBalancer);
        Set<String> set = asSet(results);
        assertTrue("All values should be the same for client: " + clientRequestKey + " but got: " + set, set.size() == 1);
        allRequests.addAll(set);
    }
    // now we should have a reasonable number of different overall answers.
    assertTrue("Across " + numberOfClients + " we should have most of the values: " + allRequests, allRequests.size() > 1);
}
Also used : RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) StickyLoadBalancer(io.fabric8.gateway.loadbalancer.StickyLoadBalancer) RandomLoadBalancer(io.fabric8.gateway.loadbalancer.RandomLoadBalancer) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) StickyLoadBalancer(io.fabric8.gateway.loadbalancer.StickyLoadBalancer) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)1 RandomLoadBalancer (io.fabric8.gateway.loadbalancer.RandomLoadBalancer)1 RoundRobinLoadBalancer (io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer)1 StickyLoadBalancer (io.fabric8.gateway.loadbalancer.StickyLoadBalancer)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1