Skip to content

Commit

Permalink
Fix ShardSplittingQueryTests by not using MockRandomMergePolicy for t…
Browse files Browse the repository at this point in the history
…he IndexWriter
  • Loading branch information
carlosdelest committed Jan 15, 2024
1 parent af9bac9 commit 1c2f386
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.lucene.search.Weight;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.routing.IndexRouting;
Expand All @@ -46,7 +47,7 @@ public void testSplitOnID() throws IOException {
SeqNoFieldMapper.SequenceIDFields sequenceIDFields = SeqNoFieldMapper.SequenceIDFields.emptySeqID();
Directory dir = newFSDirectory(createTempDir());
final int numDocs = randomIntBetween(50, 100);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
RandomIndexWriter writer = createIndexWriter(dir);
int numShards = randomIntBetween(2, 10);
IndexMetadata metadata = IndexMetadata.builder("test")
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()))
Expand All @@ -72,7 +73,7 @@ public void testSplitOnRouting() throws IOException {
SeqNoFieldMapper.SequenceIDFields sequenceIDFields = SeqNoFieldMapper.SequenceIDFields.emptySeqID();
Directory dir = newFSDirectory(createTempDir());
final int numDocs = randomIntBetween(50, 100);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
RandomIndexWriter writer = createIndexWriter(dir);
int numShards = randomIntBetween(2, 10);
IndexMetadata metadata = IndexMetadata.builder("test")
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()))
Expand All @@ -97,7 +98,7 @@ public void testSplitOnIdOrRouting() throws IOException {
SeqNoFieldMapper.SequenceIDFields sequenceIDFields = SeqNoFieldMapper.SequenceIDFields.emptySeqID();
Directory dir = newFSDirectory(createTempDir());
final int numDocs = randomIntBetween(50, 100);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
RandomIndexWriter writer = createIndexWriter(dir);
int numShards = randomIntBetween(2, 10);
IndexMetadata metadata = IndexMetadata.builder("test")
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()))
Expand All @@ -124,7 +125,7 @@ public void testSplitOnRoutingPartitioned() throws IOException {
SeqNoFieldMapper.SequenceIDFields sequenceIDFields = SeqNoFieldMapper.SequenceIDFields.emptySeqID();
Directory dir = newFSDirectory(createTempDir());
final int numDocs = randomIntBetween(50, 100);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
RandomIndexWriter writer = createIndexWriter(dir);
int numShards = randomIntBetween(2, 10);
IndexMetadata metadata = IndexMetadata.builder("test")
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()))
Expand Down Expand Up @@ -236,4 +237,12 @@ private Iterable<IndexableField> topLevel(IndexRouting indexRouting, int id, @Nu
private int shardId(IndexRouting indexRouting, int id, @Nullable String routing) {
return indexRouting.getShard(Integer.toString(id), routing);
}

private static RandomIndexWriter createIndexWriter(Directory dir) throws IOException {
return new RandomIndexWriter(
random(),
dir,
LuceneTestCase.newIndexWriterConfig().setMergePolicy(LuceneTestCase.newMergePolicy(random(), false))
);
}
}

0 comments on commit 1c2f386

Please sign in to comment.