use of org.apache.solr.common.cloud.ConnectionManager in project lucene-solr by apache.
the class ConnectionManagerTest method testConnectionManager.
@Ignore
public void testConnectionManager() throws Exception {
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
ConnectionManager cm = zkClient.getConnectionManager();
try {
assertFalse(cm.isLikelyExpired());
zkClient.getSolrZooKeeper().closeCnxn();
long sessionId = zkClient.getSolrZooKeeper().getSessionId();
server.expire(sessionId);
Thread.sleep(TIMEOUT);
assertTrue(cm.isLikelyExpired());
} finally {
cm.close();
zkClient.close();
}
} finally {
server.shutdown();
}
}
use of org.apache.solr.common.cloud.ConnectionManager in project lucene-solr by apache.
the class ConnectionManagerTest method testReconnectWhenZkDisappeared.
@Test
public void testReconnectWhenZkDisappeared() throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new DefaultSolrThreadFactory("connectionManagerTest"));
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
MockZkClientConnectionStrategy strat = new MockZkClientConnectionStrategy();
SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT, strat, null);
ConnectionManager cm = zkClient.getConnectionManager();
try {
assertFalse(cm.isLikelyExpired());
assertTrue(cm.isConnected());
// reconnect -- should no longer be likely expired
cm.process(new WatchedEvent(EventType.None, KeeperState.Expired, ""));
assertFalse(cm.isLikelyExpired());
assertTrue(cm.isConnected());
assertTrue(strat.isExceptionThrow());
} finally {
cm.close();
zkClient.close();
executor.shutdown();
}
} finally {
server.shutdown();
}
}
use of org.apache.solr.common.cloud.ConnectionManager in project lucene-solr by apache.
the class ConnectionManagerTest method testLikelyExpired.
public void testLikelyExpired() throws Exception {
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
ConnectionManager cm = zkClient.getConnectionManager();
try {
assertFalse(cm.isLikelyExpired());
assertTrue(cm.isConnected());
cm.process(new WatchedEvent(EventType.None, KeeperState.Disconnected, ""));
// disconnect shouldn't immediately set likelyExpired
assertFalse(cm.isConnected());
assertFalse(cm.isLikelyExpired());
// but it should after the timeout
Thread.sleep((long) (zkClient.getZkClientTimeout() * 1.5));
assertFalse(cm.isConnected());
assertTrue(cm.isLikelyExpired());
// even if we disconnect immediately again
cm.process(new WatchedEvent(EventType.None, KeeperState.Disconnected, ""));
assertFalse(cm.isConnected());
assertTrue(cm.isLikelyExpired());
// reconnect -- should no longer be likely expired
cm.process(new WatchedEvent(EventType.None, KeeperState.SyncConnected, ""));
assertFalse(cm.isLikelyExpired());
assertTrue(cm.isConnected());
} finally {
cm.close();
zkClient.close();
}
} finally {
server.shutdown();
}
}
Aggregations