diff --git a/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java b/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java index 14bda6f4f445c..04efdfdab808e 100644 --- a/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java +++ b/server/src/test/java/org/elasticsearch/monitor/fs/FsHealthServiceTests.java @@ -17,16 +17,13 @@ * under the License. */ - package org.elasticsearch.monitor.fs; - import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.mockfile.FilterFileChannel; import org.apache.lucene.mockfile.FilterFileSystemProvider; -import org.apache.lucene.util.Constants; import org.elasticsearch.cluster.coordination.DeterministicTaskQueue; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtilsForTesting; @@ -58,7 +55,6 @@ import static org.elasticsearch.node.Node.NODE_NAME_SETTING; import static org.hamcrest.Matchers.is; - public class FsHealthServiceTests extends ESTestCase { private DeterministicTaskQueue deterministicTaskQueue; @@ -100,8 +96,6 @@ public void testSchedulesHealthCheckAtRefreshIntervals() throws Exception { } public void testFailsHealthOnIOException() throws IOException { - assumeFalse("https://github.com/elastic/elasticsearch/issues/59380", Constants.WINDOWS); - FileSystem fileSystem = PathUtils.getDefaultFileSystem(); FileSystemIOExceptionProvider disruptFileSystemProvider = new FileSystemIOExceptionProvider(fileSystem); fileSystem = disruptFileSystemProvider.getFileSystem(null); @@ -116,6 +110,7 @@ public void testFailsHealthOnIOException() throws IOException { assertEquals("health check passed", fsHealthService.getHealth().getInfo()); //disrupt file system + disruptFileSystemProvider.restrictPathPrefix(""); // disrupt all paths disruptFileSystemProvider.injectIOException.set(true); fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env); fsHealthService.new FsHealthMonitor().run(); @@ -221,9 +216,9 @@ public void testFailsHealthOnSinglePathWriteFailure() throws IOException { assertEquals("health check passed", fsHealthService.getHealth().getInfo()); //disrupt file system writes on single path - disruptWritesFileSystemProvider.injectIOException.set(true); String disruptedPath = randomFrom(paths).toString(); disruptWritesFileSystemProvider.restrictPathPrefix(disruptedPath); + disruptWritesFileSystemProvider.injectIOException.set(true); fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env); fsHealthService.new FsHealthMonitor().run(); assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus()); @@ -241,7 +236,7 @@ private static class FileSystemIOExceptionProvider extends FilterFileSystemProvi AtomicBoolean injectIOException = new AtomicBoolean(); AtomicInteger injectedPaths = new AtomicInteger(); - private String pathPrefix = "/"; + private String pathPrefix; FileSystemIOExceptionProvider(FileSystem inner) { super("disrupt_fs_health://", inner); @@ -258,6 +253,7 @@ public int getInjectedPathCount(){ @Override public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException { if (injectIOException.get()){ + assert pathPrefix != null : "must set pathPrefix before starting disruptions"; if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) { injectedPaths.incrementAndGet(); throw new IOException("fake IOException"); @@ -272,7 +268,7 @@ private static class FileSystemFsyncIOExceptionProvider extends FilterFileSystem AtomicBoolean injectIOException = new AtomicBoolean(); AtomicInteger injectedPaths = new AtomicInteger(); - private String pathPrefix = "/"; + private String pathPrefix = null; FileSystemFsyncIOExceptionProvider(FileSystem inner) { super("disrupt_fs_health://", inner); @@ -292,6 +288,7 @@ public FileChannel newFileChannel(Path path, Set options, @Override public void force(boolean metaData) throws IOException { if (injectIOException.get()) { + assert pathPrefix != null : "must set pathPrefix before starting disruptions"; if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) { injectedPaths.incrementAndGet(); throw new IOException("fake IOException");