List of usage examples for org.apache.lucene.mockfile FilterPath FilterPath
public FilterPath(Path delegate, FileSystem fileSystem)
From source file:org.elasticsearch.core.internal.io.IOUtilsTests.java
License:Apache License
public void runTestRm(final boolean exception) throws IOException { final int numberOfLocations = randomIntBetween(0, 7); final Path[] locations = new Path[numberOfLocations]; final List<Path> locationsThrowingException = new ArrayList<>(numberOfLocations); for (int i = 0; i < numberOfLocations; i++) { if (exception && randomBoolean()) { final Path location = createTempDir(); final FileSystem fs = new AccessDeniedWhileDeletingFileSystem(location.getFileSystem()) .getFileSystem(URI.create("file:///")); final Path wrapped = new FilterPath(location, fs); locations[i] = wrapped.resolve(randomAlphaOfLength(8)); Files.createDirectory(locations[i]); locationsThrowingException.add(locations[i]); } else {//from w w w. j a va 2s. co m // we create a tree of files that IOUtils#rm should delete locations[i] = createTempDir(); Path location = locations[i]; while (true) { location = Files.createDirectory(location.resolve(randomAlphaOfLength(8))); if (rarely() == false) { Files.createTempFile(location, randomAlphaOfLength(8), null); break; } } } } if (locationsThrowingException.isEmpty()) { IOUtils.rm(locations); } else { final IOException e = expectThrows(IOException.class, () -> IOUtils.rm(locations)); assertThat(e, hasToString( containsString("could not remove the following files (in the order of attempts):"))); for (final Path locationThrowingException : locationsThrowingException) { assertThat(e, hasToString(containsString( "access denied while trying to delete file [" + locationThrowingException + "]"))); } } for (int i = 0; i < numberOfLocations; i++) { if (locationsThrowingException.contains(locations[i]) == false) { assertFalse(locations[i].toString(), Files.exists(locations[i])); } } }