Search in sources :

Example 1 with JvmOutputEvent

use of com.carrotsearch.ant.tasks.junit4.events.aggregated.JvmOutputEvent in project randomizedtesting by randomizedtesting.

the class JUnit4 method checkJvmOutput.

@SuppressForbidden("legitimate sysout.")
private void checkJvmOutput(EventBus aggregatedBus, Path file, ForkedJvmInfo forked, String fileName) throws IOException {
    if (Files.size(file) > 0) {
        String message = "JVM J" + forked.id + ": " + fileName + " was not empty, see: " + file;
        if (jvmOutputAction.contains(JvmOutputAction.WARN)) {
            log(message, Project.MSG_WARN);
        }
        if (jvmOutputAction.contains(JvmOutputAction.LISTENERS)) {
            aggregatedBus.post(new JvmOutputEvent(forked, file.toFile()));
        }
        if (jvmOutputAction.contains(JvmOutputAction.PIPE)) {
            log(">>> JVM J" + forked.id + ": " + fileName + " (verbatim) ----", Project.MSG_INFO);
            try {
                // If file > 10 mb, stream directly. Otherwise use the logger.
                if (Files.size(file) < 10 * (1024 * 1024)) {
                    // Append to logger.
                    log(new String(Files.readAllBytes(file), forked.getCharset()), Project.MSG_INFO);
                } else {
                    // Stream directly.
                    CharStreams.copy(Files.newBufferedReader(file, forked.getCharset()), System.out);
                }
            } catch (IOException e) {
                log("Couldn't pipe file " + file + ": " + e.toString(), Project.MSG_INFO);
            }
            log("<<< JVM J" + forked.id + ": EOF ----", Project.MSG_INFO);
        }
        if (jvmOutputAction.contains(JvmOutputAction.IGNORE)) {
            Files.delete(file);
        }
        if (jvmOutputAction.contains(JvmOutputAction.FAIL)) {
            throw new BuildException(message);
        }
        return;
    }
    Files.delete(file);
}
Also used : JvmOutputEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.JvmOutputEvent) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) SuppressForbidden(com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)

Aggregations

JvmOutputEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.JvmOutputEvent)1 SuppressForbidden (com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)1 IOException (java.io.IOException)1 BuildException (org.apache.tools.ant.BuildException)1