shatejas commented on code in PR #13985:
URL: https://github.com/apache/lucene/pull/13985#discussion_r1836001654


##########
lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java:
##########
@@ -1554,6 +1555,42 @@ public void testPrefetchOnSlice() throws IOException {
     doTestPrefetch(TestUtil.nextInt(random(), 1, 1024));
   }
 
+  public void testUpdateReadAdvice() throws IOException {
+    try (Directory dir = getDirectory(createTempDir("testUpdateReadAdvice"))) {
+      final int totalLength = TestUtil.nextInt(random(), 16384, 65536);
+      byte[] arr = new byte[totalLength];
+      random().nextBytes(arr);
+      try (IndexOutput out = dir.createOutput("temp.bin", IOContext.DEFAULT)) {
+        out.writeBytes(arr, arr.length);
+      }
+
+      try (IndexInput orig = dir.openInput("temp.bin", IOContext.DEFAULT)) {
+        IndexInput in = random().nextBoolean() ? orig.clone() : orig;
+        // Read advice updated at start
+        orig.updateReadAdvice(randomReadAdvice());
+        for (int i = 0; i < totalLength; i++) {
+          int offset = TestUtil.nextInt(random(), 0, (int) in.length() - 1);
+          in.seek(offset);
+          assertEquals(arr[offset], in.readByte());
+        }
+
+        // Updating readAdvice in the middle
+        for (int i = 0; i < 10_000; ++i) {
+          int offset = TestUtil.nextInt(random(), 0, (int) in.length() - 1);
+          in.seek(offset);
+          assertEquals(arr[offset], in.readByte());
+          if (random().nextBoolean()) {
+            orig.updateReadAdvice(randomReadAdvice());
+          }
+        }
+      }
+    }
+  }
+
+  private ReadAdvice randomReadAdvice() {
+    return ReadAdvice.values()[TestUtil.nextInt(random(), 0, 
ReadAdvice.values().length - 1)];

Review Comment:
   Will switch



-- 
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