Skip to content

Commit 4e1356b

Browse files
committed
Allow read advice to be overridden
1 parent 166d579 commit 4e1356b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lucene/test-framework/src/test/org/apache/lucene/tests/store/TestSerializedIOCountingDirectory.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,28 @@ public class TestSerializedIOCountingDirectory extends BaseDirectoryTestCase {
2929

3030
private record OverrideReadAdvice(ReadAdvice readAdvice) implements IOContext.FileOpenHint {}
3131

32+
private static class ReadAdviceSerialIOCountingDirectory extends SerialIOCountingDirectory {
33+
public ReadAdviceSerialIOCountingDirectory(Directory in) {
34+
super(in);
35+
}
36+
37+
@Override
38+
protected ReadAdvice toReadAdvice(IOContext context) {
39+
return context
40+
.hints(OverrideReadAdvice.class)
41+
.findAny()
42+
.map(OverrideReadAdvice::readAdvice)
43+
.orElseGet(() -> super.toReadAdvice(context));
44+
}
45+
}
46+
3247
@Override
3348
protected Directory getDirectory(Path path) throws IOException {
34-
return new SerialIOCountingDirectory(FSDirectory.open(path)) {
35-
@Override
36-
protected ReadAdvice toReadAdvice(IOContext context) {
37-
return context
38-
.hints(OverrideReadAdvice.class)
39-
.findAny()
40-
.map(OverrideReadAdvice::readAdvice)
41-
.orElseGet(() -> super.toReadAdvice(context));
42-
}
43-
};
49+
return new ReadAdviceSerialIOCountingDirectory(FSDirectory.open(path));
4450
}
4551

4652
public void testSequentialReads() throws IOException {
47-
try (SerialIOCountingDirectory dir = new SerialIOCountingDirectory(newDirectory())) {
53+
try (SerialIOCountingDirectory dir = new ReadAdviceSerialIOCountingDirectory(newDirectory())) {
4854
try (IndexOutput out = dir.createOutput("test", IOContext.DEFAULT)) {
4955
for (int i = 0; i < 10; ++i) {
5056
out.writeBytes(new byte[4096], 4096);
@@ -76,7 +82,7 @@ public void testSequentialReads() throws IOException {
7682
}
7783

7884
public void testParallelReads() throws IOException {
79-
try (SerialIOCountingDirectory dir = new SerialIOCountingDirectory(newDirectory())) {
85+
try (SerialIOCountingDirectory dir = new ReadAdviceSerialIOCountingDirectory(newDirectory())) {
8086
try (IndexOutput out = dir.createOutput("test", IOContext.DEFAULT)) {
8187
for (int i = 0; i < 10; ++i) {
8288
out.writeBytes(new byte[4096], 4096);

0 commit comments

Comments
 (0)