Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-65068] RestartableJenkinsRule: Handle NoSuchFileException thrown from FileTreeWalker #302

Merged
merged 2 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ public FileVisitResult visitFile(final Path file,
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
if (exc instanceof FileNotFoundException) {
LOGGER.log(Level.FINE, "File not found while trying to copy to new home, continuing anyway: "+file.toString());
LOGGER.log(Level.FINE, "File not found while trying to copy to new home, continuing anyway: " + file.toString());
return FileVisitResult.CONTINUE;
} else if (exc instanceof NoSuchFileException) {
LOGGER.log(Level.FINE, "File disappeared while trying to copy to new home, continuing anyway: " + file.toString());
return FileVisitResult.CONTINUE;
} else {
LOGGER.log(Level.WARNING, "Error copying file", exc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import static org.junit.Assume.assumeThat;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -23,7 +27,8 @@

public class RestartableJenkinsRuleTest {

@Rule public RestartableJenkinsRule noPortReuse = new RestartableJenkinsRule();
@Rule
public RestartableJenkinsRule noPortReuse = new RestartableJenkinsRule();

@Rule
public RestartableJenkinsRule portReuse =
Expand Down Expand Up @@ -63,14 +68,14 @@ public void pluginsCanBeDisabled() {
final String pluginId = "display-url-api";
noPortReuse.then(jr -> {
System.out.println(WarExploder.getExplodedDir());
Path srcLdap = new File(WarExploder.getExplodedDir(), "WEB-INF/detached-plugins/"+pluginId+".hpi").toPath();
Path dstLdap = new File(jr.jenkins.pluginManager.rootDir, pluginId+".jpi").toPath();
Path srcLdap = new File(WarExploder.getExplodedDir(), "WEB-INF/detached-plugins/" + pluginId + ".hpi").toPath();
Path dstLdap = new File(jr.jenkins.pluginManager.rootDir, pluginId + ".jpi").toPath();
Files.createDirectories(dstLdap.getParent());
Files.copy(srcLdap, dstLdap);
//jr.getPluginManager().doCheckUpdatesServer();
//jr.getPluginManager().install(Collections.singletonList("cvs"),true);
});

noPortReuse.then(jr -> {
Jenkins j = jr.jenkins;
PluginManager pm = j.getPluginManager();
Expand All @@ -81,9 +86,20 @@ public void pluginsCanBeDisabled() {

noPortReuse.then(jr -> {
assertFalse(pluginId + " is not enabled",
jr.jenkins.getPluginManager().getPlugin(pluginId).isEnabled());
jr.jenkins.getPluginManager().getPlugin(pluginId).isEnabled());
assertFalse(pluginId + " should not be active",
jr.jenkins.getPluginManager().getPlugin(pluginId).isActive());
jr.jenkins.getPluginManager().getPlugin(pluginId).isActive());
});
}

@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW you can use @Issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried, but too late.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np

public void verify_CopyFileVisitor_visitFileFailed_NoSuchFileException() {
Path testPath = new File("./").toPath();
RestartableJenkinsRule.CopyFileVisitor visitor = new RestartableJenkinsRule.CopyFileVisitor(testPath);

assertEquals(FileVisitResult.CONTINUE, visitor.visitFileFailed(testPath, new FileNotFoundException()));
assertEquals(FileVisitResult.CONTINUE, visitor.visitFileFailed(testPath, new NoSuchFileException("./")));
assertEquals(FileVisitResult.TERMINATE, visitor.visitFileFailed(testPath, new IOException()));
}
}