Search in sources :

Example 11 with LoadBalancerEchoServer

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

the class D2BaseTest method assertServersWeighSetup.

protected void assertServersWeighSetup(Map<LoadBalancerEchoServer, Map<Integer, Double>> hostWeightMatrix, LoadBalancerClientCli cli, String zkConnectionString) throws Exception {
    String stores = LoadBalancerClientCli.printStores(cli.getZKClient(), zkConnectionString, "/d2");
    for (LoadBalancerEchoServer server : hostWeightMatrix.keySet()) {
        String str = server.getHost() + ": " + server.getPort() + "/cluster-\\d+=" + hostWeightMatrix.get(server);
        Pattern pattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(stores);
        assertTrue(matcher.find(), "URIProperty '" + str + "' was not found is current active clusters.\n" + stores);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer)

Example 12 with LoadBalancerEchoServer

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

the class D2BaseTest method createServerWeightDataMap.

protected static Map<LoadBalancerEchoServer, Map<Integer, Double>> createServerWeightDataMap(List<LoadBalancerEchoServer> servers, int partitionId, Double[] weight) {
    Map<LoadBalancerEchoServer, Map<Integer, Double>> hash = new HashMap<LoadBalancerEchoServer, Map<Integer, Double>>();
    int count = 0;
    for (LoadBalancerEchoServer server : servers) {
        if (count < weight.length) {
            Map<Integer, Double> partitionWeight = new HashMap<Integer, Double>();
            partitionWeight.put(new Integer(partitionId), weight[count]);
            hash.put(server, partitionWeight);
            count++;
        } else {
            break;
        }
    }
    return hash;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with LoadBalancerEchoServer

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

the class TestPartitionsWithZKQuorum method testRegisterUnregisterAllEchoServers.

@Test
public void testRegisterUnregisterAllEchoServers() throws IOException, URISyntaxException, PropertyStoreException, ExecutionException, TimeoutException, InterruptedException, Exception {
    _echoServers = new ArrayList<LoadBalancerEchoServer>();
    setup();
    assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_DATA), 0);
    _cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
    _client = _cli.createZKFSTogglingLBClient(_quorum.getHosts(), "/d2", null);
    // Echo servers startup
    Map<Integer, Double> partitionWeight = new HashMap<Integer, Double>();
    partitionWeight.put(new Integer(1), new Double(1.0d));
    startAllEchoServers(partitionWeight);
    assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
    assertQuorumProcessAllRequests(D2_CONFIG_DATA);
    // Markdown echo servers
    stopAllEchoServers(_echoServers);
    assertAllEchoServersUnregistered(_cli.getZKClient(), _zkUriString, _echoServers);
}
Also used : LoadBalancerClientCli(com.linkedin.d2.balancer.util.LoadBalancerClientCli) HashMap(java.util.HashMap) LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer) D2BaseTest(com.linkedin.d2.D2BaseTest) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 14 with LoadBalancerEchoServer

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

the class TestD2Config method startEchoServer.

private static LoadBalancerEchoServer startEchoServer(int echoServerPort, String cluster, String... services) throws Exception {
    LoadBalancerEchoServer echoServer = new LoadBalancerEchoServer(ZK_HOST, ZK_PORT, ECHO_SERVER_HOST, echoServerPort, "http", "/d2", cluster, services);
    echoServer.startServer();
    echoServer.markUp();
    return echoServer;
}
Also used : LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer)

Aggregations

LoadBalancerEchoServer (com.linkedin.d2.balancer.util.LoadBalancerEchoServer)14 HashMap (java.util.HashMap)5 D2BaseTest (com.linkedin.d2.D2BaseTest)3 LoadBalancerClientCli (com.linkedin.d2.balancer.util.LoadBalancerClientCli)3 AfterTest (org.testng.annotations.AfterTest)3 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1 PartitionAccessException (com.linkedin.d2.balancer.util.partitions.PartitionAccessException)1 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 KeeperException (org.apache.zookeeper.KeeperException)1 AfterMethod (org.testng.annotations.AfterMethod)1