You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2022/11/13 14:35:24 UTC
[lucene] branch branch_9x updated: Improve test introduced in #11918 to also check that reported invalid position is transformed back original position by slicing code (#11926)
This is an automated email from the ASF dual-hosted git repository.
uschindler pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 0e4d82e1215 Improve test introduced in #11918 to also check that reported invalid position is transformed back original position by slicing code (#11926)
0e4d82e1215 is described below
commit 0e4d82e121536843413f04d7d6171df7a14e7bd8
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Sun Nov 13 15:34:10 2022 +0100
Improve test introduced in #11918 to also check that reported invalid position is transformed back original position by slicing code (#11926)
---
.../org/apache/lucene/store/TestMultiMMap.java | 31 +++++++++++++++++-----
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
index 9cdd6e2b54e..a0c5a29ccf8 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
@@ -16,9 +16,11 @@
*/
package org.apache.lucene.store;
+import java.io.EOFException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
+import java.util.Locale;
import org.apache.lucene.tests.store.BaseChunkedDirectoryTestCase;
import org.apache.lucene.util.BytesRef;
import org.junit.BeforeClass;
@@ -41,22 +43,39 @@ public class TestMultiMMap extends BaseChunkedDirectoryTestCase {
assertTrue(MMapDirectory.UNMAP_NOT_SUPPORTED_REASON, MMapDirectory.UNMAP_SUPPORTED);
}
- public void testSeekNegative() throws IOException {
- try (Directory dir = getDirectory(createTempDir())) {
+ public void testSeekingExceptions() throws IOException {
+ final int sliceSize = 128;
+ try (Directory dir = getDirectory(createTempDir(), sliceSize)) {
+ final int size = 128 + 63;
try (IndexOutput out = dir.createOutput("a", IOContext.DEFAULT)) {
- for (int i = 0; i < 2048; ++i) {
+ for (int i = 0; i < size; ++i) {
out.writeByte((byte) 0);
}
}
try (IndexInput in = dir.openInput("a", IOContext.DEFAULT)) {
- in.seek(1234);
- assertEquals(1234, in.getFilePointer());
+ final long negativePos = -1234;
var e =
expectThrowsAnyOf(
List.of(IllegalArgumentException.class, AssertionError.class),
- () -> in.seek(-1234));
+ () -> in.seek(negativePos));
assertTrue(
"does not mention negative position", e.getMessage().contains("negative position"));
+
+ final long posAfterEOF = size + 123;
+ var eof = expectThrows(EOFException.class, () -> in.seek(posAfterEOF));
+ assertTrue(
+ "wrong position in error message: " + eof,
+ eof.getMessage().contains(String.format(Locale.ROOT, "(pos=%d)", posAfterEOF)));
+
+ // this test verifies that the invalid position is transformed back to original one for
+ // exception by slicing:
+ IndexInput slice = in.slice("slice", 33, sliceSize + 15);
+ // ensure that the slice uses multi-mmap:
+ assertCorrectImpl(false, slice);
+ eof = expectThrows(EOFException.class, () -> slice.seek(posAfterEOF));
+ assertTrue(
+ "wrong position in error message: " + eof,
+ eof.getMessage().contains(String.format(Locale.ROOT, "(pos=%d)", posAfterEOF)));
}
}
}