"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/test/java/jenkins/util/io/PathRemoverTest.java" between
jenkins-jenkins-2.302.tar.gz and jenkins-jenkins-2.303.tar.gz

About: Jenkins is a automation server (written in Java) which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software (for e.g. as Continuous Integration and Continuous Delivery server). Weekly release.

PathRemoverTest.java  (jenkins-jenkins-2.302):PathRemoverTest.java  (jenkins-jenkins-2.303)
skipping to change at line 64 skipping to change at line 64
import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class PathRemoverTest { public class PathRemoverTest {
@Rule public TemporaryFolder tmp = new TemporaryFolder(); @Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule public Timeout timeout = new Timeout(10, TimeUnit.SECONDS); @Rule public Timeout timeout = new Timeout(10, TimeUnit.SECONDS);
@Rule public FileLockerRule locker = new FileLockerRule(); @Rule public FileLockerRule locker = new FileLockerRule();
skipping to change at line 107 skipping to change at line 106
given(path.toString()).willReturn(filename); given(path.toString()).willReturn(filename);
given(path.toFile()).willReturn(file); given(path.toFile()).willReturn(file);
given(path.getFileSystem()).willReturn(fs); given(path.getFileSystem()).willReturn(fs);
given(path.normalize()).willReturn(path); given(path.normalize()).willReturn(path);
given(fs.provider()).willReturn(fsProvider); given(fs.provider()).willReturn(fsProvider);
given(fsProvider.deleteIfExists(path)).willThrow(new FileSystemException (filename)); given(fsProvider.deleteIfExists(path)).willThrow(new FileSystemException (filename));
given(fsProvider.readAttributes(path, BasicFileAttributes.class)).willRe turn(attributes); given(fsProvider.readAttributes(path, BasicFileAttributes.class)).willRe turn(attributes);
given(attributes.isDirectory()).willReturn(false); given(attributes.isDirectory()).willReturn(false);
PathRemover remover = PathRemover.newSimpleRemover(); PathRemover remover = PathRemover.newSimpleRemover();
try { final IOException e = assertThrows(IOException.class, () -> remover.forc
remover.forceRemoveFile(file.toPath()); eRemoveFile(file.toPath()));
fail("Should not have been deleted: " + file); assertThat(calcExceptionHierarchy(e), hasItem(FileSystemException.class)
} catch (IOException e) { );
assertThat(calcExceptionHierarchy(e), hasItem(FileSystemException.cl assertThat(e.getMessage(), containsString(filename));
ass));
assertThat(e.getMessage(), containsString(filename));
}
} }
private static List<Class<?>> calcExceptionHierarchy(Throwable t) { private static List<Class<?>> calcExceptionHierarchy(Throwable t) {
List<Class<?>> hierarchy = new ArrayList<>(); List<Class<?>> hierarchy = new ArrayList<>();
for (; t != null; t = t.getCause()) { for (; t != null; t = t.getCause()) {
hierarchy.add(t.getClass()); hierarchy.add(t.getClass());
// with a composite exception, we might be hiding some other causes // with a composite exception, we might be hiding some other causes
if (t instanceof CompositeIOException) { if (t instanceof CompositeIOException) {
CompositeIOException e = (CompositeIOException) t; CompositeIOException e = (CompositeIOException) t;
e.getExceptions().forEach(ex -> hierarchy.addAll(calcExceptionHi erarchy(ex))); e.getExceptions().forEach(ex -> hierarchy.addAll(calcExceptionHi erarchy(ex)));
skipping to change at line 440 skipping to change at line 434
final int totalFiles = lockedFiles + 5; final int totalFiles = lockedFiles + 5;
File dir = tmp.newFolder(); File dir = tmp.newFolder();
File[] files = new File[totalFiles]; File[] files = new File[totalFiles];
for (int i = 0; i < totalFiles; i++) { for (int i = 0; i < totalFiles; i++) {
files[i] = new File(dir, "f" + i); files[i] = new File(dir, "f" + i);
} }
touchWithFileName(files); touchWithFileName(files);
for (int i = 0; i < lockedFiles; i++) { for (int i = 0; i < lockedFiles; i++) {
locker.acquireLock(files[i]); locker.acquireLock(files[i]);
} }
try {
PathRemover.newSimpleRemover().forceRemoveRecursive(dir.toPath()); final CompositeIOException e = assertThrows(CompositeIOException.class,
fail("Deletion should have failed"); () -> PathRemover.newSimpleRemover().forceRemoveRecursive(dir.to
} catch (CompositeIOException e) { Path()));
assertThat(e.getSuppressed(), arrayWithSize(maxExceptions)); assertThat(e.getSuppressed(), arrayWithSize(maxExceptions));
assertThat(e.getMessage(), endsWith("(Discarded " + (lockedFiles + 1 assertThat(e.getMessage(), endsWith("(Discarded " + (lockedFiles + 1 - m
- maxExceptions) + " additional exceptions)")); axExceptions) + " additional exceptions)"));
}
assertTrue(dir.exists()); assertTrue(dir.exists());
assertThat(dir.listFiles().length, equalTo(lockedFiles)); assertThat(dir.listFiles().length, equalTo(lockedFiles));
} }
private static void mkdirs(File... dirs) { private static void mkdirs(File... dirs) {
for (File dir : dirs) { for (File dir : dirs) {
assertTrue("Could not mkdir " + dir, dir.mkdir()); assertTrue("Could not mkdir " + dir, dir.mkdir());
assertTrue(dir.isDirectory()); assertTrue(dir.isDirectory());
} }
} }
 End of changes. 3 change blocks. 
18 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)