You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2020/06/24 16:50:32 UTC
[lucene-solr] 03/07: pimp test to randomly use soft-deletes which
also check if DV updates work accordingly
This is an automated email from the ASF dual-hosted git repository.
simonw pushed a commit to branch jira/lucene-8962
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit a533094c1479e9e350ad7f364e64f6ec362a62d0
Author: Simon Willnauer <si...@apache.org>
AuthorDate: Wed Jun 24 18:23:50 2020 +0200
pimp test to randomly use soft-deletes which also check if DV updates work accordingly
---
.../org/apache/lucene/index/TestIndexWriterMergePolicy.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
index 08222ef..654c6a9 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
@@ -25,6 +25,7 @@ import java.util.concurrent.CountDownLatch;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.IndexSearcher;
@@ -368,10 +369,12 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
public void testCarryOverNewDeletes() throws IOException, InterruptedException {
try (Directory directory = newDirectory()) {
+ boolean useSoftDeletes = random().nextBoolean();
CountDownLatch waitForMerge = new CountDownLatch(1);
CountDownLatch waitForUpdate = new CountDownLatch(1);
try (IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig()
.setMergePolicy(MERGE_ON_COMMIT_POLICY).setMaxCommitMergeWaitSeconds(30)
+ .setSoftDeletesField("soft_delete")
.setMergeScheduler(new ConcurrentMergeScheduler())) {
@Override
protected void merge(MergePolicy.OneMerge merge) throws IOException {
@@ -384,6 +387,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
super.merge(merge);
}
}) {
+
Document d1 = new Document();
d1.add(new StringField("id", "1", Field.Store.NO));
Document d2 = new Document();
@@ -394,7 +398,11 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
Thread t = new Thread(() -> {
try {
waitForMerge.await();
- writer.updateDocument(new Term("id", "2"), d2);
+ if (useSoftDeletes) {
+ writer.softUpdateDocument(new Term("id", "2"), d2, new NumericDocValuesField("soft_delete", 1));
+ } else {
+ writer.updateDocument(new Term("id", "2"), d2);
+ }
writer.flush();
waitForUpdate.countDown();
} catch (Exception e) {
@@ -404,7 +412,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
t.start();
writer.commit();
t.join();
- try (DirectoryReader open = DirectoryReader.open(directory)) {
+ try (DirectoryReader open = new SoftDeletesDirectoryReaderWrapper(DirectoryReader.open(directory), "soft_delete")) {
assertEquals(2, open.numDocs());
}
}