You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2017/02/16 17:45:43 UTC

lucene-solr:master: SOLR-10114: test cleanup

Repository: lucene-solr
Updated Branches:
  refs/heads/master 2d3487dba -> d49edabf8


SOLR-10114: test cleanup


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d49edabf
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d49edabf
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d49edabf

Branch: refs/heads/master
Commit: d49edabf8992c2b2f9e2583e289cc58a4e71fd31
Parents: 2d3487d
Author: yonik <yo...@apache.org>
Authored: Thu Feb 16 12:45:32 2017 -0500
Committer: yonik <yo...@apache.org>
Committed: Thu Feb 16 12:45:32 2017 -0500

----------------------------------------------------------------------
 .../org/apache/solr/search/TestRecovery.java    |   6 +-
 .../org/apache/solr/update/PeerSyncTest.java    | 119 +++++++++++--------
 .../java/org/apache/solr/SolrTestCaseJ4.java    |   9 +-
 3 files changed, 81 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d49edabf/solr/core/src/test/org/apache/solr/search/TestRecovery.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.java
index 5daf944..8dffac2 100644
--- a/solr/core/src/test/org/apache/solr/search/TestRecovery.java
+++ b/solr/core/src/test/org/apache/solr/search/TestRecovery.java
@@ -70,8 +70,6 @@ public class TestRecovery extends SolrTestCaseJ4 {
   static String savedFactory;
 
 
-  private interface RunnableWithException{void run () throws Exception;}
-
   @BeforeClass
   public static void beforeClass() throws Exception {
     savedFactory = System.getProperty("solr.DirectoryFactory");
@@ -371,7 +369,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
     );
   }
 
