SOLR-12150: Fix a test bug in CdcrBidirectionalTest.testBiDir

This commit is contained in:
Varun Thacker 2018-04-12 15:25:11 -07:00
parent 3d5f2f24c3
commit 2a2a0b6acd
2 changed files with 15 additions and 11 deletions

View File

@ -150,6 +150,8 @@ Bug Fixes
* SOLR-12065: A successful restore collection should mark the shard state as active and not buffering * SOLR-12065: A successful restore collection should mark the shard state as active and not buffering
(Rohit, Varun Thacker) (Rohit, Varun Thacker)
* SOLR-12150: Fix a test bug in CdcrBidirectionalTest.testBiDir (Steve Rowe, Amrit Sarkar via Varun Thacker)
Optimizations Optimizations
---------------------- ----------------------

View File

@ -32,7 +32,9 @@ import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.handler.CdcrParams; import org.apache.solr.handler.CdcrParams;
import org.apache.solr.util.TimeOut;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -185,19 +187,20 @@ public class CdcrBidirectionalTest extends SolrTestCaseJ4 {
// ATOMIC UPDATES // ATOMIC UPDATES
req = new UpdateRequest(); req = new UpdateRequest();
doc = new SolrInputDocument(); doc = new SolrInputDocument();
String atomicFieldName = "abc";
ImmutableMap.of("", ""); ImmutableMap.of("", "");
String atomicUpdateId = "cluster2_" + random().nextInt(numDocs_c2); String atomicUpdateId = "cluster2_" + random().nextInt(numDocs_c2);
doc.addField("id", atomicUpdateId); doc.addField("id", atomicUpdateId);
doc.addField("xyz", ImmutableMap.of("delete", "")); doc.addField("xyz", ImmutableMap.of("delete", ""));
doc.addField("abc", ImmutableMap.of("set", "ABC")); doc.addField(atomicFieldName, ImmutableMap.of("set", "ABC"));
req.add(doc); req.add(doc);
req.process(cluster2SolrClient); req.process(cluster2SolrClient);
cluster2SolrClient.commit(); cluster2SolrClient.commit();
String atomicQuery = "id:" + atomicUpdateId; String atomicQuery = "id:" + atomicUpdateId;
response = cluster2SolrClient.query(new SolrQuery(atomicQuery)); response = cluster2SolrClient.query(new SolrQuery(atomicQuery));
assertEquals("cluster 2 wrong doc", "ABC", response.getResults().get(0).get("abc")); assertEquals("cluster 2 wrong doc", "ABC", response.getResults().get(0).get(atomicFieldName));
assertEquals("cluster 1 wrong doc", "ABC", getDocFieldValue(cluster1SolrClient, atomicQuery, "ABC")); assertEquals("cluster 1 wrong doc", "ABC", getDocFieldValue(cluster1SolrClient, atomicQuery, "ABC", atomicFieldName ));
// logging cdcr clusters queue response // logging cdcr clusters queue response
@ -218,17 +221,16 @@ public class CdcrBidirectionalTest extends SolrTestCaseJ4 {
} }
} }
private String getDocFieldValue(CloudSolrClient clusterSolrClient, String query, String match) throws Exception { private String getDocFieldValue(CloudSolrClient clusterSolrClient, String query, String match, String field) throws Exception {
long start = System.nanoTime(); TimeOut waitTimeOut = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
QueryResponse response = null; while (!waitTimeOut.hasTimedOut()) {
while (System.nanoTime() - start <= TimeUnit.NANOSECONDS.convert(120, TimeUnit.SECONDS)) {
clusterSolrClient.commit(); clusterSolrClient.commit();
response = clusterSolrClient.query(new SolrQuery(query)); QueryResponse response = clusterSolrClient.query(new SolrQuery(query));
if (match.equals(response.getResults().get(0).get("abc"))) { if (response.getResults().size() > 0 && match.equals(response.getResults().get(0).get(field))) {
break; return (String) response.getResults().get(0).get(field);
} }
Thread.sleep(1000); Thread.sleep(1000);
} }
return response != null ? (String) response.getResults().get(0).get("abc") : ""; return null;
} }
} }