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