thecoop commented on code in PR #16970:
URL: https://github.com/apache/lucene/pull/16970#discussion_r4456592127
##########
lucene/core/src/test/org/apache/lucene/index/TestSortingStoredFieldsConsumer.java:
##########
@@ -133,4 +146,44 @@ public int size() {
"Expected only 1 seek (for checksum retrieval), not one per
document", 1, numSeeks.get());
}
}
+
+ /**
+ * The temporary stored fields are read back on the flushing thread only, so
their index must be
+ * opened read-once to let directories confine it to that thread.
+ */
+ public void testTempIndexFilesOpenedReadOnce() throws IOException {
+ List<IOContext> tempIndexOpens = new ArrayList<>();
+ try (Directory dir =
+ new FilterDirectory(new ByteBuffersDirectory()) {
+ @Override
+ public IndexInput openInput(String name, IOContext context) throws
IOException {
+ if ((name.contains(".fdx") || name.contains(".tvx")) &&
name.endsWith(".tmp")) {
+ tempIndexOpens.add(context);
+ }
+ return super.openInput(name, context);
+ }
+ }) {
+ IndexWriterConfig iwc =
+ new IndexWriterConfig()
+ .setIndexSort(new Sort(new SortField("sort",
SortField.Type.LONG)));
+ try (IndexWriter writer = new IndexWriter(dir, iwc)) {
+ for (int i = 0; i < 10; i++) {
+ Document doc = new Document();
+ doc.add(new NumericDocValuesField("sort", 10 - i));
+ doc.add(new StoredField("stored", i));
+ FieldType withVectors = new FieldType(TextField.TYPE_NOT_STORED);
+ withVectors.setStoreTermVectors(true);
+ doc.add(new Field("vectors", "a b c", withVectors));
+ writer.addDocument(doc);
+ }
+ writer.commit();
+ }
+ }
+ assertEquals(2, tempIndexOpens.size());
+ for (IOContext context : tempIndexOpens) {
+ assertTrue(context.hints().contains(ReadOnceHint.INSTANCE));
Review Comment:
Can use hamcrest for these - `assertThat(context.hints(), hasItem(...))`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]