Apache Lucene open-source search software
SOLR-10114: test cleanup
yonikd49edabf8992
diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.javaindex 5daf944ff15..8dffac24dcf 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;}-@BeforeClasspublic 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 {// Assertingassrt.run();+ } catch (Throwable thr) {+ throw new Exception(thr);} finally {DirectUpdateHandler2.commitOnClose = true;UpdateLog.testing_logReplayHook = null;diff --git a/solr/core/src/test/org/apache/solr/update/PeerSyncTest.java b/solr/core/src/test/org/apache/solr/update/PeerSyncTest.javaindex fed30a1dca4..848d1bc975f 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 deleteByQueryv=1000;@@ -150,9 +146,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {docsAdded.add(1002); // 1002 addedassertSync(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 shouldv=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 addedassertSync(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 failsv = 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 updatesadd(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 anythingassertSync(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 {diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex c70195cc4b0..c9b25a822df 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);