use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testDelayMarkUp.
@Test
public void testDelayMarkUp() throws IOException, ExecutionException, InterruptedException, PropertyStoreException {
final String uri = "http://cluster-1/test";
final String cluster = "cluster-1";
final double weight = 0.5d;
ZooKeeperAnnouncer announcer = new ZooKeeperAnnouncer(new ZooKeeperServer(), false);
announcer.setCluster(cluster);
announcer.setUri(uri);
Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
partitionWeight.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(weight));
announcer.setPartitionData(partitionWeight);
ZooKeeperConnectionManager manager = createManager(announcer);
FutureCallback<None> managerStartCallback = new FutureCallback<None>();
manager.start(managerStartCallback);
managerStartCallback.get();
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
UriProperties properties = store.get(cluster);
assertNull(properties);
FutureCallback<None> markUpCallback = new FutureCallback<None>();
announcer.markUp(markUpCallback);
markUpCallback.get();
UriProperties propertiesAfterMarkUp = store.get(cluster);
assertNotNull(propertiesAfterMarkUp);
assertEquals(propertiesAfterMarkUp.getPartitionDataMap(URI.create(uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), weight);
assertEquals(propertiesAfterMarkUp.Uris().size(), 1);
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUp.
@Test
public void testMarkUp() throws IOException, ExecutionException, InterruptedException, PropertyStoreException {
final String uri = "http://cluster-1/test";
final String cluster = "cluster-1";
final double weight = 0.5d;
ZooKeeperAnnouncer announcer = new ZooKeeperAnnouncer(new ZooKeeperServer());
announcer.setCluster(cluster);
announcer.setUri(uri);
Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
partitionWeight.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(weight));
announcer.setPartitionData(partitionWeight);
ZooKeeperConnectionManager manager = createManager(announcer);
FutureCallback<None> managerStartCallback = new FutureCallback<None>();
manager.start(managerStartCallback);
managerStartCallback.get();
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
UriProperties properties = store.get(cluster);
assertNotNull(properties);
assertEquals(properties.getPartitionDataMap(URI.create(uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), weight);
assertEquals(properties.Uris().size(), 1);
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkDownAndUpDuringDisconnection.
@Test
public void testMarkDownAndUpDuringDisconnection() throws IOException, ExecutionException, InterruptedException, PropertyStoreException, TimeoutException {
final String uri = "http://cluster-5/test";
final String cluster = "cluster-5";
final double weight = 0.5d;
ZooKeeperAnnouncer announcer = new ZooKeeperAnnouncer(new ZooKeeperServer());
announcer.setCluster(cluster);
announcer.setUri(uri);
Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
partitionWeight.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(weight));
announcer.setPartitionData(partitionWeight);
ZooKeeperConnectionManager manager = createManager(announcer);
FutureCallback<None> managerStartCallback = new FutureCallback<None>();
manager.start(managerStartCallback);
managerStartCallback.get();
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
UriProperties properties = store.get(cluster);
assertNotNull(properties);
assertEquals(properties.getPartitionDataMap(URI.create(uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), weight);
assertEquals(properties.Uris().size(), 1);
_zkServer.shutdown(false);
FutureCallback<None> markDownCallback = new FutureCallback<None>();
announcer.markDown(markDownCallback);
FutureCallback<None> markUpCallback = new FutureCallback<None>();
announcer.markUp(markUpCallback);
// ugly, but we need to wait for a while just so that Disconnect event is propagated
// to the caller before we restart zk sever.
Thread.sleep(1000);
_zkServer.restart();
markUpCallback.get(10, TimeUnit.SECONDS);
try {
markDownCallback.get();
Assert.fail("mark down should have thrown CancellationException.");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof CancellationException);
}
properties = store.get(cluster);
assertNotNull(properties);
assertEquals(properties.getPartitionDataMap(URI.create(uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), weight);
assertEquals(properties.Uris().size(), 1);
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class LoadBalancerClientCli method hasService.
public static boolean hasService(ZKConnection zkclient, String zkserver, String d2path, String cluster, String service) throws URISyntaxException, IOException, PropertyStoreException {
ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = null;
String scstoreString = zkserver + ZKFSUtil.servicePath(d2path);
zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(zkclient, scstoreString, new ServicePropertiesJsonSerializer());
return zkServiceRegistry.get(service).getClusterName().equals(cluster);
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class LoadBalancerClientCli method getSchema.
public String getSchema(ZKConnection zkclient, String zkserver, String d2path, String cluster, String service, String requestType) throws URISyntaxException, InterruptedException, ExecutionException, IOException, PropertyStoreException, TimeoutException {
String responseString = null;
if (hasService(zkclient, zkserver, d2path, cluster, service)) {
DynamicClient client = new DynamicClient(getLoadBalancer(zkclient, zkserver, d2path, service), null);
URI uri = URI.create("d2://" + service + "/");
try {
RestRequest restRequest = new RestRequestBuilder(uri).setEntity("".getBytes("UTF-8")).build();
Future<RestResponse> response = client.restRequest(restRequest, new RequestContext());
responseString = response.get().getEntity().asString("UTF-8");
} finally {
LoadBalancerUtil.syncShutdownClient(_client, _log);
zkclient.shutdown();
}
} else {
System.out.println("Service '" + service + "' is not defined for cluster '" + cluster + "'.");
}
return responseString;
}
Aggregations