use of com.linkedin.d2.balancer.servers.ZooKeeperAnnouncer in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpDuringDisconnection.
@Test
public void testMarkUpDuringDisconnection() throws ExecutionException, InterruptedException, IOException, PropertyStoreException {
final String uri = "http://cluster-3/test";
final String cluster = "cluster-3";
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);
_zkServer.shutdown(false);
FutureCallback<None> managerStartCallback = new FutureCallback<None>();
manager.start(managerStartCallback);
_zkServer.restart();
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.balancer.servers.ZooKeeperAnnouncer in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkDownDuringDisconnection.
@Test
public void testMarkDownDuringDisconnection() throws IOException, ExecutionException, InterruptedException, PropertyStoreException {
final String uri = "http://cluster-4/test";
final String cluster = "cluster-4";
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);
// 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();
markDownCallback.get();
properties = store.get(cluster);
assertNotNull(properties);
assertEquals(properties.Uris().size(), 0);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperAnnouncer in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpAndMarkDown.
@Test
public void testMarkUpAndMarkDown() throws IOException, ExecutionException, InterruptedException, PropertyStoreException {
final String uri = "http://cluster-2/test";
final String cluster = "cluster-2";
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);
FutureCallback<None> markDownCallback = new FutureCallback<None>();
announcer.markDown(markDownCallback);
markDownCallback.get();
properties = store.get(cluster);
assertNotNull(properties);
assertEquals(properties.Uris().size(), 0);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperAnnouncer 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.balancer.servers.ZooKeeperAnnouncer 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);
}
Aggregations