Skip to content

Commit

Permalink
Fix FSHealthServiceTests on Windows (#59387)
Browse files Browse the repository at this point in the history
In #52680 we introduced a new health check mechanism. This commit fixes
up some related test failures on Windows caused by erroneously assuming
that all paths begin with `/`.

Closes #59380
  • Loading branch information
DaveCTurner committed Jul 13, 2020
1 parent 3cb9105 commit e63f2f8
Showing 1 changed file with 6 additions and 9 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -292,6 +288,7 @@ public FileChannel newFileChannel(Path path, Set<? extends OpenOption> 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");
Expand Down

0 comments on commit e63f2f8

Please sign in to comment.