Search in sources :

Example 46 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class DistribDocExpirationUpdateProcessorTest method waitForNoResults.

/**
   * Executes a query over and over against the cloudClient every 5 seconds 
   * until the numFound is 0 or the maxTimeLimitSeconds is exceeded. 
   * Query is guaranteed to be executed at least once.
   */
private void waitForNoResults(int maxTimeLimitSeconds, SolrParams params) throws SolrServerException, InterruptedException, IOException {
    final TimeOut timeout = new TimeOut(maxTimeLimitSeconds, TimeUnit.SECONDS);
    long numFound = cluster.getSolrClient().query(COLLECTION, params).getResults().getNumFound();
    while (0L < numFound && !timeout.hasTimedOut()) {
        Thread.sleep(Math.max(1, Math.min(5000, timeout.timeLeft(TimeUnit.MILLISECONDS))));
        numFound = cluster.getSolrClient().query(COLLECTION, params).getResults().getNumFound();
    }
    assertEquals("Give up waiting for no results: " + params, 0L, numFound);
}
Also used : TimeOut(org.apache.solr.util.TimeOut)

Example 47 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class CollectionsAPIDistributedZkTest method waitForReloads.

private boolean waitForReloads(String collectionName, Map<String, Long> urlToTimeBefore) throws SolrServerException, IOException {
    TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS);
    boolean allTimesAreCorrect = false;
    while (!timeout.hasTimedOut()) {
        Map<String, Long> urlToTimeAfter = new HashMap<>();
        collectStartTimes(collectionName, urlToTimeAfter);
        boolean retry = false;
        Set<Entry<String, Long>> entries = urlToTimeBefore.entrySet();
        for (Entry<String, Long> entry : entries) {
            Long beforeTime = entry.getValue();
            Long afterTime = urlToTimeAfter.get(entry.getKey());
            assertNotNull(afterTime);
            if (afterTime <= beforeTime) {
                retry = true;
                break;
            }
        }
        if (!retry) {
            allTimesAreCorrect = true;
            break;
        }
    }
    return allTimesAreCorrect;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) TimeOut(org.apache.solr.util.TimeOut)

Example 48 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class UnloadDistributedZkTest method checkCoreNamePresenceAndSliceCount.

private void checkCoreNamePresenceAndSliceCount(String collectionName, String coreName, boolean shouldBePresent, int expectedSliceCount) throws Exception {
    final TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS);
    // null meaning "don't know"
    Boolean isPresent = null;
    while (null == isPresent || shouldBePresent != isPresent.booleanValue()) {
        final Collection<Slice> slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collectionName);
        if (timeout.hasTimedOut()) {
            printLayout();
            fail("checkCoreNamePresenceAndSliceCount failed:" + " collection=" + collectionName + " CoreName=" + coreName + " shouldBePresent=" + shouldBePresent + " isPresent=" + isPresent + " expectedSliceCount=" + expectedSliceCount + " actualSliceCount=" + slices.size());
        }
        if (expectedSliceCount == (slices == null ? 0 : slices.size())) {
            isPresent = false;
            if (slices != null) {
                for (Slice slice : slices) {
                    for (Replica replica : slice.getReplicas()) {
                        if (coreName.equals(replica.get("core"))) {
                            isPresent = true;
                        }
                    }
                }
            }
        }
        Thread.sleep(1000);
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut) Slice(org.apache.solr.common.cloud.Slice) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

TimeOut (org.apache.solr.util.TimeOut)48 SolrException (org.apache.solr.common.SolrException)15 Slice (org.apache.solr.common.cloud.Slice)15 DocCollection (org.apache.solr.common.cloud.DocCollection)14 Replica (org.apache.solr.common.cloud.Replica)13 SolrQuery (org.apache.solr.client.solrj.SolrQuery)11 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)6 NamedList (org.apache.solr.common.util.NamedList)6 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 Map (java.util.Map)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Collections.singletonList (java.util.Collections.singletonList)3 HashSet (java.util.HashSet)3