Search in sources :

Example 1 with MockZkController

use of org.apache.solr.cloud.MockZkController 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)

Aggregations

MockZkController (org.apache.solr.cloud.MockZkController)1 CoreContainer (org.apache.solr.core.CoreContainer)1 KeeperException (org.apache.zookeeper.KeeperException)1 SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1