@Override public void run() { try { if ( pingMechanism.pluginProcessChecker.canUse() && !pingMechanism.pluginProcessChecker.isProcessAlive() && !pingMechanism.pingScheduler.isShutdown() ) { DumpErrorSingleton.getSingleton() .dumpText( "Killing self fork JVM. Maven process died." ); kill(); } } catch ( RuntimeException e ) { DumpErrorSingleton.getSingleton() .dumpException( e, "System.exit() or native command error interrupted process checker." ); } } };
public synchronized void init( File reportsDir, String dumpFileName ) { dumpFile = createDumpFile( reportsDir, dumpFileName ); dumpStreamFile = createDumpStreamFile( reportsDir, dumpFileName ); }
private void encodeAndWriteToTarget( String string ) { byte[] encodeBytes = encodeStringForForkCommunication( string ); synchronized ( target ) // See notes about synchronization/thread safety in class javadoc { target.write( encodeBytes, 0, encodeBytes.length ); target.flush(); if ( target.checkError() ) { // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up: // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception DumpErrorSingleton.getSingleton().dumpStreamText( "Unexpected IOException: " + string ); } } }
@Override public void run() { if ( !canUseNewPingMechanism( pluginProcessChecker ) ) { boolean hasPing = pingDone.getAndSet( false ); if ( !hasPing ) { DumpErrorSingleton.getSingleton() .dumpText( "Killing self fork JVM. PING timeout elapsed." ); kill(); } } } };
public boolean awaitStarted() throws TestSetFailedException { if ( state.get() == RUNNABLE ) { try { startMonitor.await(); return true; } catch ( InterruptedException e ) { DumpErrorSingleton.getSingleton().dumpException( e ); throw new TestSetFailedException( e.getLocalizedMessage() ); } } else { return false; } }
DumpErrorSingleton.getSingleton().dumpStreamText( errorMessage ); logger.error( errorMessage ); break; + "initializing exit by non-null configuration: " + CommandReader.this.shutdown; DumpErrorSingleton.getSingleton().dumpStreamException( e, msg ); DumpErrorSingleton.getSingleton().dumpStreamException( e, msg ); logger.error( msg, e );
private void setupBooter( String tmpDir, String dumpFileName, String surefirePropsFileName, String effectiveSystemPropertiesFileName ) throws IOException { BooterDeserializer booterDeserializer = new BooterDeserializer( createSurefirePropertiesIfFileExists( tmpDir, surefirePropsFileName ) ); // todo: print PID in debug console logger in version 2.21.2 pingScheduler = isDebugging() ? null : listenToShutdownCommands( booterDeserializer.getPluginPid() ); setSystemProperties( new File( tmpDir, effectiveSystemPropertiesFileName ) ); providerConfiguration = booterDeserializer.deserialize(); DumpErrorSingleton.getSingleton() .init( providerConfiguration.getReporterConfiguration().getReportsDirectory(), dumpFileName ); startupConfiguration = booterDeserializer.getProviderConfiguration(); systemExitTimeoutInSeconds = providerConfiguration.systemExitTimeout( DEFAULT_SYSTEM_EXIT_TIMEOUT_IN_SECONDS ); AbstractPathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); if ( classpathConfiguration.isClassPathConfig() ) { if ( startupConfiguration.isManifestOnlyJarRequestedAndUsable() ) { classpathConfiguration.toRealPath( ClasspathConfiguration.class ) .trickClassPathWhenManifestOnlyClasspath(); } startupConfiguration.writeSurefireTestClasspathProperty(); } ClassLoader classLoader = currentThread().getContextClassLoader(); classLoader.setDefaultAssertionStatus( classpathConfiguration.isEnableAssertions() ); boolean readTestsFromCommandReader = providerConfiguration.isReadTestsFromInStream(); testSet = createTestSet( providerConfiguration.getTestForFork(), readTestsFromCommandReader, classLoader ); }
public boolean awaitStarted() throws TestSetFailedException { if ( state.get() == RUNNABLE ) { try { startMonitor.await(); return true; } catch ( InterruptedException e ) { DumpErrorSingleton.getSingleton().dumpException( e ); throw new TestSetFailedException( e.getLocalizedMessage() ); } } else { return false; } }
DumpErrorSingleton.getSingleton().dumpStreamText( errorMessage ); logger.error( errorMessage ); break; + "initializing exit by non-null configuration: " + CommandReader.this.shutdown; DumpErrorSingleton.getSingleton().dumpStreamException( e, msg ); DumpErrorSingleton.getSingleton().dumpStreamException( e, msg ); logger.error( msg, e );
@Override public void update( Command command ) { Shutdown shutdown = command.toShutdownData(); if ( shutdown.isKill() ) { DumpErrorSingleton.getSingleton() .dumpText( "Killing self fork JVM. Received SHUTDOWN command from Maven shutdown hook." ); kill(); } else if ( shutdown.isExit() ) { cancelPingScheduler(); DumpErrorSingleton.getSingleton() .dumpText( "Exiting self fork JVM. Received SHUTDOWN command from Maven shutdown hook." ); exit( 1 ); } // else refers to shutdown=testset, but not used now, keeping reader open } };
DumpErrorSingleton.getSingleton() .dumpException( e );
private void encodeAndWriteToTarget( String string ) { byte[] encodeBytes = encodeStringForForkCommunication( string ); synchronized ( target ) // See notes about synchronization/thread safety in class javadoc { target.write( encodeBytes, 0, encodeBytes.length ); target.flush(); if ( target.checkError() ) { // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up: // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception DumpErrorSingleton.getSingleton().dumpStreamText( "Unexpected IOException: " + string ); } } }
public synchronized void init( File reportsDir, String dumpFileName ) { dumpFile = createDumpFile( reportsDir, dumpFileName ); dumpStreamFile = createDumpStreamFile( reportsDir, dumpFileName ); }
private void execute() { try { runSuitesInProcess(); } catch ( InvocationTargetException t ) { DumpErrorSingleton.getSingleton().dumpException( t ); StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter( "test subsystem", "no method", t.getTargetException() ); StringBuilder stringBuilder = new StringBuilder(); encode( stringBuilder, stackTraceWriter, false ); encodeAndWriteToOutput( ( (char) BOOTERCODE_ERROR ) + ",0," + stringBuilder + "\n" ); } catch ( Throwable t ) { DumpErrorSingleton.getSingleton().dumpException( t ); StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter( "test subsystem", "no method", t ); StringBuilder stringBuilder = new StringBuilder(); encode( stringBuilder, stackTraceWriter, false ); encodeAndWriteToOutput( ( (char) BOOTERCODE_ERROR ) + ",0," + stringBuilder + "\n" ); } acknowledgedExit(); }
@Override public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) { EncodedArray encodedArray = escapeBytesToPrintable( stdout ? stdOutHeader : stdErrHeader, buf, off, len ); synchronized ( target ) // See notes about synchronization/thread safety in class javadoc { target.write( encodedArray.getArray(), 0, encodedArray.getSize() ); target.flush(); if ( target.checkError() ) { // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up: // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception DumpErrorSingleton.getSingleton() .dumpStreamText( "Unexpected IOException with stream: " + new String( buf, off, len ) ); } } }
/** * This method is invoked when Surefire is forked - this method parses and organizes the arguments passed to it and * then calls the Surefire class' run method. <br> The system exit code will be 1 if an exception is thrown. * * @param args Commandline arguments */ public static void main( String... args ) { ForkedBooter booter = new ForkedBooter(); try { booter.setupBooter( args[0], args[1], args[2], args.length > 3 ? args[3] : null ); booter.execute(); } catch ( Throwable t ) { DumpErrorSingleton.getSingleton().dumpException( t ); t.printStackTrace(); booter.cancelPingScheduler(); booter.exit( 1 ); } }
@Override public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) { EncodedArray encodedArray = escapeBytesToPrintable( stdout ? stdOutHeader : stdErrHeader, buf, off, len ); synchronized ( target ) // See notes about synchronization/thread safety in class javadoc { target.write( encodedArray.getArray(), 0, encodedArray.getSize() ); target.flush(); if ( target.checkError() ) { // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up: // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception DumpErrorSingleton.getSingleton() .dumpStreamText( "Unexpected IOException with stream: " + new String( buf, off, len ) ); } } }