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;
}
Aggregations