mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-09-10 14:11:25 +00:00
[SEARCH-1364] Modified waitForDocCountCore and dependencies.
Cherry picket from 2.0 to master
This commit is contained in:
@@ -259,8 +259,9 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
cores.addAll(getJettyCores(jettyShards));
|
cores.addAll(getJettyCores(jettyShards));
|
||||||
|
|
||||||
long begin = System.currentTimeMillis();
|
long begin = System.currentTimeMillis();
|
||||||
for (SolrCore core : cores) {
|
|
||||||
waitForDocCountCore(core, query, count, waitMillis, begin);
|
for (SolrClient client : getAllClients()) {
|
||||||
|
waitForDocCountCore(client, luceneToSolrQuery(query), count, waitMillis, begin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +269,8 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
{
|
{
|
||||||
List<SolrCore> cores = getJettyCores(jettyShards);
|
List<SolrCore> cores = getJettyCores(jettyShards);
|
||||||
long begin = System.currentTimeMillis();
|
long begin = System.currentTimeMillis();
|
||||||
for (SolrCore core : cores) {
|
for (SolrClient client : getClusterClients()) {
|
||||||
waitForDocCountCore(core, query, count, waitMillis, begin);
|
waitForDocCountCore(client, luceneToSolrQuery(query), count, waitMillis, begin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,6 +301,14 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<SolrClient> getJettyClients()
|
||||||
|
{
|
||||||
|
List<SolrClient> clients = new ArrayList();
|
||||||
|
clients.addAll(jettyClients.values());
|
||||||
|
return clients;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the doc count on the first core available, then checks all the Shards match.
|
* Waits for the doc count on the first core available, then checks all the Shards match.
|
||||||
* @param query
|
* @param query
|
||||||
@@ -310,10 +319,9 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
public void waitForDocCount(Query query, int count, long waitMillis) throws Exception
|
public void waitForDocCount(Query query, int count, long waitMillis) throws Exception
|
||||||
{
|
{
|
||||||
long begin = System.currentTimeMillis();
|
long begin = System.currentTimeMillis();
|
||||||
List<SolrCore> cores = getJettyCores(jettyContainers.values());
|
|
||||||
//TODO: Support multiple cores per jetty
|
//TODO: Support multiple cores per jetty
|
||||||
SolrCore controlCore = cores.get(0); //Get the first one
|
SolrClient controlClient = getJettyClients().get(0); //Get the first one
|
||||||
waitForDocCountCore(controlCore, query, count, waitMillis, begin);
|
waitForDocCountCore(controlClient, luceneToSolrQuery(query), count, waitMillis, begin);
|
||||||
waitForShardsCount(query, count, waitMillis, begin);
|
waitForShardsCount(query, count, waitMillis, begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,6 +347,9 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
private String fixTermQuery(String query)
|
private String fixTermQuery(String query)
|
||||||
{
|
{
|
||||||
int i = query.lastIndexOf(":");
|
int i = query.lastIndexOf(":");
|
||||||
|
if (i == -1){
|
||||||
|
return query + " ";
|
||||||
|
}
|
||||||
String[] operands = {query.substring(0, i), query.substring(i+1)};
|
String[] operands = {query.substring(0, i), query.substring(i+1)};
|
||||||
|
|
||||||
String s1 = operands[0].replaceAll("\\:", "\\\\:")
|
String s1 = operands[0].replaceAll("\\:", "\\\\:")
|
||||||
@@ -348,12 +359,8 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
return s1 + ":" + operands[1] + " ";
|
return s1 + ":" + operands[1] + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
public SolrQuery luceneToSolrQuery(Query query)
|
||||||
* @param query
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private SolrQuery luceneToSolrQuery(Query query)
|
|
||||||
{
|
{
|
||||||
String[] terms = query.toString().split(" ");
|
String[] terms = query.toString().split(" ");
|
||||||
String solrQueryString = new String();
|
String solrQueryString = new String();
|
||||||
@@ -478,42 +485,39 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
public int assertNodesPerShardGreaterThan(int count, boolean ignoreZero) throws Exception
|
public int assertNodesPerShardGreaterThan(int count, boolean ignoreZero) throws Exception
|
||||||
{
|
{
|
||||||
int shardHit = 0;
|
int shardHit = 0;
|
||||||
|
List<SolrClient> clients = getJettyClients();
|
||||||
List<SolrCore> cores = getJettyCores(jettyShards);
|
List<SolrCore> cores = getJettyCores(jettyShards);
|
||||||
Query query = new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_NODE));
|
SolrQuery query = luceneToSolrQuery(new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_NODE)));
|
||||||
StringBuilder error = new StringBuilder();
|
StringBuilder error = new StringBuilder();
|
||||||
for (SolrCore core : cores)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
{
|
{
|
||||||
RefCounted<SolrIndexSearcher> refCounted = null;
|
|
||||||
try
|
SolrCore core = cores.get(i);
|
||||||
|
SolrClient client = clients.get(i);
|
||||||
|
|
||||||
|
|
||||||
|
QueryResponse response = client.query(query);
|
||||||
|
int totalHits = (int) response.getResults().getNumFound();
|
||||||
|
|
||||||
|
|
||||||
|
if(totalHits > 0)
|
||||||
{
|
{
|
||||||
refCounted = core.getSearcher();
|
shardHit++;
|
||||||
SolrIndexSearcher searcher = refCounted.get();
|
|
||||||
TopDocs topDocs = searcher.search(query, 10);
|
|
||||||
if(topDocs.totalHits > 0)
|
|
||||||
{
|
|
||||||
shardHit++;
|
|
||||||
}
|
|
||||||
if(topDocs.totalHits < count)
|
|
||||||
{
|
|
||||||
if (ignoreZero && topDocs.totalHits == 0)
|
|
||||||
{
|
|
||||||
log.info(core.getName()+": have zero hits ");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error.append(" "+core.getName()+": ");
|
|
||||||
error.append("Expected nodes per shard greater than "+count+" found "+topDocs.totalHits+" : "+query.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.info(core.getName()+": Hits "+topDocs.totalHits);
|
|
||||||
}
|
}
|
||||||
finally
|
if(totalHits < count)
|
||||||
{
|
{
|
||||||
if (refCounted != null)
|
if (ignoreZero && totalHits == 0)
|
||||||
{
|
{
|
||||||
refCounted.decref();
|
log.info(core.getName()+": have zero hits ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.append(" "+core.getName()+": ");
|
||||||
|
error.append("Expected nodes per shard greater than "+count+" found "+totalHits+" : "+query.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info(core.getName()+": Hits "+totalHits);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error.length() > 0)
|
if (error.length() > 0)
|
||||||
@@ -588,8 +592,8 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void waitForDocCountCore(SolrCore core,
|
public void waitForDocCountCore(SolrClient client,
|
||||||
Query query,
|
SolrQuery query,
|
||||||
long expectedNumFound,
|
long expectedNumFound,
|
||||||
long waitMillis,
|
long waitMillis,
|
||||||
long startMillis)
|
long startMillis)
|
||||||
@@ -600,26 +604,15 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
int increment = 1;
|
int increment = 1;
|
||||||
while(new Date().getTime() < timeout)
|
while(new Date().getTime() < timeout)
|
||||||
{
|
{
|
||||||
RefCounted<SolrIndexSearcher> refCounted = null;
|
QueryResponse response = client.query(query);
|
||||||
boolean refCountedDecremented = false;
|
totalHits = (int) response.getResults().getNumFound();
|
||||||
try {
|
|
||||||
refCounted = core.getSearcher();
|
if (totalHits == expectedNumFound) {
|
||||||
SolrIndexSearcher searcher = refCounted.get();
|
return;
|
||||||
TopDocs topDocs = searcher.search(query, 10);
|
} else {
|
||||||
totalHits = topDocs.totalHits;
|
Thread.sleep(500 * increment++);
|
||||||
refCounted.decref();
|
|
||||||
refCountedDecremented = true;
|
|
||||||
if (topDocs.totalHits == expectedNumFound) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
Thread.sleep(500 * increment++);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if(refCounted!=null && !refCountedDecremented)
|
|
||||||
{
|
|
||||||
refCounted.decref();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
throw new Exception("Core:Wait error expected "+expectedNumFound+" found "+totalHits+" : "+query.toString());
|
throw new Exception("Core:Wait error expected "+expectedNumFound+" found "+totalHits+" : "+query.toString());
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ import org.apache.lucene.search.Query;
|
|||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -97,6 +98,7 @@ public class DistributedExplicitShardRoutingTrackerTest extends AbstractAlfresco
|
|||||||
Query contentQuery = new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world"));
|
Query contentQuery = new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world"));
|
||||||
Query aclQuery = new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL));
|
Query aclQuery = new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL));
|
||||||
List<SolrCore> shards = getJettyCores(jettyShards);
|
List<SolrCore> shards = getJettyCores(jettyShards);
|
||||||
|
List<SolrClient> shardClients = getClusterClients();
|
||||||
long begin = System.currentTimeMillis();
|
long begin = System.currentTimeMillis();
|
||||||
|
|
||||||
//Acls go to all cores
|
//Acls go to all cores
|
||||||
@@ -106,13 +108,15 @@ public class DistributedExplicitShardRoutingTrackerTest extends AbstractAlfresco
|
|||||||
waitForShardsCount(contentQuery,numNodes,20000, begin);
|
waitForShardsCount(contentQuery,numNodes,20000, begin);
|
||||||
begin = System.currentTimeMillis();
|
begin = System.currentTimeMillis();
|
||||||
|
|
||||||
for (SolrCore core : shards)
|
for (int i = 0; i < shardClients.size(); ++i)
|
||||||
{
|
{
|
||||||
|
SolrCore core = shards.get(i);
|
||||||
|
SolrClient client = shardClients.get(i);
|
||||||
switch (core.getName())
|
switch (core.getName())
|
||||||
{
|
{
|
||||||
case "shard0":
|
case "shard0":
|
||||||
case "shard1":
|
case "shard1":
|
||||||
waitForDocCountCore(core, contentQuery, 500, 1000, begin);
|
waitForDocCountCore(client, luceneToSolrQuery(contentQuery), 500, 1000, begin);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//ignore other shards because we will check below
|
//ignore other shards because we will check below
|
||||||
|
Reference in New Issue
Block a user