Class SlaveMain


  • public class SlaveMain
    extends java.lang.Object
    A slave process running the actual tests on the target JVM.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  SlaveMain.ChunkedStream
      Base for redirected streams.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File debugMessagesFile
      Debug stream to flush progress information to.
      static int ERR_EXCEPTION
      Runtime exception.
      static int ERR_NO_JUNIT
      No JUnit on classpath.
      static int ERR_OLD_JUNIT
      Old JUnit on classpath.
      static int ERR_OOM
      OOM
      private boolean flushFrequently
      Flush serialization stream frequently.
      (package private) static java.lang.Object lastResortMemory
      Last resort memory pool released under low memory conditions.
      private static boolean multiplexStdStreams
      Multiplex calls to System streams to both event stream and the original streams?
      (package private) static java.lang.Class<java.lang.OutOfMemoryError> oomClass
      Preallocate and load in advance.
      static java.lang.String OPTION_DEBUGSTREAM
      Should the debug stream from the runner be created? It's named after the events file with .debug suffix.
      static java.lang.String OPTION_EVENTSFILE
      Name the sink for events.
      static java.lang.String OPTION_FREQUENT_FLUSH
      Frequent event strean flushing.
      static java.lang.String OPTION_STDIN
      Read class names from standard input.
      static java.lang.String OPTION_SYSOUTS
      Multiplex sysout and syserr to original streams (aside from pumping them to event stream).
      private Serializer serializer
      Event sink.
      static java.lang.String SYSPROP_FIRERUNNERFAILURE
      Fire a runner failure after startup to verify messages are propagated properly.
      static java.lang.String SYSPROP_FORKEDJVM_DELAY_MS
      Delay the initial bootstrap event from the forked JVM (used in tests).
      private static java.io.PrintStream warnings
      A sink for warnings (non-event stream).
    • Constructor Summary

      Constructors 
      Constructor Description
      SlaveMain​(Serializer serializer)
      Creates a slave emitting events to the given serializer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void debug​(java.io.Writer w, java.lang.String msg)  
      private void execute​(java.util.Iterator<java.lang.String> classNames)
      Execute tests.
      private java.lang.Class<?> instantiate​(java.lang.String className)
      Instantiate test classes (or try to).
      static void main​(java.lang.String[] allArgs)
      Console entry point.
      private static java.lang.String[] readArgsFile​(java.lang.String argsFile)
      Read arguments from a file.
      private static void redirectStreams​(Serializer serializer, boolean flushFrequently)
      Redirect standard streams so that the output can be passed to listeners.
      private static void tryWaitingForGC()
      Try waiting for a GC to happen.
      static void warn​(java.lang.String message, java.lang.Throwable t)
      Warning emitter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ERR_EXCEPTION

        public static final int ERR_EXCEPTION
        Runtime exception.
        See Also:
        Constant Field Values
      • ERR_NO_JUNIT

        public static final int ERR_NO_JUNIT
        No JUnit on classpath.
        See Also:
        Constant Field Values
      • ERR_OLD_JUNIT

        public static final int ERR_OLD_JUNIT
        Old JUnit on classpath.
        See Also:
        Constant Field Values
      • lastResortMemory

        static volatile java.lang.Object lastResortMemory
        Last resort memory pool released under low memory conditions. This is not a solution, it's a terrible hack. I know this. Everyone knows this. Even monkeys in Madagaskar know this. If you know a better solution, patches welcome.

        Approximately 5mb is reserved. Really, smaller values don't make any difference and the JVM fails to even return the status passed to Runtime.halt().

      • oomClass

        static java.lang.Class<java.lang.OutOfMemoryError> oomClass
        Preallocate and load in advance.
      • OPTION_FREQUENT_FLUSH

        public static final java.lang.String OPTION_FREQUENT_FLUSH
        Frequent event strean flushing.
        See Also:
        Constant Field Values
      • OPTION_SYSOUTS

        public static final java.lang.String OPTION_SYSOUTS
        Multiplex sysout and syserr to original streams (aside from pumping them to event stream).
        See Also:
        Constant Field Values
      • OPTION_STDIN

        public static final java.lang.String OPTION_STDIN
        Read class names from standard input.
        See Also:
        Constant Field Values
      • OPTION_EVENTSFILE

        public static final java.lang.String OPTION_EVENTSFILE
        Name the sink for events. If given, accepts one argument - name of a file to which events should be dumped. The file has to be initially empty!
        See Also:
        Constant Field Values
      • OPTION_DEBUGSTREAM

        public static final java.lang.String OPTION_DEBUGSTREAM
        Should the debug stream from the runner be created? It's named after the events file with .debug suffix.
        See Also:
        Constant Field Values
      • SYSPROP_FIRERUNNERFAILURE

        public static final java.lang.String SYSPROP_FIRERUNNERFAILURE
        Fire a runner failure after startup to verify messages are propagated properly. Not really useful in practice...
      • SYSPROP_FORKEDJVM_DELAY_MS

        public static final java.lang.String SYSPROP_FORKEDJVM_DELAY_MS
        Delay the initial bootstrap event from the forked JVM (used in tests).
        See Also:
        Constant Field Values
      • serializer

        private final Serializer serializer
        Event sink.
      • warnings

        private static java.io.PrintStream warnings
        A sink for warnings (non-event stream).
      • flushFrequently

        private boolean flushFrequently
        Flush serialization stream frequently.
      • debugMessagesFile

        private java.io.File debugMessagesFile
        Debug stream to flush progress information to.
      • multiplexStdStreams

        private static boolean multiplexStdStreams
        Multiplex calls to System streams to both event stream and the original streams?
    • Constructor Detail

      • SlaveMain

        public SlaveMain​(Serializer serializer)
        Creates a slave emitting events to the given serializer.
    • Method Detail

      • execute

        private void execute​(java.util.Iterator<java.lang.String> classNames)
                      throws java.lang.Throwable
        Execute tests.
        Throws:
        java.lang.Throwable
      • debug

        private void debug​(java.io.Writer w,
                           java.lang.String msg)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • instantiate

        private java.lang.Class<?> instantiate​(java.lang.String className)
        Instantiate test classes (or try to).
      • main

        public static void main​(java.lang.String[] allArgs)
        Console entry point.
      • tryWaitingForGC

        private static void tryWaitingForGC()
        Try waiting for a GC to happen. This is a dirty heuristic but if we're here we're neck deep in sh*t anyway (OOMs all over).
      • readArgsFile

        private static java.lang.String[] readArgsFile​(java.lang.String argsFile)
                                                throws java.io.IOException
        Read arguments from a file. Newline delimited, UTF-8 encoded. No fanciness to avoid dependencies.
        Throws:
        java.io.IOException
      • redirectStreams

        private static void redirectStreams​(Serializer serializer,
                                            boolean flushFrequently)
        Redirect standard streams so that the output can be passed to listeners.
      • warn

        public static void warn​(java.lang.String message,
                                java.lang.Throwable t)
        Warning emitter. Uses whatever alternative non-event communication channel is.