mirror of https://github.com/apache/lucene.git
SOLR-10114: test cleanup
This commit is contained in:
parent
2d3487dba2
commit
d49edabf89
|
@ -70,8 +70,6 @@ public class TestRecovery extends SolrTestCaseJ4 {
|
||||||
static String savedFactory;
|
static String savedFactory;
|
||||||
|
|
||||||
|
|
||||||
private interface RunnableWithException{void run () throws Exception;}
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
savedFactory = System.getProperty("solr.DirectoryFactory");
|
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 {
|
try {
|
||||||
|
|
||||||
|
@ -417,6 +415,8 @@ public class TestRecovery extends SolrTestCaseJ4 {
|
||||||
// Asserting
|
// Asserting
|
||||||
assrt.run();
|
assrt.run();
|
||||||
|
|
||||||
|
} catch (Throwable thr) {
|
||||||
|
throw new Exception(thr);
|
||||||
} finally {
|
} finally {
|
||||||
DirectUpdateHandler2.commitOnClose = true;
|
DirectUpdateHandler2.commitOnClose = true;
|
||||||
UpdateLog.testing_logReplayHook = null;
|
UpdateLog.testing_logReplayHook = null;
|
||||||
|
|
|
@ -115,9 +115,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
|
||||||
for (int i=0; i<10; i++) docsAdded.add(i+1);
|
for (int i=0; i<10; i++) docsAdded.add(i+1);
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
|
|
||||||
client0.commit(); client1.commit();
|
validateDocs(docsAdded, client0, client1);
|
||||||
QueryResponse qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000"), client0, client1);
|
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
|
||||||
|
|
||||||
int toAdd = (int)(numVersions *.95);
|
int toAdd = (int)(numVersions *.95);
|
||||||
for (int i=0; i<toAdd; i++) {
|
for (int i=0; i<toAdd; i++) {
|
||||||
|
@ -135,9 +133,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
client0.commit(); client1.commit();
|
validateDocs(docsAdded, client0, client1);
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
|
||||||
|
|
||||||
// test delete and deleteByQuery
|
// test delete and deleteByQuery
|
||||||
v=1000;
|
v=1000;
|
||||||
|
@ -150,9 +146,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
|
||||||
docsAdded.add(1002); // 1002 added
|
docsAdded.add(1002); // 1002 added
|
||||||
|
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
client0.commit(); client1.commit();
|
validateDocs(docsAdded, client0, client1);
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
|
||||||
|
|
||||||
// test that delete by query is returned even if not requested, and that it doesn't delete newer stuff than it should
|
// test that delete by query is returned even if not requested, and that it doesn't delete newer stuff than it should
|
||||||
v=2000;
|
v=2000;
|
||||||
|
@ -174,9 +168,8 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
|
||||||
del(client, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_",Long.toString(-++v)), "2000");
|
del(client, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_",Long.toString(-++v)), "2000");
|
||||||
|
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
client0.commit(); client1.commit();
|
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
validateDocs(docsAdded, client0, client1);
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Test that handling reorders work when applying docs retrieved from peer
|
// 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
|
docsAdded.add(3002); // 3002 added
|
||||||
|
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
client0.commit(); client1.commit();
|
validateDocs(docsAdded, client0, client1);
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
|
||||||
|
|
||||||
// now lets check fingerprinting causes appropriate fails
|
// now lets check fingerprinting causes appropriate fails
|
||||||
v = 4000;
|
v = 4000;
|
||||||
|
@ -238,9 +229,7 @@ public class PeerSyncTest extends BaseDistributedSearchTestCase {
|
||||||
}
|
}
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
|
|
||||||
client0.commit(); client1.commit();
|
validateDocs(docsAdded, client0, client1);
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
|
||||||
|
|
||||||
// lets add some in-place updates
|
// lets add some in-place updates
|
||||||
add(client0, seenLeader, sdoc("id", "5000", "val_i_dvo", 0, "title", "mytitle", "_version_", 5000)); // full update
|
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
|
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]);
|
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()) {
|
add(client0, seenLeader, sdoc("id", "5000", "val_i_dvo", 0, "title", "mytitle", "_version_", 5000)); // full update
|
||||||
client0.commit(); client1.commit();
|
docsAdded.add(5000);
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
inPlaceParams.set(DistributedUpdateProcessor.DISTRIB_INPLACE_PREVVERSION, "5004");
|
||||||
}
|
add(client0, inPlaceParams, sdoc("id", 5000, "val_i_dvo", 3, "_version_", 5006));
|
||||||
del(client0, params(DISTRIB_UPDATE_PARAM,FROM_LEADER,"_version_","5007"), 5000);
|
assertSync(client1, numVersions, true, shardsArr[0]);
|
||||||
docsAdded.remove(5000);
|
|
||||||
assertSync(client1, numVersions, true, shardsArr[0]);
|
|
||||||
|
|
||||||
client0.commit(); client1.commit();
|
// verify the in-place updated document (id=5000) has correct fields
|
||||||
qacResponse = queryAndCompare(params("q", "*:*", "rows", "10000", "sort","_version_ desc"), client0, client1);
|
assertEquals(3, client1.getById("5000").get("val_i_dvo"));
|
||||||
validateQACResponse(docsAdded, qacResponse);
|
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 {
|
void assertSync(SolrClient client, int numVersions, boolean expectedResult, String... syncWith) throws IOException, SolrServerException {
|
||||||
|
|
|
@ -1302,11 +1302,18 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
|
|
||||||
public SolrInputDocument sdocWithChildren(String id, String version, int childCount) {
|
public SolrInputDocument sdocWithChildren(String id, String version, int childCount) {
|
||||||
SolrInputDocument doc = sdoc("id", id, "_version_", version);
|
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));
|
doc.addChildDocument(sdoc("id", id + "_child" + i));
|
||||||
}
|
}
|
||||||
return doc;
|
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) {
|
public static List<SolrInputDocument> sdocs(SolrInputDocument... docs) {
|
||||||
return Arrays.asList(docs);
|
return Arrays.asList(docs);
|
||||||
|
|
Loading…
Reference in New Issue