rmuir commented on code in PR #11998:
URL: https://github.com/apache/lucene/pull/11998#discussion_r1045078398


##########
lucene/test-framework/src/java/org/apache/lucene/tests/index/AssertingLeafReader.java:
##########
@@ -113,34 +116,84 @@ public Fields getTermVectors(int docID) throws 
IOException {
     return fields == null ? null : new AssertingFields(fields);
   }
 
+  @Override
+  public TermVectors termVectors() throws IOException {
+    return new AssertingTermVectors(super.termVectors());
+  }
+
+  @Override
+  public StoredFields storedFields() throws IOException {
+    return new AssertingStoredFields(super.storedFields());
+  }
+
+  /** Wraps a StoredFields but with additional asserts */
+  public static class AssertingStoredFields extends StoredFields {
+    private final StoredFields in;
+    private final Thread creationThread = Thread.currentThread();
+
+    public AssertingStoredFields(StoredFields in) {
+      this.in = in;
+    }
+
+    @Override
+    public void document(int docID, StoredFieldVisitor visitor) throws 
IOException {
+      assertThread("StoredFields", creationThread);
+      in.document(docID, visitor);
+    }
+  }
+
+  /** Wraps a TermVectors but with additional asserts */
+  public static class AssertingTermVectors extends TermVectors {
+    private final TermVectors in;
+    private final Thread creationThread = Thread.currentThread();
+
+    public AssertingTermVectors(TermVectors in) {
+      this.in = in;
+    }
+
+    @Override
+    public Fields get(int doc) throws IOException {
+      assertThread("TermVectors", creationThread);
+      Fields fields = in.get(doc);
+      return fields == null ? null : new AssertingFields(fields);
+    }
+  }
+
   /** Wraps a Fields but with additional asserts */
   public static class AssertingFields extends FilterFields {
+    private final Thread creationThread = Thread.currentThread();

Review Comment:
   I had the idea to add these checks for stored/fields vectors just to fail a 
test clearly rather than with some "crazy" behavior that would be difficult to 
debug. 
   
   Looks like i wasn't the first person to have this idea, as @jpountz already 
added most of them 8 years ago: 
https://github.com/apache/lucene/commit/fc94b0b4d9e0
   
   For the postings API, previously we had existing checks on `TermsEnum`, 
`PostingsEnum`. But `Terms` and `Fields` were not checked. Seems like an 
oversight to me, they are all in the same codec postings api (also used by term 
vectors). So, depending on codec's implementation, codec might do e.g. any 
number of disk reads or whatever it wants and these should be checked too.



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to