Search in sources :

Example 1 with EndpointConfiguration

use of io.mantisrx.common.network.EndpointConfiguration in project mantis by Netflix.

the class ConsistentHashTest method emptyNodeThrowsTest.

@Test
public void emptyNodeThrowsTest() {
    List<Endpoint> nodes = new ArrayList<Endpoint>();
    try {
        ConsistentHash<Endpoint> ch = new ConsistentHash<Endpoint>(HashFunctions.ketama(), new EndpointConfiguration(), nodes);
        fail();
    } catch (Exception e) {
    }
}
Also used : ConsistentHash(io.mantisrx.common.network.ConsistentHash) Endpoint(io.mantisrx.common.network.Endpoint) ArrayList(java.util.ArrayList) EndpointConfiguration(io.mantisrx.common.network.EndpointConfiguration) Test(org.junit.Test)

Example 2 with EndpointConfiguration

use of io.mantisrx.common.network.EndpointConfiguration in project mantis by Netflix.

the class ConsistentHashTest method oneNodeTest.

@Test
public void oneNodeTest() {
    Endpoint n1 = new Endpoint("host1", 7001);
    List<Endpoint> nodes = new ArrayList<Endpoint>();
    nodes.add(n1);
    ConsistentHash<Endpoint> ch = new ConsistentHash<Endpoint>(HashFunctions.ketama(), new EndpointConfiguration(), nodes);
    int hostHitCountNode1 = 0;
    int nonHitCount = 0;
    int MSG_COUNT = 100000;
    for (int i = 0; i < MSG_COUNT; i++) {
        Endpoint sn = ch.get(("msg:" + i).getBytes());
        if (sn.getHost().equals("host1")) {
            hostHitCountNode1++;
        } else {
            nonHitCount++;
        }
    }
    assertTrue(nonHitCount == 0);
    assertEquals(MSG_COUNT, hostHitCountNode1);
}
Also used : ConsistentHash(io.mantisrx.common.network.ConsistentHash) Endpoint(io.mantisrx.common.network.Endpoint) ArrayList(java.util.ArrayList) EndpointConfiguration(io.mantisrx.common.network.EndpointConfiguration) Endpoint(io.mantisrx.common.network.Endpoint) Test(org.junit.Test)

Example 3 with EndpointConfiguration

use of io.mantisrx.common.network.EndpointConfiguration in project mantis by Netflix.

the class ConsistentHashTest method twoNodeTest.

@Test
public void twoNodeTest() {
    Endpoint n1 = new Endpoint("host1", 7001);
    Endpoint n2 = new Endpoint("host2", 7001);
    List<Endpoint> nodes = new ArrayList<Endpoint>();
    nodes.add(n1);
    nodes.add(n2);
    ConsistentHash<Endpoint> ch = new ConsistentHash<Endpoint>(HashFunctions.ketama(), new EndpointConfiguration(), nodes);
    int hostHitCountNode1 = 0;
    int hostHitCountNode2 = 0;
    int nonHitCount = 0;
    int MSG_COUNT = 100000;
    for (int i = 0; i < MSG_COUNT; i++) {
        Endpoint sn = ch.get(("msg:" + i).getBytes());
        if (sn.getHost().equals("host1")) {
            hostHitCountNode1++;
        } else if (sn.getHost().equals("host2")) {
            hostHitCountNode2++;
        } else {
            nonHitCount++;
        }
    }
    double host1HitPercentage = (double) hostHitCountNode1 / (double) MSG_COUNT;
    System.out.println("host1 hit % " + host1HitPercentage);
    assertTrue(host1HitPercentage > 0.48 && host1HitPercentage < 0.52);
    assertTrue(nonHitCount == 0);
    assertEquals(MSG_COUNT, hostHitCountNode1 + hostHitCountNode2);
}
Also used : ConsistentHash(io.mantisrx.common.network.ConsistentHash) Endpoint(io.mantisrx.common.network.Endpoint) ArrayList(java.util.ArrayList) EndpointConfiguration(io.mantisrx.common.network.EndpointConfiguration) Endpoint(io.mantisrx.common.network.Endpoint) Test(org.junit.Test)

Aggregations

ConsistentHash (io.mantisrx.common.network.ConsistentHash)3 Endpoint (io.mantisrx.common.network.Endpoint)3 EndpointConfiguration (io.mantisrx.common.network.EndpointConfiguration)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3