Example usage for org.apache.cassandra.locator EndpointSnitchInfoMBean EndpointSnitchInfoMBean

List of usage examples for org.apache.cassandra.locator EndpointSnitchInfoMBean EndpointSnitchInfoMBean

Introduction

In this page you can find the example usage for org.apache.cassandra.locator EndpointSnitchInfoMBean EndpointSnitchInfoMBean.

Prototype

EndpointSnitchInfoMBean

Source Link

Usage

From source file:org.ayache.cassandra.repair.scheduler.NodeChooserTest.java

/**
 * Test of getNextNodeToRepair method, of class NodeChooser.
 *///from  w w w  . j  av  a2s.  com
@Test
public void testGetNextNodeToRepair() throws Exception {
    System.out.println("getNextNodeToRepair");
    StorageServiceMBean mock = Mockito.mock(StorageServiceMBean.class);
    List<String> nodes = Arrays.asList("127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5",
            "127.0.0.6", "127.0.0.7", "127.0.0.8", "127.0.0.9");
    Map<InetAddress, Float> ownership = new HashMap<>();
    Map<String, String> tokenToEndpoints = new LinkedHashMap<>();
    int Rf = 3;
    for (String node : nodes) {
        ownership.put(InetAddress.getByName(node), 1f / nodes.size() * (float) Rf);
        tokenToEndpoints.put(node, node);
    }
    Mockito.when(mock.getKeyspaces()).thenReturn(Arrays.asList("TestKeyspace"));
    Mockito.when(mock.effectiveOwnership(Mockito.anyString())).thenReturn(ownership);
    Mockito.when(mock.getLiveNodes()).thenReturn(nodes);
    Mockito.when(mock.getTokenToEndpointMap()).thenReturn(tokenToEndpoints);
    NodeChooser instance = new NodeChooser(mock, new EndpointSnitchInfoMBean() {
        @Override
        public String getRack(String host) throws UnknownHostException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public String getDatacenter(String host) throws UnknownHostException {
            return "DC1";
        }

        @Override
        public String getSnitchName() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }, "DC1", null, true);
    Collection<String> expResult = new HashSet<>(Arrays.asList("127.0.0.1", "127.0.0.5"));
    Collection<String> result = instance.getNextNodeToRepair();
    assertEquals(expResult, result);

    instance = new NodeChooser(mock, new EndpointSnitchInfoMBean() {
        @Override
        public String getRack(String host) throws UnknownHostException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public String getDatacenter(String host) throws UnknownHostException {
            return "DC1";
        }

        @Override
        public String getSnitchName() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }, "DC1", "127.0.0.2", true);
    expResult = new HashSet<>(Arrays.asList("127.0.0.3", "127.0.0.7"));
    result = instance.getNextNodeToRepair();
    assertEquals(expResult, result);

    instance = new NodeChooser(mock, new EndpointSnitchInfoMBean() {
        @Override
        public String getRack(String host) throws UnknownHostException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public String getDatacenter(String host) throws UnknownHostException {
            return "DC1";
        }

        @Override
        public String getSnitchName() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }, "DC1", "127.0.0.8", true);
    expResult = new HashSet<>(Arrays.asList("127.0.0.9", "127.0.0.4"));
    result = instance.getNextNodeToRepair();
    assertEquals(expResult, result);

    instance = new NodeChooser(mock, new EndpointSnitchInfoMBean() {
        @Override
        public String getRack(String host) throws UnknownHostException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public String getDatacenter(String host) throws UnknownHostException {
            return "DC1";
        }

        @Override
        public String getSnitchName() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }, "DC1", "127.0.0.9", true);
    expResult = new HashSet<>(Arrays.asList("127.0.0.1", "127.0.0.5"));
    result = instance.getNextNodeToRepair();
    assertEquals(expResult, result);
    //        // TODO review the generated test code and remove the default call to fail.
    //        fail("The test case is a prototype.");
}