use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpAndDownMultipleTimesFinalDown.
@Test(invocationCount = 10, timeOut = 10000)
public void testMarkUpAndDownMultipleTimesFinalDown() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZooKeeperConnectionManager manager = createManager(true, announcer);
// set up many concurrent callbacks
FutureCallback<None> allMarkupsDownsSucceed = new FutureCallback<>();
int count = 1;
Callback<None> markUpAllServersCallback = new MultiCallback(allMarkupsDownsSucceed, count * 2);
ExecutorService executorService = Executors.newScheduledThreadPool(100);
for (int i = 0; i < count; i++) {
executorService.execute(() -> {
manager.markUpAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
manager.markDownAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
});
}
allMarkupsDownsSucceed.get();
// data validation
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
AssertionMethods.assertWithTimeout(1000, () -> {
UriProperties properties = store.get(_cluster);
assertNotNull(properties);
assertNull(properties.getPartitionDataMap(URI.create(_uri)), _uri);
});
shutdownManager(manager);
executorService.shutdown();
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpWithMultiPartition.
@Test
public void testMarkUpWithMultiPartition() throws Exception {
double newWeight = 10d;
ZooKeeperAnnouncer announcer = getZooKeeperMultiPartitionAnnouncer(_cluster, _uri, PARTITION1_ID, PARTITION2_ID, PARTITION1_WEIGHT, PARTITION2_WEIGHT);
try {
announcer.setWeight(newWeight);
Assert.fail("The operation should not be supported since we don't know for which partition we should change weight for.");
} catch (IllegalArgumentException ex) {
// Success
}
ZooKeeperConnectionManager manager = createManager(true, announcer);
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
UriProperties properties = store.get(_cluster);
assertNotNull(properties);
assertNotEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION1_ID).getWeight(), newWeight);
assertNotEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION2_ID).getWeight(), newWeight);
assertNull(properties.getPartitionDataMap(URI.create(_uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID));
assertEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION1_ID).getWeight(), PARTITION1_WEIGHT);
assertEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION2_ID).getWeight(), PARTITION2_WEIGHT);
assertEquals(properties.Uris().size(), 1);
shutdownManager(manager);
}
Aggregations