Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
LuXugang committed Aug 1, 2023
1 parent ed75fe7 commit 9af4ba5
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -867,14 +867,20 @@ public void testRandomLong() throws IOException {
writer.flush();
}
}
boolean reverse = random().nextBoolean();
writer.flush();
seqNos.sort(Long::compare);
if (reverse == false) {
seqNos.sort(Long::compare);
} else {
seqNos.sort(Collections.reverseOrder());
}
IndexReader reader = DirectoryReader.open(writer);
writer.close();
IndexSearcher searcher = newSearcher(reader, random().nextBoolean(), random().nextBoolean());
SortField sortField = new SortField("seq_no", SortField.Type.LONG);
SortField sortField = new SortField("seq_no", SortField.Type.LONG, reverse);
int visitedHits = 0;
ScoreDoc after = null;
// test page search
while (visitedHits < seqNos.size()) {
int batch = 1 + random().nextInt(100);
Query query =
Expand All @@ -892,6 +898,17 @@ public void testRandomLong() throws IOException {
visitedHits++;
}
}

// test search
int numHits = 1 + random().nextInt(100);
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
TopFieldCollector.createSharedManager(new Sort(sortField), numHits, null, numHits);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
long expectedSeqNo = seqNos.get(i);
FieldDoc fieldDoc = (FieldDoc) topDocs.scoreDocs[i];
assertEquals(expectedSeqNo, ((Long) fieldDoc.fields[0]).intValue());
}
reader.close();
dir.close();
}
Expand Down

0 comments on commit 9af4ba5

Please sign in to comment.