|
10 | 10 | package org.elasticsearch.index.store; |
11 | 11 |
|
12 | 12 | import org.apache.logging.log4j.Level; |
| 13 | +import org.apache.lucene.misc.store.DirectIODirectory; |
| 14 | +import org.apache.lucene.store.Directory; |
| 15 | +import org.apache.lucene.store.FSDirectory; |
| 16 | +import org.apache.lucene.store.IOContext; |
| 17 | +import org.apache.lucene.store.IndexOutput; |
13 | 18 | import org.apache.lucene.tests.util.LuceneTestCase; |
14 | 19 | import org.elasticsearch.common.settings.Settings; |
15 | 20 | import org.elasticsearch.plugins.Plugin; |
|
19 | 24 | import org.elasticsearch.test.InternalSettingsPlugin; |
20 | 25 | import org.elasticsearch.test.MockLog; |
21 | 26 | import org.elasticsearch.test.junit.annotations.TestLogging; |
| 27 | +import org.junit.BeforeClass; |
22 | 28 |
|
| 29 | +import java.io.IOException; |
| 30 | +import java.nio.file.Path; |
23 | 31 | import java.util.Collection; |
24 | 32 | import java.util.List; |
| 33 | +import java.util.OptionalLong; |
25 | 34 | import java.util.stream.IntStream; |
26 | 35 |
|
27 | 36 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
|
30 | 39 | @LuceneTestCase.SuppressCodecs("*") // only use our own codecs |
31 | 40 | public class DirectIOIT extends ESIntegTestCase { |
32 | 41 |
|
| 42 | + @BeforeClass |
| 43 | + public static void checkSupported() throws IOException { |
| 44 | + Path path = createTempDir("directIOProbe"); |
| 45 | + try (Directory dir = open(path); IndexOutput out = dir.createOutput("out", IOContext.DEFAULT)) { |
| 46 | + out.writeString("test"); |
| 47 | + } catch (IOException e) { |
| 48 | + assumeNoException("test requires filesystem that supports Direct IO", e); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + static DirectIODirectory open(Path path) throws IOException { |
| 53 | + return new DirectIODirectory(FSDirectory.open(path)) { |
| 54 | + @Override |
| 55 | + protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) { |
| 56 | + return true; |
| 57 | + } |
| 58 | + }; |
| 59 | + } |
| 60 | + |
33 | 61 | @Override |
34 | 62 | protected Collection<Class<? extends Plugin>> nodePlugins() { |
35 | 63 | return List.of(InternalSettingsPlugin.class); |
|
0 commit comments