From 2a2a0b6acd527ae219b66d22b67c2c7b37273bf2 Mon Sep 17 00:00:00 2001 From: Varun Thacker Date: Thu, 12 Apr 2018 15:25:11 -0700 Subject: [PATCH] SOLR-12150: Fix a test bug in CdcrBidirectionalTest.testBiDir --- solr/CHANGES.txt | 2 ++ .../cloud/cdcr/CdcrBidirectionalTest.java | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index c2e6da78984..3194e3d7408 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -149,6 +149,8 @@ Bug Fixes * SOLR-12065: A successful restore collection should mark the shard state as active and not buffering (Rohit, Varun Thacker) + +* SOLR-12150: Fix a test bug in CdcrBidirectionalTest.testBiDir (Steve Rowe, Amrit Sarkar via Varun Thacker) Optimizations ---------------------- diff --git a/solr/core/src/test/org/apache/solr/cloud/cdcr/CdcrBidirectionalTest.java b/solr/core/src/test/org/apache/solr/cloud/cdcr/CdcrBidirectionalTest.java index 4a7fae4164a..a11b9ac3231 100644 --- a/solr/core/src/test/org/apache/solr/cloud/cdcr/CdcrBidirectionalTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/cdcr/CdcrBidirectionalTest.java @@ -32,7 +32,9 @@ import org.apache.solr.cloud.MiniSolrCloudCluster; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.TimeSource; import org.apache.solr.handler.CdcrParams; +import org.apache.solr.util.TimeOut; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,19 +187,20 @@ public class CdcrBidirectionalTest extends SolrTestCaseJ4 { // ATOMIC UPDATES req = new UpdateRequest(); doc = new SolrInputDocument(); + String atomicFieldName = "abc"; ImmutableMap.of("", ""); String atomicUpdateId = "cluster2_" + random().nextInt(numDocs_c2); doc.addField("id", atomicUpdateId); doc.addField("xyz", ImmutableMap.of("delete", "")); - doc.addField("abc", ImmutableMap.of("set", "ABC")); + doc.addField(atomicFieldName, ImmutableMap.of("set", "ABC")); req.add(doc); req.process(cluster2SolrClient); cluster2SolrClient.commit(); String atomicQuery = "id:" + atomicUpdateId; response = cluster2SolrClient.query(new SolrQuery(atomicQuery)); - assertEquals("cluster 2 wrong doc", "ABC", response.getResults().get(0).get("abc")); - assertEquals("cluster 1 wrong doc", "ABC", getDocFieldValue(cluster1SolrClient, atomicQuery, "ABC")); + assertEquals("cluster 2 wrong doc", "ABC", response.getResults().get(0).get(atomicFieldName)); + assertEquals("cluster 1 wrong doc", "ABC", getDocFieldValue(cluster1SolrClient, atomicQuery, "ABC", atomicFieldName )); // 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 { - long start = System.nanoTime(); - QueryResponse response = null; - while (System.nanoTime() - start <= TimeUnit.NANOSECONDS.convert(120, TimeUnit.SECONDS)) { + private String getDocFieldValue(CloudSolrClient clusterSolrClient, String query, String match, String field) throws Exception { + TimeOut waitTimeOut = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); + while (!waitTimeOut.hasTimedOut()) { clusterSolrClient.commit(); - response = clusterSolrClient.query(new SolrQuery(query)); - if (match.equals(response.getResults().get(0).get("abc"))) { - break; + QueryResponse response = clusterSolrClient.query(new SolrQuery(query)); + if (response.getResults().size() > 0 && match.equals(response.getResults().get(0).get(field))) { + return (String) response.getResults().get(0).get(field); } Thread.sleep(1000); } - return response != null ? (String) response.getResults().get(0).get("abc") : ""; + return null; } }