Search in sources :

Example 6 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.

the class TestManagedSchemaThreadSafety method createZkController.

private ZkController createZkController(SolrZkClient client) throws KeeperException, InterruptedException {
    CoreContainer mockAlwaysUpCoreContainer = mock(CoreContainer.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
    // Allow retry on session expiry
    when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(Boolean.FALSE);
    MockZkController zkController = mock(MockZkController.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
    when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);
    when(zkController.getZkClient()).thenReturn(client);
    Mockito.doAnswer(new Answer<Boolean>() {

        volatile boolean sessionExpired = false;

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            String path = (String) invocation.getArguments()[0];
            perhapsExpired();
            Boolean exists = client.exists(path, true);
            perhapsExpired();
            return exists;
        }

        private void perhapsExpired() throws SessionExpiredException {
            if (!sessionExpired && rarely()) {
                sessionExpired = true;
                throw new KeeperException.SessionExpiredException();
            }
        }
    }).when(zkController).pathExists(Mockito.anyString());
    return zkController;
}
Also used : MockZkController(org.apache.solr.cloud.MockZkController) CoreContainer(org.apache.solr.core.CoreContainer) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) KeeperException(org.apache.zookeeper.KeeperException)

Example 7 with SessionExpiredException

use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.

the class LeaderElectionTest method getLeaderUrl.

private String getLeaderUrl(final String collection, final String slice) throws KeeperException, InterruptedException {
    int iterCount = 60;
    while (iterCount-- > 0) {
        try {
            byte[] data = zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null, true);
            ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data));
            return leaderProps.getCoreUrl();
        } catch (NoNodeException | SessionExpiredException e) {
            Thread.sleep(500);
        }
    }
    zkClient.printLayoutToStdOut();
    throw new RuntimeException("Could not get leader props");
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException)

Aggregations

SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)7 IOException (java.io.IOException)3 KeeperException (org.apache.zookeeper.KeeperException)3 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 UnknownHostException (java.net.UnknownHostException)2 TimeoutException (java.util.concurrent.TimeoutException)2 SolrException (org.apache.solr.common.SolrException)2 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)2 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)2 SolrCoreInitializationException (org.apache.solr.core.SolrCoreInitializationException)2 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)2 SessionExpirer (org.apache.zookeeper.server.SessionTracker.SessionExpirer)2 Test (org.junit.Test)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1