use of org.apache.solr.util.TimeOut in project lucene-solr by apache.
the class TestPullReplicaErrorHandling method assertNumDocs.
private void assertNumDocs(int numDocs, SolrClient client, int timeoutSecs) throws InterruptedException, SolrServerException, IOException {
TimeOut t = new TimeOut(timeoutSecs, TimeUnit.SECONDS);
long numFound = -1;
while (!t.hasTimedOut()) {
Thread.sleep(200);
numFound = client.query(new SolrQuery("*:*")).getResults().getNumFound();
if (numFound == numDocs) {
return;
}
}
fail("Didn't get expected doc count. Expected: " + numDocs + ", Found: " + numFound);
}
use of org.apache.solr.util.TimeOut in project lucene-solr by apache.
the class TestTlogReplica method testAddDocs.
@SuppressWarnings("unchecked")
public void testAddDocs() throws Exception {
int numTlogReplicas = 1 + random().nextInt(3);
DocCollection docCollection = createAndWaitForCollection(1, 0, numTlogReplicas, 0);
assertEquals(1, docCollection.getSlices().size());
cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar"));
cluster.getSolrClient().commit(collectionName);
Slice s = docCollection.getSlices().iterator().next();
try (HttpSolrClient leaderClient = getHttpSolrClient(s.getLeader().getCoreUrl())) {
assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound());
}
TimeOut t = new TimeOut(REPLICATION_TIMEOUT_SECS, TimeUnit.SECONDS);
for (Replica r : s.getReplicas(EnumSet.of(Replica.Type.TLOG))) {
//TODO: assert replication < REPLICATION_TIMEOUT_SECS
try (HttpSolrClient tlogReplicaClient = getHttpSolrClient(r.getCoreUrl())) {
while (true) {
try {
assertEquals("Replica " + r.getName() + " not up to date after 10 seconds", 1, tlogReplicaClient.query(new SolrQuery("*:*")).getResults().getNumFound());
// Append replicas process all updates
SolrQuery req = new SolrQuery("qt", "/admin/plugins", "stats", "true");
QueryResponse statsResponse = tlogReplicaClient.query(req);
assertEquals("Append replicas should recive all updates. Replica: " + r + ", response: " + statsResponse, 1L, ((Map<String, Object>) ((NamedList<Object>) statsResponse.getResponse()).findRecursive("plugins", "UPDATE", "updateHandler", "stats")).get("UPDATE.updateHandler.cumulativeAdds.count"));
break;
} catch (AssertionError e) {
if (t.hasTimedOut()) {
throw e;
} else {
Thread.sleep(100);
}
}
}
}
}
assertUlogPresence(docCollection);
}
use of org.apache.solr.util.TimeOut in project lucene-solr by apache.
the class TestRebalanceLeaders method waitForAllPreferreds.
boolean waitForAllPreferreds() throws KeeperException, InterruptedException {
boolean goAgain = true;
TimeOut timeout = new TimeOut(timeoutMs, TimeUnit.MILLISECONDS);
while (!timeout.hasTimedOut()) {
goAgain = false;
Map<String, Slice> slices = cloudClient.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME).getSlicesMap();
for (Map.Entry<String, Replica> ent : expected.entrySet()) {
Replica me = slices.get(ent.getKey()).getReplica(ent.getValue().getName());
if (me.getBool("property.preferredleader", false) == false) {
goAgain = true;
break;
}
}
if (goAgain) {
Thread.sleep(250);
} else {
return true;
}
}
return false;
}
use of org.apache.solr.util.TimeOut in project lucene-solr by apache.
the class TestRebalanceLeaders method checkConsistency.
// After we've called the rebalance command, we want to insure that:
// 1> all replicas appear once and only once in the respective leader election queue
// 2> All the replicas we _think_ are leaders are in the 0th position in the leader election queue.
// 3> The node that ZooKeeper thinks is the leader is the one we think should be the leader.
void checkConsistency() throws InterruptedException, KeeperException {
TimeOut timeout = new TimeOut(timeoutMs, TimeUnit.MILLISECONDS);
boolean checkAppearOnce = false;
boolean checkElectionZero = false;
boolean checkZkLeadersAgree = false;
while (!timeout.hasTimedOut()) {
checkAppearOnce = checkAppearOnce();
checkElectionZero = checkElectionZero();
checkZkLeadersAgree = checkZkLeadersAgree();
if (checkAppearOnce && checkElectionZero && checkZkLeadersAgree) {
return;
}
Thread.sleep(1000);
}
fail("Checking the rebalance leader command failed, checkAppearOnce=" + checkAppearOnce + " checkElectionZero=" + checkElectionZero + " checkZkLeadersAgree=" + checkZkLeadersAgree);
}
use of org.apache.solr.util.TimeOut in project lucene-solr by apache.
the class TestPullReplica method waitForDeletion.
private void waitForDeletion(String collection) throws InterruptedException, KeeperException {
TimeOut t = new TimeOut(10, TimeUnit.SECONDS);
while (cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection(collection)) {
LOG.info("Collection not yet deleted");
try {
Thread.sleep(100);
if (t.hasTimedOut()) {
fail("Timed out waiting for collection " + collection + " to be deleted.");
}
cluster.getSolrClient().getZkStateReader().forceUpdateCollection(collection);
} catch (SolrException e) {
return;
}
}
}
Aggregations