diff --git a/server/src/test/java/org/opensearch/index/mapper/BytesRefsCollectionBuilderTests.java b/server/src/test/java/org/opensearch/index/mapper/BytesRefsCollectionBuilderTests.java index 83c4877a1949e..c3860a3f8a66f 100644 --- a/server/src/test/java/org/opensearch/index/mapper/BytesRefsCollectionBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/BytesRefsCollectionBuilderTests.java @@ -28,8 +28,10 @@ public void testBuildSortedNotSorted() { Collection sortedSet = assertCollectionBuilt(sortedBytesRefs); assertCollectionBuilt(bytesRefList); - assertTrue(sortedSet instanceof SortedSet); - assertNull(((SortedSet) sortedSet).comparator()); + assertTrue(sortedSet.isEmpty() || sortedSet instanceof SortedSet); + if (!sortedSet.isEmpty()) { + assertNull(((SortedSet) sortedSet).comparator()); + } } public void testBuildFooBar() { diff --git a/server/src/test/java/org/opensearch/index/mapper/KeywordFieldTypeTests.java b/server/src/test/java/org/opensearch/index/mapper/KeywordFieldTypeTests.java index 4074cb0497e6c..02fd0d825c26f 100644 --- a/server/src/test/java/org/opensearch/index/mapper/KeywordFieldTypeTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/KeywordFieldTypeTests.java @@ -33,8 +33,6 @@ import com.carrotsearch.randomizedtesting.generators.RandomStrings; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.LowerCaseFilter; import org.apache.lucene.analysis.TokenFilter; @@ -79,18 +77,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Random; -import java.util.SortedSet; -import java.util.stream.Stream; - -import org.mockito.MockedConstruction; -import org.mockito.stubbing.Answer; - -import static org.mockito.Mockito.mockConstructionWithAnswer; public class KeywordFieldTypeTests extends FieldTypeTestCase { @@ -229,57 +218,6 @@ public void testTermsSortedQuery() { assertEquals(expectedDocValues, onlyDocValues.termsQuery(sortedStrings, null)); } - @AwaitsFix(bugUrl = "no commit") - public void testMockTermsSortedQuery() { - String[] seedStrings = generateRandomStringArray(10, 10, false, false); - if (seedStrings.length == 1) { - seedStrings = Stream.concat(Arrays.stream(seedStrings), Arrays.stream(generateRandomStringArray(10, 10, false, false))) - .toArray(String[]::new); - } - List bytesRefList = Arrays.stream(seedStrings).map(BytesRef::new).toList(); - List sortedStrings = bytesRefList.stream().sorted().map(BytesRef::utf8ToString).toList(); - Answer asseretSortedSetArg = invocationOnMock -> { - Object[] args = invocationOnMock.getArguments(); - for (int i = 0; i < args.length; i++) { - if (args[i] instanceof Collection) { - assertTrue(args[i] instanceof SortedSet); - return invocationOnMock.callRealMethod(); - } - } - fail(); - return null; - }; - try (MockedConstruction ignored = mockConstructionWithAnswer(TermInSetQuery.class, asseretSortedSetArg)) { - MappedFieldType ft = new KeywordFieldType("field"); - assertNotNull(ft.termsQuery(sortedStrings, MOCK_QSC_ENABLE_INDEX_DOC_VALUES)); - MappedFieldType onlyIndexed = new KeywordFieldType("field", true, false, Collections.emptyMap()); - assertNotNull(onlyIndexed.termsQuery(sortedStrings, null)); - MappedFieldType onlyDocValues = new KeywordFieldType("field", false, true, Collections.emptyMap()); - assertNotNull(onlyDocValues.termsQuery(sortedStrings, null)); - } - } - - @AwaitsFix(bugUrl = "no commit") - public void testHeavyWeight() { - int arraySize = 10000000; - BytesRef[] array = new BytesRef[arraySize]; - Random random = random(); - for (int i = 0; i < arraySize; i++) { - String str = RandomStrings.randomAsciiOfLength(random, 10); - array[i] = new BytesRef(str); - } - BytesRefsCollectionBuilder outofOrder = new BytesRefsCollectionBuilder(arraySize); - BytesRefsCollectionBuilder inOrder = new BytesRefsCollectionBuilder(arraySize); - Arrays.stream(array).forEach(outofOrder); - Arrays.stream(array).sorted().forEachOrdered(inOrder); - Logger logger = LogManager.getLogger(KeywordFieldTypeTests.class); - long start = System.currentTimeMillis(), intermid; - new TermInSetQuery("foo", outofOrder.get()); - logger.info("out of order {} ms", (intermid = System.currentTimeMillis()) - start); - new TermInSetQuery("foo", inOrder.get()); - logger.info("in order{} ms", System.currentTimeMillis() - intermid); - } - public void testExistsQuery() { { KeywordFieldType ft = new KeywordFieldType("field");