use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class TestD2Config method verifyPartitionProperties.
public static void verifyPartitionProperties(String cluster, Map<String, Object> propertiesMap) throws IOException, URISyntaxException, PropertyStoreException {
final ClusterProperties clusterprops = getClusterProperties(_zkclient, cluster);
if (propertiesMap.get("partitionProperties") != null) {
@SuppressWarnings("unchecked") Map<String, Object> properties = (Map<String, Object>) propertiesMap.get("partitionProperties");
PartitionProperties.PartitionType partitionType = PartitionProperties.PartitionType.valueOf((String) properties.get("partitionType"));
switch(partitionType) {
case RANGE:
{
long keyRangeStart = ((Number) properties.get("keyRangeStart")).longValue();
long partitionSize = ((Number) properties.get("partitionSize")).longValue();
int partitionCount = ((Number) properties.get("partitionCount")).intValue();
String regex = (String) properties.get("partitionKeyRegex");
RangeBasedPartitionProperties rbp = (RangeBasedPartitionProperties) clusterprops.getPartitionProperties();
assertEquals(keyRangeStart, rbp.getKeyRangeStart());
assertEquals(partitionSize, rbp.getPartitionSize());
assertEquals(partitionCount, rbp.getPartitionCount());
assertEquals(regex, rbp.getPartitionKeyRegex());
}
break;
case HASH:
{
int partitionCount = ((Number) properties.get("partitionCount")).intValue();
String regex = (String) properties.get("partitionKeyRegex");
String algorithm = (String) properties.get("hashAlgorithm");
HashBasedPartitionProperties.HashAlgorithm hashAlgorithm = HashBasedPartitionProperties.HashAlgorithm.valueOf(algorithm.toUpperCase());
HashBasedPartitionProperties hbp = (HashBasedPartitionProperties) clusterprops.getPartitionProperties();
assertEquals(partitionCount, hbp.getPartitionCount());
assertEquals(regex, hbp.getPartitionKeyRegex());
assertEquals(hashAlgorithm, hbp.getHashAlgorithm());
}
break;
default:
break;
}
}
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class TestD2Config method verifyClusterProperties.
@SuppressWarnings("unchecked")
public static void verifyClusterProperties(String cluster, Map<String, Object> propertiesMap) throws PropertyStoreException, IOException, URISyntaxException {
ClusterProperties clusterProperties = getClusterProperties(_zkclient, cluster);
if (propertiesMap.get(PropertyKeys.COLO_VARIANTS) != null) {
String coloVariantsString = clusterProperties.getProperties().get(PropertyKeys.COLO_VARIANTS);
List<String> coloVariants = Arrays.asList(coloVariantsString.split(D2Config.LIST_SEPARATOR));
List<String> expectedColoVariants = (List<String>) propertiesMap.get(PropertyKeys.COLO_VARIANTS);
Assert.assertTrue(coloVariants.containsAll(expectedColoVariants));
Assert.assertTrue(expectedColoVariants.containsAll(coloVariants));
}
if (propertiesMap.get(PropertyKeys.MASTER_COLO) != null) {
String masterColo = clusterProperties.getProperties().get(PropertyKeys.MASTER_COLO);
String expectedMasterColo = (String) propertiesMap.get(PropertyKeys.MASTER_COLO);
Assert.assertEquals(masterColo, expectedMasterColo);
}
if (propertiesMap.get(PropertyKeys.CLUSTER_VARIANTS) != null) {
String clusterVariantsString = clusterProperties.getProperties().get(PropertyKeys.CLUSTER_VARIANTS);
List<String> clusterVariants = Arrays.asList(clusterVariantsString.split(D2Config.LIST_SEPARATOR));
List<String> expectedClusterVariants = (List<String>) propertiesMap.get(PropertyKeys.CLUSTER_VARIANTS);
Assert.assertTrue(clusterVariants.containsAll(expectedClusterVariants));
Assert.assertTrue(expectedClusterVariants.containsAll(clusterVariants));
}
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class TestD2Config method verifyUriProperties.
public static void verifyUriProperties(String cluster, Map<URI, Double> urisWeights) throws IOException, URISyntaxException, PropertyStoreException {
UriProperties uriprops = getUriProperties(_zkclient, cluster);
assertEquals(uriprops.getClusterName(), cluster);
for (URI uri : urisWeights.keySet()) {
assertEquals(uriprops.getPartitionDataMap(uri).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), urisWeights.get(uri));
}
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class TestD2Config method verifyPartitionedUriProperties.
public static void verifyPartitionedUriProperties(String cluster, Map<URI, Map<Integer, Double>> partitionWeights) throws IOException, URISyntaxException, PropertyStoreException {
UriProperties uriprops = getUriProperties(_zkclient, cluster);
assertEquals(uriprops.getClusterName(), cluster);
if (partitionWeights != null) {
Map<Integer, Set<URI>> partitionUris = new HashMap<Integer, Set<URI>>();
for (final URI uri : partitionWeights.keySet()) {
for (final int partitionId : partitionWeights.get(uri).keySet()) {
Set<URI> uriSet = partitionUris.get(partitionId);
if (uriSet == null) {
uriSet = new HashSet<URI>();
partitionUris.put(partitionId, uriSet);
}
uriSet.add(uri);
}
}
for (final int partitionId : partitionUris.keySet()) {
assertEquals(uriprops.getUriBySchemeAndPartition("http", partitionId), partitionUris.get(partitionId));
}
for (URI uri : partitionWeights.keySet()) {
Map<Integer, Double> weights = partitionWeights.get(uri);
for (int partitionId : weights.keySet()) {
assertEquals(weights.get(partitionId), uriprops.getPartitionDataMap(uri).get(partitionId).getWeight());
}
}
}
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class LoadBalancerEchoClient method startClient.
public void startClient() throws URISyntaxException, InterruptedException, ExecutionException, IOException, PropertyStoreException {
DynamicClient client = new DynamicClient(getLoadBalancer(_hostPort), null);
for (; ; ) {
int index = 0;
if (_services.length > 1) {
index = _random.nextInt(_services.length);
}
String service = _services[index];
URI uri = URI.create("d2://" + service);
RestRequest req = new RestRequestBuilder(uri).setEntity("hi there".getBytes("UTF-8")).build();
try {
Future<RestResponse> response = client.restRequest(req);
String responseString = response.get().getEntity().asString("UTF-8");
System.err.println(uri + " response: " + responseString);
} catch (ExecutionException e) {
System.err.println("future.get() failed for " + uri + ": " + e);
}
Thread.sleep(_random.nextInt(1000));
}
}
Aggregations