Search in sources :

Example 1 with LoadBalancerClientCli

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

the class TestPartitionsWithZKQuorum method testRegisterUnregisterDefaultPartitionEchoServers.

@Test
public void testRegisterUnregisterDefaultPartitionEchoServers() throws IOException, URISyntaxException, PropertyStoreException, ExecutionException, TimeoutException, InterruptedException, Exception {
    _echoServers = new ArrayList<LoadBalancerEchoServer>();
    setup();
    assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_DEFAULT_PARTITION_DATA), 0);
    _cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
    _client = _cli.createZKFSTogglingLBClient(_quorum.getHosts(), "/d2", null);
    // Echo servers startup
    startDefaultPartitionEchoServers();
    assertAllEchoServersRunning(_echoServers);
    assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
    assertQuorumProcessAllRequests(D2_CONFIG_DEFAULT_PARTITION_DATA);
    // Markdown echo servers
    stopAllEchoServers(_echoServers);
    assertAllEchoServersUnregistered(_cli.getZKClient(), _zkUriString, _echoServers);
}
Also used : LoadBalancerClientCli(com.linkedin.d2.balancer.util.LoadBalancerClientCli) LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer) D2BaseTest(com.linkedin.d2.D2BaseTest) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 2 with LoadBalancerClientCli

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

the class TestPartitionsWithZKQuorum method testRegisterUnregisterCustomPartitionEchoServers.

@Test
public void testRegisterUnregisterCustomPartitionEchoServers() throws IOException, URISyntaxException, PropertyStoreException, ExecutionException, TimeoutException, InterruptedException, Exception {
    _echoServers = new ArrayList<LoadBalancerEchoServer>();
    setup();
    assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_CUSTOM_PARTITION_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));
    startCustomPartitionEchoServers(partitionWeight);
    assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
    assertQuorumProcessAllRequests(D2_CONFIG_CUSTOM_PARTITION_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 3 with LoadBalancerClientCli

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

the class TestD2ZKQuorumFailover method setup.

private void setup() throws IOException, Exception {
    // Start _quorum
    _quorum = new ZKQuorum(QUORUM_SIZE);
    _quorum.startAll();
    _quorum.assertAllPeersUp();
    _zkUriString = "zk://" + _quorum.getHosts();
    _zkHosts = _quorum.getHosts().split(",");
    // Register clusters/services with zookeeper _quorum
    LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_DATA);
    // Echo servers startup
    startAllEchoServers();
    assertAllEchoServersRunning(_echoServers);
    // Get LoadBalancer Client
    _cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
    _client = _cli.createZKFSTogglingLBClient(_quorum.getHosts(), "/d2", null);
    assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
    assertQuorumProcessAllRequests(D2_CONFIG_DATA);
}
Also used : LoadBalancerClientCli(com.linkedin.d2.balancer.util.LoadBalancerClientCli) ZKQuorum(com.linkedin.d2.quorum.ZKQuorum)

Example 4 with LoadBalancerClientCli

use of com.linkedin.d2.balancer.util.LoadBalancerClientCli 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 5 with LoadBalancerClientCli

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

the class D2BaseTest method assertQuorumProcessAllRequests.

public void assertQuorumProcessAllRequests(int num, String jsonConfigData, String zkUriString, LoadBalancerClientCli cli, DynamicClient client, String miscmsg) throws Exception {
    Map<String, Object> clustersData = D2ConfigTestUtil.getClusterServiceConfiguration(jsonConfigData);
    for (int j = 0; j < num; j++) {
        for (String clusterName : clustersData.keySet()) {
            String msg = generateMessage(zkUriString);
            String response = null;
            @SuppressWarnings("unchecked") Map<String, Object> servicesData = (Map<String, Object>) clustersData.get(clusterName);
            @SuppressWarnings("unchecked") Map<String, Object> services = (Map<String, Object>) servicesData.get("services");
            for (String service : services.keySet()) {
                try {
                    response = cli.sendRequest(client, clusterName, service, msg);
                    assertTrue(response.contains(LoadBalancerEchoServer.getResponsePostfixString()), "No '" + LoadBalancerEchoServer.getResponsePostfixString() + "' found in response from " + clusterName + "/" + service + ". Response:" + response);
                    _log.error("Assert pass. Response contains " + LoadBalancerEchoServer.getResponsePostfixString());
                } catch (Exception e) {
                    _log.error("Response for " + clusterName + "/" + service + " failed." + miscmsg + " Error:" + e + "\n", e);
                    e.printStackTrace();
                    throw new Exception(e);
                }
                _log.debug("Response for " + clusterName + "/" + service + ":" + response);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Aggregations

LoadBalancerClientCli (com.linkedin.d2.balancer.util.LoadBalancerClientCli)5 LoadBalancerEchoServer (com.linkedin.d2.balancer.util.LoadBalancerEchoServer)4 D2BaseTest (com.linkedin.d2.D2BaseTest)3 HashMap (java.util.HashMap)3 AfterTest (org.testng.annotations.AfterTest)3 Test (org.testng.annotations.Test)3 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)1 ZKQuorum (com.linkedin.d2.quorum.ZKQuorum)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 BeforeTest (org.testng.annotations.BeforeTest)1