use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpDuringSessionExpirationManyCallbacks.
@Test(invocationCount = 10, timeOut = 10000, retryAnalyzer = ThreeRetries.class)
public void testMarkUpDuringSessionExpirationManyCallbacks() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZKPersistentConnection zkPersistentConnection = getZkPersistentConnection();
ZooKeeperConnectionManager manager = createManager(true, zkPersistentConnection, announcer);
// set up many concurrent callbacks
FutureCallback<None> allMarkupsSucceed = new FutureCallback<>();
int count = 1000;
Callback<None> markUpAllServersCallback = new MultiCallback(allMarkupsSucceed, 2 * count);
ExecutorService executorService = Executors.newScheduledThreadPool(100);
for (int i = 0; i < count; i++) {
executorService.execute(() -> {
manager.markDownAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
manager.markUpAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
});
}
// expiring the connection
long oldSessionId = zkPersistentConnection.getZooKeeper().getSessionId();
ZKTestUtil.expireSession("localhost:" + PORT, zkPersistentConnection.getZooKeeper(), 10, TimeUnit.SECONDS);
ZKTestUtil.waitForNewSessionEstablished(oldSessionId, zkPersistentConnection, 10, TimeUnit.SECONDS);
try {
allMarkupsSucceed.get(1, TimeUnit.MILLISECONDS);
Assert.fail("All the callbacks were resolved before expiring the connection, which means it won't test that callbacks are invoked even after session expiration");
} catch (Throwable e) {
// expected
}
allMarkupsSucceed.get();
// making sure that a new connection has been established. There should be no need to wait, because at least one markup should have been run on
// the new connection, which means that by this part of code it should already have been established
ZKTestUtil.waitForNewSessionEstablished(oldSessionId, zkPersistentConnection, 0, TimeUnit.SECONDS);
// data validation
dataValidation(_uri, _cluster, WEIGHT);
shutdownManager(manager);
executorService.shutdown();
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkDownDuringDisconnection.
@Test
public void testMarkDownDuringDisconnection() 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);
// 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);
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpAndMarkDown.
@Test
public void testMarkUpAndMarkDown() 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);
FutureCallback<None> markDownCallback = new FutureCallback<>();
announcer.markDown(markDownCallback);
markDownCallback.get();
properties = store.get(_cluster);
assertNotNull(properties);
assertEquals(properties.Uris().size(), 0);
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpDuringDisconnection.
@Test
public void testMarkUpDuringDisconnection() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZooKeeperConnectionManager manager = createManager(false, announcer);
_zkServer.shutdown(false);
FutureCallback<None> managerStartCallback = new FutureCallback<>();
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);
shutdownManager(manager);
}
use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.
the class SharedZkConnectionProviderTest method testManyHostsAnnouncementSharingConnections.
/**
* Test announcing many hosts using one connection concurrently
*/
@Test(groups = "needZk")
public void testManyHostsAnnouncementSharingConnections() throws Exception {
List<URI> hostNames = prepareHostNames(100, "testManyHostsAnnouncementSharingConnections");
List<ZooKeeperConnectionManager> connectionManagers = prepareConnectionManagers(hostNames);
startConnectionManagers(connectionManagers);
UriProperties newProperties = _verificationStore.get(CLUSTER_NAME);
assertNotNull(newProperties);
assertEquals(newProperties.Uris().size(), 100);
shutdownConnectionManagers(connectionManagers);
}
Aggregations