use of hudson.util.RingBufferLogHandler in project support-core-plugin by jenkinsci.
the class SupportActionTest method takeSnapshotAndMakeSureSomethingHappens.
/*
* Integration test that simulates the user action of clicking the button to generate the bundle.
* <p>
* If any warning is reported to j.u.l logger, treat that as a sign of failure, because
* support-core plugin works darn hard to try to generate something in the presence of failing
* {@link Component} impls.
*/
@Test
public void takeSnapshotAndMakeSureSomethingHappens() throws Exception {
j.createSlave("agent1", "test", null).getComputer().connect(false).get();
j.createSlave("agent2", "test", null).getComputer().connect(false).get();
RingBufferLogHandler checker = new RingBufferLogHandler();
Logger logger = Logger.getLogger(SupportPlugin.class.getPackage().getName());
logger.addHandler(checker);
try {
WebClient wc = j.createWebClient();
HtmlPage p = wc.goTo(root.getUrlName());
HtmlForm form = p.getFormByName("bundle-contents");
HtmlButton submit = (HtmlButton) form.getElementsByTagName("button").get(0);
Page zip = submit.click();
File zipFile = File.createTempFile("test", "zip");
IOUtils.copy(zip.getWebResponse().getContentAsStream(), Files.newOutputStream(zipFile.toPath()));
ZipFile z = new ZipFile(zipFile);
// check the presence of files
// TODO: emit some log entries and see if it gets captured here
assertNotNull(z.getEntry("about.md"));
assertNotNull(z.getEntry("nodes.md"));
assertNotNull(z.getEntry("nodes/master/thread-dump.txt"));
if (SystemPlatform.LINUX == SystemPlatform.current()) {
List<String> files = Arrays.asList("proc/swaps.txt", "proc/cpuinfo.txt", "proc/mounts.txt", "proc/system-uptime.txt", "proc/net/rpc/nfs.txt", "proc/net/rpc/nfsd.txt", "proc/meminfo.txt", "proc/self/status.txt", "proc/self/cmdline", "proc/self/environ", "proc/self/limits.txt", "proc/self/mountstats.txt", "sysctl.txt", "dmesg.txt", "userid.txt", "dmi.txt");
for (String file : files) {
assertNotNull(file + " was not found in the bundle", z.getEntry("nodes/master/" + file));
}
}
} finally {
logger.removeHandler(checker);
for (LogRecord r : checker.getView()) {
if (r.getLevel().intValue() >= Level.WARNING.intValue()) {
Throwable thrown = r.getThrown();
if (thrown != null)
thrown.printStackTrace(System.err);
fail(r.getMessage());
}
}
}
}
use of hudson.util.RingBufferLogHandler in project support-core-plugin by jenkinsci.
the class SupportTestUtils method generateBundleWithoutWarnings.
/**
* Generate a support bundle via HTTPS using the action passed in.
*
* <p>
* If any warning is reported to j.u.l logger, treat that as a sign of failure, because
* support-core plugin works darn hard to try to generate something in the presence of failing
* {@link Component} implementations.
*
* @param baseUrl the base url of the action. "" for root actions.
* @param action the {@link Action}
* @param loggerClass the class package to inspect loggers from
* @param webClient a {@link org.jvnet.hudson.test.JenkinsRule.WebClient}
* @return the {@link ZipFile} generated
*/
public static ZipFile generateBundleWithoutWarnings(String baseUrl, Action action, Class<?> loggerClass, JenkinsRule.WebClient webClient) throws Exception {
RingBufferLogHandler checker = new RingBufferLogHandler(256);
Logger logger = Logger.getLogger(loggerClass.getPackage().getName());
logger.addHandler(checker);
try {
return SupportTestUtils.generateBundleFromAction(baseUrl, action, webClient);
} finally {
logger.removeHandler(checker);
for (LogRecord r : checker.getView()) {
if (r.getLevel().intValue() >= Level.WARNING.intValue()) {
Throwable thrown = r.getThrown();
if (thrown != null)
thrown.printStackTrace(System.err);
fail(r.getMessage());
}
}
}
}
Aggregations