use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpWithSinglePartition.
@Test
public void testMarkUpWithSinglePartition() throws Exception {
double newWeight = 10d;
ZooKeeperAnnouncer announcer = getZooKeeperSinglePartitionAnnouncer(_cluster, _uri, PARTITION1_ID, PARTITION1_WEIGHT);
announcer.setWeight(newWeight);
ZooKeeperConnectionManager manager = createManager(true, announcer);
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
UriProperties properties = store.get(_cluster);
assertNotNull(properties);
assertNull(properties.getPartitionDataMap(URI.create(_uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID));
assertNotEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION1_ID).getWeight(), PARTITION1_WEIGHT);
assertEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION1_ID).getWeight(), newWeight);
assertEquals(properties.Uris().size(), 1);
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUp.
@Test
public void testMarkUp() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZooKeeperConnectionManager manager = createManager(true, announcer);
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);
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpDuringSessionExpiration.
@Test(invocationCount = 10, timeOut = 10000)
public void testMarkUpDuringSessionExpiration() throws Exception {
// set up
final double newWeight = 1.5d;
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZKPersistentConnection zkPersistentConnection = getZkPersistentConnection();
ZooKeeperConnectionManager manager = createManager(true, zkPersistentConnection, announcer);
// the new WEIGHT will be picked up only if the connection is re-established
announcer.setWeight(newWeight);
// expiring the connection
long oldSessionId = zkPersistentConnection.getZooKeeper().getSessionId();
ZKTestUtil.expireSession("localhost:" + PORT, zkPersistentConnection.getZooKeeper(), 10, TimeUnit.SECONDS);
// making sure that a new connection has been established.
ZKTestUtil.waitForNewSessionEstablished(oldSessionId, zkPersistentConnection, 10, TimeUnit.SECONDS);
// validation
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
AssertionMethods.assertWithTimeout(1000, () -> {
UriProperties properties = store.get(_cluster);
assertNotNull(properties);
if (properties.getPartitionDataMap(URI.create(_uri)) == null) {
Assert.fail("Supposed to have the uri present in ZK");
}
assertEquals(properties.getPartitionDataMap(URI.create(_uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), newWeight);
assertEquals(properties.Uris().size(), 1);
});
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkDownAndUpDuringDisconnection.
@Test
public void testMarkDownAndUpDuringDisconnection() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZooKeeperConnectionManager manager = createManager(true, announcer);
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<>();
announcer.markDown(markDownCallback);
FutureCallback<None> markUpCallback = new FutureCallback<>();
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);
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testDelayMarkUp.
@Test
public void testDelayMarkUp() throws Exception {
ZooKeeperAnnouncer announcer = new ZooKeeperAnnouncer(new ZooKeeperServer(), false);
announcer.setCluster(_cluster);
announcer.setUri(_uri);
Map<Integer, PartitionData> partitionWeight = new HashMap<>();
partitionWeight.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(ZookeeperConnectionManagerTest.WEIGHT));
announcer.setPartitionData(partitionWeight);
ZooKeeperConnectionManager manager = createManager(true, announcer);
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
UriProperties properties = store.get(_cluster);
assertNull(properties);
FutureCallback<None> markUpCallback = new FutureCallback<>();
announcer.markUp(markUpCallback);
markUpCallback.get();
UriProperties propertiesAfterMarkUp = store.get(_cluster);
assertNotNull(propertiesAfterMarkUp);
assertEquals(propertiesAfterMarkUp.getPartitionDataMap(URI.create(_uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), ZookeeperConnectionManagerTest.WEIGHT);
assertEquals(propertiesAfterMarkUp.Uris().size(), 1);
shutdownManager(manager);
}
Aggregations