Fix FSHealthServiceTests on Windows (#59387)
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
This commit is contained in:
parent
19ba6c39d2
commit
3fb9dccc22
|
@ -17,16 +17,13 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.elasticsearch.monitor.fs;
|
package org.elasticsearch.monitor.fs;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.lucene.mockfile.FilterFileChannel;
|
import org.apache.lucene.mockfile.FilterFileChannel;
|
||||||
import org.apache.lucene.mockfile.FilterFileSystemProvider;
|
import org.apache.lucene.mockfile.FilterFileSystemProvider;
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.elasticsearch.cluster.coordination.DeterministicTaskQueue;
|
import org.elasticsearch.cluster.coordination.DeterministicTaskQueue;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
import org.elasticsearch.common.io.PathUtilsForTesting;
|
import org.elasticsearch.common.io.PathUtilsForTesting;
|
||||||
|
@ -58,7 +55,6 @@ import static org.elasticsearch.monitor.StatusInfo.Status.UNHEALTHY;
|
||||||
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
|
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
|
|
||||||
public class FsHealthServiceTests extends ESTestCase {
|
public class FsHealthServiceTests extends ESTestCase {
|
||||||
|
|
||||||
private DeterministicTaskQueue deterministicTaskQueue;
|
private DeterministicTaskQueue deterministicTaskQueue;
|
||||||
|
@ -100,8 +96,6 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailsHealthOnIOException() throws IOException {
|
public void testFailsHealthOnIOException() throws IOException {
|
||||||
assumeFalse("https://github.com/elastic/elasticsearch/issues/59380", Constants.WINDOWS);
|
|
||||||
|
|
||||||
FileSystem fileSystem = PathUtils.getDefaultFileSystem();
|
FileSystem fileSystem = PathUtils.getDefaultFileSystem();
|
||||||
FileSystemIOExceptionProvider disruptFileSystemProvider = new FileSystemIOExceptionProvider(fileSystem);
|
FileSystemIOExceptionProvider disruptFileSystemProvider = new FileSystemIOExceptionProvider(fileSystem);
|
||||||
fileSystem = disruptFileSystemProvider.getFileSystem(null);
|
fileSystem = disruptFileSystemProvider.getFileSystem(null);
|
||||||
|
@ -116,6 +110,7 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
assertEquals("health check passed", fsHealthService.getHealth().getInfo());
|
assertEquals("health check passed", fsHealthService.getHealth().getInfo());
|
||||||
|
|
||||||
//disrupt file system
|
//disrupt file system
|
||||||
|
disruptFileSystemProvider.restrictPathPrefix(""); // disrupt all paths
|
||||||
disruptFileSystemProvider.injectIOException.set(true);
|
disruptFileSystemProvider.injectIOException.set(true);
|
||||||
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
|
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
|
||||||
fsHealthService.new FsHealthMonitor().run();
|
fsHealthService.new FsHealthMonitor().run();
|
||||||
|
@ -221,9 +216,9 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
assertEquals("health check passed", fsHealthService.getHealth().getInfo());
|
assertEquals("health check passed", fsHealthService.getHealth().getInfo());
|
||||||
|
|
||||||
//disrupt file system writes on single path
|
//disrupt file system writes on single path
|
||||||
disruptWritesFileSystemProvider.injectIOException.set(true);
|
|
||||||
String disruptedPath = randomFrom(paths).toString();
|
String disruptedPath = randomFrom(paths).toString();
|
||||||
disruptWritesFileSystemProvider.restrictPathPrefix(disruptedPath);
|
disruptWritesFileSystemProvider.restrictPathPrefix(disruptedPath);
|
||||||
|
disruptWritesFileSystemProvider.injectIOException.set(true);
|
||||||
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
|
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
|
||||||
fsHealthService.new FsHealthMonitor().run();
|
fsHealthService.new FsHealthMonitor().run();
|
||||||
assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus());
|
assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus());
|
||||||
|
@ -241,7 +236,7 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
AtomicBoolean injectIOException = new AtomicBoolean();
|
AtomicBoolean injectIOException = new AtomicBoolean();
|
||||||
AtomicInteger injectedPaths = new AtomicInteger();
|
AtomicInteger injectedPaths = new AtomicInteger();
|
||||||
|
|
||||||
private String pathPrefix = "/";
|
private String pathPrefix;
|
||||||
|
|
||||||
FileSystemIOExceptionProvider(FileSystem inner) {
|
FileSystemIOExceptionProvider(FileSystem inner) {
|
||||||
super("disrupt_fs_health://", inner);
|
super("disrupt_fs_health://", inner);
|
||||||
|
@ -258,6 +253,7 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
@Override
|
@Override
|
||||||
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException {
|
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException {
|
||||||
if (injectIOException.get()){
|
if (injectIOException.get()){
|
||||||
|
assert pathPrefix != null : "must set pathPrefix before starting disruptions";
|
||||||
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
|
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
|
||||||
injectedPaths.incrementAndGet();
|
injectedPaths.incrementAndGet();
|
||||||
throw new IOException("fake IOException");
|
throw new IOException("fake IOException");
|
||||||
|
@ -272,7 +268,7 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
AtomicBoolean injectIOException = new AtomicBoolean();
|
AtomicBoolean injectIOException = new AtomicBoolean();
|
||||||
AtomicInteger injectedPaths = new AtomicInteger();
|
AtomicInteger injectedPaths = new AtomicInteger();
|
||||||
|
|
||||||
private String pathPrefix = "/";
|
private String pathPrefix = null;
|
||||||
|
|
||||||
FileSystemFsyncIOExceptionProvider(FileSystem inner) {
|
FileSystemFsyncIOExceptionProvider(FileSystem inner) {
|
||||||
super("disrupt_fs_health://", inner);
|
super("disrupt_fs_health://", inner);
|
||||||
|
@ -292,6 +288,7 @@ public class FsHealthServiceTests extends ESTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void force(boolean metaData) throws IOException {
|
public void force(boolean metaData) throws IOException {
|
||||||
if (injectIOException.get()) {
|
if (injectIOException.get()) {
|
||||||
|
assert pathPrefix != null : "must set pathPrefix before starting disruptions";
|
||||||
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
|
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) {
|
||||||
injectedPaths.incrementAndGet();
|
injectedPaths.incrementAndGet();
|
||||||
throw new IOException("fake IOException");
|
throw new IOException("fake IOException");
|
||||||
|
|
Loading…
Reference in New Issue