Search in sources :

Example 1 with PureConsistentHashBalancerAlgorithm

use of org.mobicents.tools.sip.balancer.PureConsistentHashBalancerAlgorithm in project load-balancer by RestComm.

the class ConsistentHashDistributionTest method testDistribution.

@Test
public void testDistribution() {
    PureConsistentHashBalancerAlgorithm algo = new PureConsistentHashBalancerAlgorithm();
    for (Integer i = 0; i < 12199; i++) {
        System.out.println(Integer.toString(algo.digest(i.toString()), 2));
        assertTrue(set.add(new Integer(algo.digest(i.toString()))));
    }
    boolean[] bits = new boolean[32];
    for (int q = 0; q < 31; q++) {
        boolean has1 = false;
        boolean has0 = false;
        for (Integer i : set) {
            boolean isOne = (i & (1 << q)) > 0;
            if (isOne)
                has1 = true;
            else
                has0 = true;
            if (has1 && has0)
                break;
        }
        if (has1 && has0) {
            bits[q] = true;
        }
    }
    for (int q = 0; q < 31; q++) {
        assertTrue(bits[q]);
    }
}
Also used : PureConsistentHashBalancerAlgorithm(org.mobicents.tools.sip.balancer.PureConsistentHashBalancerAlgorithm) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 PureConsistentHashBalancerAlgorithm (org.mobicents.tools.sip.balancer.PureConsistentHashBalancerAlgorithm)1