Search in sources :

Example 1 with ConnectionManager

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();
    }
}
Also used : ConnectionManager(org.apache.solr.common.cloud.ConnectionManager) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Ignore(org.junit.Ignore)

Example 2 with ConnectionManager

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();
    }
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConnectionManager(org.apache.solr.common.cloud.ConnectionManager) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Example 3 with ConnectionManager

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();
    }
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) ConnectionManager(org.apache.solr.common.cloud.ConnectionManager) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Aggregations

ConnectionManager (org.apache.solr.common.cloud.ConnectionManager)3 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)3 WatchedEvent (org.apache.zookeeper.WatchedEvent)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 DefaultSolrThreadFactory (org.apache.solr.util.DefaultSolrThreadFactory)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1