-  private void testLogReplayWithReorderedDBQWrapper(RunnableWithException act, RunnableWithException assrt) throws Exception {
+  private void testLogReplayWithReorderedDBQWrapper(ThrowingRunnable act, ThrowingRunnable assrt) throws Exception {
 
     try {
 
@@ -417,6 +415,8 @@ public class TestRecovery extends SolrTestCaseJ4 {
       // Asserting
       assrt.run();
 
+    } catch (Throwable thr) {
+      throw new Exception(thr);
     } finally {
       DirectUpdateHandler2.commitOnClose = true;
       UpdateLog.testing_logReplayHook = null;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d49edabf/solr/core/src/test/org/apache/solr/update/PeerSyncTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/PeerSyncTest.java b/solr/core/src/test/org/apache/solr/update/PeerSyncTest.java
index fed30a1..848d1bc 100644
--- a/solr/core/src/test/org/apache/solr/update/PeerSyncTest.java
+++ b/solr/core/src/test/org/apache/solr/update/PeerSyncTest.java
@@ -115,9 +115,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     for (int i=0; i<10; i++) docsAdded.add(i+1);
     assertSync(client1, numVersions, true, shardsArr[0]);
 
-    client0.commit(); client1.commit();
-    QueryResponse qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000"), client0, client1);
-    validateQACResponse(docsAdded, qacResponse);
+    validateDocs(docsAdded, client0, client1);
 
     int toAdd = (int)(numVersions *.95);
     for (int i=0; i<toAdd; i++) {
@@ -135,9 +133,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     }
 
     assertSync(client1, numVersions, true, shardsArr[0]);
-    client0.commit(); client1.commit();
-    qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-    validateQACResponse(docsAdded, qacResponse);
+    validateDocs(docsAdded, client0, client1);
 
     // test delete and deleteByQuery
     v=1000;
@@ -150,9 +146,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     docsAdded.add(1002); // 1002 added
 
     assertSync(client1, numVersions, true, shardsArr[0]);
-    client0.commit(); client1.commit();
-    qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-    validateQACResponse(docsAdded, qacResponse);
+    validateDocs(docsAdded, client0, client1);
 
     // test that delete by query is returned even if not requested, and that it doesn't delete newer stuff than it should
     v=2000;
@@ -174,9 +168,8 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     del(client, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_",Long.toString(-++v)), "2000");
 
     assertSync(client1, numVersions, true, shardsArr[0]);
-    client0.commit(); client1.commit();
-    qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-    validateQACResponse(docsAdded, qacResponse);
+
+    validateDocs(docsAdded, client0, client1);
 
     //
     // Test that handling reorders work when applying docs retrieved from peer
@@ -202,9 +195,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     docsAdded.add(3002); // 3002 added
     
     assertSync(client1, numVersions, true, shardsArr[0]);
-    client0.commit(); client1.commit();
-    qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-    validateQACResponse(docsAdded, qacResponse);
+    validateDocs(docsAdded, client0, client1);
 
     // now lets check fingerprinting causes appropriate fails
     v = 4000;
@@ -238,9 +229,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     }
     assertSync(client1, numVersions, true, shardsArr[0]);
     
-    client0.commit(); client1.commit();
-    qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-    validateQACResponse(docsAdded, qacResponse);
+    validateDocs(docsAdded, client0, client1);
 
     // lets add some in-place updates
     add(client0, seenLeader, sdoc("id", "5000", "val_i_dvo", 0, "title", "mytitle", "_version_", 5000)); // full update
@@ -278,39 +267,71 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
     delQ(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","5005"),  "val_i_dvo:1"); // current val is 2, so this should not delete anything
     assertSync(client1, numVersions, true, shardsArr[0]);
 
-    boolean deleteTheUpdatedDocument = random().nextBoolean();
-    if (deleteTheUpdatedDocument) { // if doc with id=5000 is deleted, further in-place-updates should fail
-      delQ(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","5006"),  "val_i_dvo:2"); // current val is 2, this will delete id=5000
-      assertSync(client1, numVersions, true, shardsArr[0]);
-      SolrException ex = expectThrows(SolrException.class, () -> {
-        inPlaceParams.set(DistributedUpdateProcessor.DISTRIB_INPLACE_PREVVERSION, "5004");
-        add(client0, inPlaceParams, sdoc("id", 5000, "val_i_dvo", 3, "_version_", 5007));
-      });
-      assertEquals(ex.toString(), SolrException.ErrorCode.SERVER_ERROR.code, ex.code());
-      assertThat(ex.getMessage(), containsString("Can't find document with id=5000"));
-    } else {
-      inPlaceParams.set(DistributedUpdateProcessor.DISTRIB_INPLACE_PREVVERSION, "5004");
-      add(client0, inPlaceParams, sdoc("id", 5000, "val_i_dvo", 3, "_version_", 5006));
-      assertSync(client1, numVersions, true, shardsArr[0]);
 
-      // verify the in-place updated document (id=5000) has correct fields
-      assertEquals(3, client1.getById("5000").get("val_i_dvo"));
-      assertEquals(client0.getById("5000")+" and "+client1.getById("5000"), 
-          "mytitle", client1.getById("5000").getFirstValue("title"));
-
-      if (random().nextBoolean()) {
-        client0.commit(); client1.commit();
-        qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-        validateQACResponse(docsAdded, qacResponse);
-      }
-      del(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","5007"),  5000);
-      docsAdded.remove(5000);
-      assertSync(client1, numVersions, true, shardsArr[0]);
 
-      client0.commit(); client1.commit();
-      qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
-      validateQACResponse(docsAdded, qacResponse);
-    }
+    add(client0, seenLeader, sdoc("id", "5000", "val_i_dvo", 0, "title", "mytitle", "_version_", 5000)); // full update
+    docsAdded.add(5000);
+    assertSync(client1, numVersions, true, shardsArr[0]);
+    inPlaceParams.set(DistributedUpdateProcessor.DISTRIB_INPLACE_PREVVERSION, "5004");
+    add(client0, inPlaceParams, sdoc("id", 5000, "val_i_dvo", 3, "_version_", 5006));
+    assertSync(client1, numVersions, true, shardsArr[0]);
+
+    // verify the in-place updated document (id=5000) has correct fields
+    assertEquals(3, client1.getById("5000").get("val_i_dvo"));
+    assertEquals(client0.getById("5000")+" and "+client1.getById("5000"),
+        "mytitle", client1.getById("5000").getFirstValue("title"));
+
+    validateDocs(docsAdded, client0, client1);
+
+    del(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","5007"),  5000);
+    docsAdded.remove(5000);
+    assertSync(client1, numVersions, true, shardsArr[0]);
+
+    validateDocs(docsAdded, client0, client1);
+
+
+    // if doc with id=6000 is deleted, further in-place-updates should fail
+    add(client0, seenLeader, sdoc("id", "6000", "val_i_dvo", 6, "title", "mytitle", "_version_", 6000)); // full update
+    delQ(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","6004"),  "val_i_dvo:6"); // current val is 6000, this will delete id=6000
+    assertSync(client1, numVersions, true, shardsArr[0]);
+    SolrException ex = expectThrows(SolrException.class, () -> {
+      inPlaceParams.set(DistributedUpdateProcessor.DISTRIB_INPLACE_PREVVERSION, "6000");
+      add(client0, inPlaceParams, sdoc("id", 6000, "val_i_dvo", 6003, "_version_", 5007));
+    });
+    assertEquals(ex.toString(), SolrException.ErrorCode.SERVER_ERROR.code, ex.code());
+    assertThat(ex.getMessage(), containsString("Can't find document with id=6000"));
+
+
+    // Reordered DBQ with Child-nodes (SOLR-10114)
+    docsAdded.clear();
+
+    // Reordered full delete should not delete child-docs
+    add(client0, seenLeader, sdocWithChildren(7001, "7001", 2)); // add with later version
+    docsAdded.add(7001);
+    docsAdded.add(7001001);
+    docsAdded.add(7001002);
+    delQ(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","7000"),  "id:*"); // reordered delete
+    assertSync(client1, numVersions, true, shardsArr[0]);
+    validateDocs(docsAdded, client0, client1);
+
+    // Reordered DBQ should not affect update
+    add(client0, seenLeader, sdocWithChildren(8000, "8000", 5)); // add with later version
+    delQ(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","8002"),  "id:8500"); // not found, arrives earlier
+    add(client0, seenLeader, sdocWithChildren(8000, "8001", 2)); // update with two childs
+    docsAdded.add(8000);
+    docsAdded.add(8000001);
+    docsAdded.add(8000002);
+    assertSync(client1, numVersions, true, shardsArr[0]);
+    validateDocs(docsAdded, client0, client1);
+
+  }
+
+  private void validateDocs(Set<Integer> docsAdded, SolrClient client0, SolrClient client1) throws SolrServerException, IOException {
+    client0.commit();
+    client1.commit();
+    QueryResponse qacResponse;
+    qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
+    validateQACResponse(docsAdded, qacResponse);
   }
 
   void assertSync(SolrClient client, int numVersions, boolean expectedResult, String... syncWith) throws IOException, SolrServerException {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d49edabf/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index c70195c..c9b25a8 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -1302,11 +1302,18 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
 
   public SolrInputDocument sdocWithChildren(String id, String version, int childCount) {
     SolrInputDocument doc = sdoc("id", id, "_version_", version);
-    for (int i = 0; i < childCount; i++) {
+    for (int i = 1; i <= childCount; i++) {
       doc.addChildDocument(sdoc("id", id + "_child" + i));
     }
     return doc;
   }
+  public SolrInputDocument sdocWithChildren(Integer id, String version, int childCount) {
+    SolrInputDocument doc = sdoc("id", id, "_version_", version);
+    for (int i = 1; i <= childCount; i++) {
+      doc.addChildDocument(sdoc("id", (1000)*id + i));
+    }
+    return doc;
+  }
 
   public static List<SolrInputDocument> sdocs(SolrInputDocument... docs) {
     return Arrays.asList(docs);