diff --git a/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java index cad1ff15b05..9dddedd548f 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java @@ -59,7 +59,6 @@ import org.elasticsearch.node.settings.NodeSettingsService; import org.elasticsearch.search.internal.ContextIndexSearcher; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.ElasticsearchLuceneTestCase; -import org.elasticsearch.test.cache.recycler.MockBigArrays; import org.elasticsearch.test.index.service.StubIndexService; import org.elasticsearch.threadpool.ThreadPool; import org.hamcrest.Description; @@ -149,7 +148,7 @@ public class ChildrenConstantScoreQueryTests extends ElasticsearchLuceneTestCase .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH) .setRAMBufferSizeMB(scaledRandomIntBetween(16, 64)); // we might index a lot - don't go crazy here RandomIndexWriter indexWriter = new RandomIndexWriter(r, directory, iwc); - int numUniqueChildValues = scaledRandomIntBetween(1, 10000); + int numUniqueChildValues = scaledRandomIntBetween(100, 2000); String[] childValues = new String[numUniqueChildValues]; for (int i = 0; i < numUniqueChildValues; i++) { childValues[i] = Integer.toString(i); @@ -157,7 +156,7 @@ public class ChildrenConstantScoreQueryTests extends ElasticsearchLuceneTestCase IntOpenHashSet filteredOrDeletedDocs = new IntOpenHashSet(); int childDocId = 0; - int numParentDocs = scaledRandomIntBetween(1, 2000); + int numParentDocs = scaledRandomIntBetween(1, numUniqueChildValues); ObjectObjectOpenHashMap> childValueToParentIds = new ObjectObjectOpenHashMap<>(); for (int parentDocId = 0; parentDocId < numParentDocs; parentDocId++) { boolean markParentAsDeleted = rarely(); diff --git a/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java index 6c0a55d5ef8..e5386823d26 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.search.child; import com.carrotsearch.hppc.FloatArrayList; import com.carrotsearch.hppc.IntOpenHashSet; import com.carrotsearch.hppc.ObjectObjectOpenHashMap; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; @@ -29,6 +30,7 @@ import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.common.lucene.search.NotFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.index.engine.Engine; @@ -48,6 +50,7 @@ import org.junit.Test; import java.io.IOException; import java.util.Map; import java.util.NavigableMap; +import java.util.Random; import java.util.TreeMap; import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.assertBitSet; @@ -81,8 +84,13 @@ public class ChildrenQueryTests extends ElasticsearchLuceneTestCase { @Test public void testRandom() throws Exception { Directory directory = newDirectory(); - RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory); - int numUniqueChildValues = 1 + random().nextInt(TEST_NIGHTLY ? 6000 : 600); + final Random r = random(); + final IndexWriterConfig iwc = LuceneTestCase.newIndexWriterConfig(r, + LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(r)) + .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH) + .setRAMBufferSizeMB(scaledRandomIntBetween(16, 64)); // we might index a lot - don't go crazy here + RandomIndexWriter indexWriter = new RandomIndexWriter(r, directory, iwc); + int numUniqueChildValues = scaledRandomIntBetween(100, 2000); String[] childValues = new String[numUniqueChildValues]; for (int i = 0; i < numUniqueChildValues; i++) { childValues[i] = Integer.toString(i); @@ -91,7 +99,7 @@ public class ChildrenQueryTests extends ElasticsearchLuceneTestCase { IntOpenHashSet filteredOrDeletedDocs = new IntOpenHashSet(); int childDocId = 0; - int numParentDocs = 1 + random().nextInt(TEST_NIGHTLY ? 20000 : 1000); + int numParentDocs = scaledRandomIntBetween(1, numUniqueChildValues); ObjectObjectOpenHashMap> childValueToParentIds = new ObjectObjectOpenHashMap<>(); for (int parentDocId = 0; parentDocId < numParentDocs; parentDocId++) { boolean markParentAsDeleted = rarely(); @@ -110,12 +118,7 @@ public class ChildrenQueryTests extends ElasticsearchLuceneTestCase { } indexWriter.addDocument(document); - int numChildDocs; - if (rarely()) { - numChildDocs = random().nextInt(TEST_NIGHTLY ? 100 : 25); - } else { - numChildDocs = random().nextInt(TEST_NIGHTLY ? 40 : 10); - } + int numChildDocs = scaledRandomIntBetween(0, 100); for (int i = 0; i < numChildDocs; i++) { boolean markChildAsDeleted = rarely(); String childValue = childValues[random().nextInt(childValues.length)]; diff --git a/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java index aa9b8d5be25..127a4ba6196 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java @@ -88,14 +88,14 @@ public class ParentConstantScoreQueryTests extends ElasticsearchLuceneTestCase { .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH) .setRAMBufferSizeMB(scaledRandomIntBetween(16, 64)); // we might index a lot - don't go crazy here RandomIndexWriter indexWriter = new RandomIndexWriter(r, directory, iwc); - int numUniqueParentValues = scaledRandomIntBetween(1, 1000); + int numUniqueParentValues = scaledRandomIntBetween(100, 2000); String[] parentValues = new String[numUniqueParentValues]; for (int i = 0; i < numUniqueParentValues; i++) { parentValues[i] = Integer.toString(i); } int childDocId = 0; - int numParentDocs = scaledRandomIntBetween(1, 2000); + int numParentDocs = scaledRandomIntBetween(1, numUniqueParentValues); ObjectObjectOpenHashMap> parentValueToChildDocIds = new ObjectObjectOpenHashMap<>(); IntIntOpenHashMap childIdToParentId = new IntIntOpenHashMap(); for (int parentDocId = 0; parentDocId < numParentDocs; parentDocId++) { diff --git a/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java index 7c09e5ed16c..f86e4815809 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.search.child; import com.carrotsearch.hppc.FloatArrayList; import com.carrotsearch.hppc.IntIntOpenHashMap; import com.carrotsearch.hppc.ObjectObjectOpenHashMap; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; @@ -29,6 +30,7 @@ import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.common.lucene.search.NotFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.index.engine.Engine; @@ -47,6 +49,7 @@ import org.junit.Test; import java.io.IOException; import java.util.Map; import java.util.NavigableMap; +import java.util.Random; import java.util.TreeMap; import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.assertBitSet; @@ -79,15 +82,20 @@ public class ParentQueryTests extends ElasticsearchLuceneTestCase { @Test public void testRandom() throws Exception { Directory directory = newDirectory(); - RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory); - int numUniqueParentValues = 1 + random().nextInt(TEST_NIGHTLY ? 6000 : 600); + final Random r = random(); + final IndexWriterConfig iwc = LuceneTestCase.newIndexWriterConfig(r, + LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(r)) + .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH) + .setRAMBufferSizeMB(scaledRandomIntBetween(16, 64)); // we might index a lot - don't go crazy here + RandomIndexWriter indexWriter = new RandomIndexWriter(r, directory, iwc); + int numUniqueParentValues = scaledRandomIntBetween(100, 2000); String[] parentValues = new String[numUniqueParentValues]; for (int i = 0; i < numUniqueParentValues; i++) { parentValues[i] = Integer.toString(i); } int childDocId = 0; - int numParentDocs = 1 + random().nextInt(TEST_NIGHTLY ? 20000 : 1000); + int numParentDocs = scaledRandomIntBetween(1, numUniqueParentValues); ObjectObjectOpenHashMap> parentValueToChildIds = new ObjectObjectOpenHashMap<>(); IntIntOpenHashMap childIdToParentId = new IntIntOpenHashMap(); for (int parentDocId = 0; parentDocId < numParentDocs; parentDocId++) { @@ -103,12 +111,7 @@ public class ParentQueryTests extends ElasticsearchLuceneTestCase { } indexWriter.addDocument(document); - int numChildDocs; - if (rarely()) { - numChildDocs = random().nextInt(TEST_NIGHTLY ? 100 : 25); - } else { - numChildDocs = random().nextInt(TEST_NIGHTLY ? 40 : 10); - } + int numChildDocs = scaledRandomIntBetween(0, 100); if (parentDocId == numParentDocs - 1 && childIdToParentId.isEmpty()) { // ensure there is at least one child in the index numChildDocs = Math.max(1, numChildDocs); @@ -181,7 +184,7 @@ public class ParentQueryTests extends ElasticsearchLuceneTestCase { // Simulate a child update if (random().nextBoolean()) { - int numberOfUpdates = 1 + random().nextInt(TEST_NIGHTLY ? 25 : 5); + int numberOfUpdates = scaledRandomIntBetween(1, 5); int[] childIds = childIdToParentId.keys().toArray(); for (int j = 0; j < numberOfUpdates; j++) { int childId = childIds[random().nextInt(childIds.length)];