Skip to content

Commit a6d5f90

Browse files
committed
Add test
1 parent 2a51289 commit a6d5f90

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lucene/core/src/test/org/apache/lucene/store/TestMMapDirectory.java

+23
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ public void testWithNormal() throws Exception {
131131
}
132132
}
133133

134+
public void testPreload() throws Exception {
135+
final int size = 8 * 1024;
136+
byte[] bytes = new byte[size];
137+
random().nextBytes(bytes);
138+
139+
try (MMapDirectory dir = new MMapDirectory(createTempDir("testPreload"))) {
140+
dir.setPreload(MMapDirectory.PRELOAD_HINT);
141+
try (IndexOutput out =
142+
dir.createOutput("test", IOContext.DEFAULT.withHints(PreloadHint.INSTANCE))) {
143+
out.writeBytes(bytes, 0, bytes.length);
144+
}
145+
146+
try (final IndexInput in =
147+
dir.openInput("test", IOContext.DEFAULT.withHints(PreloadHint.INSTANCE))) {
148+
// the data should be loaded in memory
149+
assertTrue(in.isLoaded().orElse(false));
150+
final byte[] readBytes = new byte[size];
151+
in.readBytes(readBytes, 0, readBytes.length);
152+
assertArrayEquals(bytes, readBytes);
153+
}
154+
}
155+
}
156+
134157
// Opens the input with ReadAdvice.READONCE to ensure slice and clone are appropriately confined
135158
public void testConfined() throws Exception {
136159
final int size = 16;

0 commit comments

Comments
 (0)