Skip to content

Commit b842e48

Browse files
authored
Fix BytesRefsCollectionBuilderTests.testBuildSortedNotSorted
Followup for #17714: Remove redundant tests (#17902) * Remove redundant tests Signed-off-by: Mikhail Khludnev <[email protected]> * Fix empty collection test Signed-off-by: Mikhail Khludnev <[email protected]> --------- Signed-off-by: Mikhail Khludnev <[email protected]>
1 parent 5a0d5c5 commit b842e48

File tree

2 files changed

+4
-64
lines changed

2 files changed

+4
-64
lines changed

server/src/test/java/org/opensearch/index/mapper/BytesRefsCollectionBuilderTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public void testBuildSortedNotSorted() {
2828
Collection<BytesRef> sortedSet = assertCollectionBuilt(sortedBytesRefs);
2929
assertCollectionBuilt(bytesRefList);
3030

31-
assertTrue(sortedSet instanceof SortedSet<BytesRef>);
32-
assertNull(((SortedSet<BytesRef>) sortedSet).comparator());
31+
assertTrue(sortedSet.isEmpty() || sortedSet instanceof SortedSet<BytesRef>);
32+
if (!sortedSet.isEmpty()) {
33+
assertNull(((SortedSet<BytesRef>) sortedSet).comparator());
34+
}
3335
}
3436

3537
public void testBuildFooBar() {

server/src/test/java/org/opensearch/index/mapper/KeywordFieldTypeTests.java

-62
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
3535

36-
import org.apache.logging.log4j.LogManager;
37-
import org.apache.logging.log4j.Logger;
3836
import org.apache.lucene.analysis.Analyzer;
3937
import org.apache.lucene.analysis.LowerCaseFilter;
4038
import org.apache.lucene.analysis.TokenFilter;
@@ -79,18 +77,9 @@
7977
import java.io.IOException;
8078
import java.util.ArrayList;
8179
import java.util.Arrays;
82-
import java.util.Collection;
8380
import java.util.Collections;
8481
import java.util.List;
8582
import java.util.Map;
86-
import java.util.Random;
87-
import java.util.SortedSet;
88-
import java.util.stream.Stream;
89-
90-
import org.mockito.MockedConstruction;
91-
import org.mockito.stubbing.Answer;
92-
93-
import static org.mockito.Mockito.mockConstructionWithAnswer;
9483

9584
public class KeywordFieldTypeTests extends FieldTypeTestCase {
9685

@@ -229,57 +218,6 @@ public void testTermsSortedQuery() {
229218
assertEquals(expectedDocValues, onlyDocValues.termsQuery(sortedStrings, null));
230219
}
231220

232-
@AwaitsFix(bugUrl = "no commit")
233-
public void testMockTermsSortedQuery() {
234-
String[] seedStrings = generateRandomStringArray(10, 10, false, false);
235-
if (seedStrings.length == 1) {
236-
seedStrings = Stream.concat(Arrays.stream(seedStrings), Arrays.stream(generateRandomStringArray(10, 10, false, false)))
237-
.toArray(String[]::new);
238-
}
239-
List<BytesRef> bytesRefList = Arrays.stream(seedStrings).map(BytesRef::new).toList();
240-
List<String> sortedStrings = bytesRefList.stream().sorted().map(BytesRef::utf8ToString).toList();
241-
Answer asseretSortedSetArg = invocationOnMock -> {
242-
Object[] args = invocationOnMock.getArguments();
243-
for (int i = 0; i < args.length; i++) {
244-
if (args[i] instanceof Collection<?>) {
245-
assertTrue(args[i] instanceof SortedSet<?>);
246-
return invocationOnMock.callRealMethod();
247-
}
248-
}
249-
fail();
250-
return null;
251-
};
252-
try (MockedConstruction<TermInSetQuery> ignored = mockConstructionWithAnswer(TermInSetQuery.class, asseretSortedSetArg)) {
253-
MappedFieldType ft = new KeywordFieldType("field");
254-
assertNotNull(ft.termsQuery(sortedStrings, MOCK_QSC_ENABLE_INDEX_DOC_VALUES));
255-
MappedFieldType onlyIndexed = new KeywordFieldType("field", true, false, Collections.emptyMap());
256-
assertNotNull(onlyIndexed.termsQuery(sortedStrings, null));
257-
MappedFieldType onlyDocValues = new KeywordFieldType("field", false, true, Collections.emptyMap());
258-
assertNotNull(onlyDocValues.termsQuery(sortedStrings, null));
259-
}
260-
}
261-
262-
@AwaitsFix(bugUrl = "no commit")
263-
public void testHeavyWeight() {
264-
int arraySize = 10000000;
265-
BytesRef[] array = new BytesRef[arraySize];
266-
Random random = random();
267-
for (int i = 0; i < arraySize; i++) {
268-
String str = RandomStrings.randomAsciiOfLength(random, 10);
269-
array[i] = new BytesRef(str);
270-
}
271-
BytesRefsCollectionBuilder outofOrder = new BytesRefsCollectionBuilder(arraySize);
272-
BytesRefsCollectionBuilder inOrder = new BytesRefsCollectionBuilder(arraySize);
273-
Arrays.stream(array).forEach(outofOrder);
274-
Arrays.stream(array).sorted().forEachOrdered(inOrder);
275-
Logger logger = LogManager.getLogger(KeywordFieldTypeTests.class);
276-
long start = System.currentTimeMillis(), intermid;
277-
new TermInSetQuery("foo", outofOrder.get());
278-
logger.info("out of order {} ms", (intermid = System.currentTimeMillis()) - start);
279-
new TermInSetQuery("foo", inOrder.get());
280-
logger.info("in order{} ms", System.currentTimeMillis() - intermid);
281-
}
282-
283221
public void testExistsQuery() {
284222
{
285223
KeywordFieldType ft = new KeywordFieldType("field");

0 commit comments

Comments
 (0)