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);
}
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);
}
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);
}
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);
}
}
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);
}
}
}
}
Aggregations