@Test public void shouldComputeStreamPreemptiveLength() { CharsetEncoder encoder = UTF_8.newEncoder(); assertThat( estimateBufferLength( BOOTERCODE_SYSPROPS, NORMAL_RUN, encoder, 0, "k", "v" ) ) .isEqualTo( 72 ); assertThat( estimateBufferLength( BOOTERCODE_TESTSET_STARTING, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 149 ); assertThat( estimateBufferLength( BOOTERCODE_TESTSET_COMPLETED, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 150 ); assertThat( estimateBufferLength( BOOTERCODE_TEST_STARTING, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 146 ); assertThat( estimateBufferLength( BOOTERCODE_TEST_SUCCEEDED, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 147 ); assertThat( estimateBufferLength( BOOTERCODE_TEST_FAILED, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 144 ); assertThat( estimateBufferLength( BOOTERCODE_TEST_SKIPPED, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 145 ); assertThat( estimateBufferLength( BOOTERCODE_TEST_ERROR, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 143 ); assertThat( estimateBufferLength( BOOTERCODE_TEST_ASSUMPTIONFAILURE, NORMAL_RUN, encoder, 1, "s", "s", "s", "s", "s", "s", "s", "s", "s" ) ) .isEqualTo( 156 ); assertThat( estimateBufferLength( BOOTERCODE_STDOUT, NORMAL_RUN, encoder, 0, "s" ) ) .isEqualTo( 69 ); assertThat( estimateBufferLength( BOOTERCODE_STDOUT_NEW_LINE, NORMAL_RUN, encoder, 0, "s" ) ) .isEqualTo( 78 ); assertThat( estimateBufferLength( BOOTERCODE_STDERR, NORMAL_RUN, encoder, 0, "s" ) ) .isEqualTo( 69 ); assertThat( estimateBufferLength( BOOTERCODE_STDERR_NEW_LINE, NORMAL_RUN, encoder, 0, "s" ) ) .isEqualTo( 78 ); assertThat( estimateBufferLength( BOOTERCODE_CONSOLE_INFO, null, encoder, 0, "s" ) ) .isEqualTo( 58 ); assertThat( estimateBufferLength( BOOTERCODE_CONSOLE_DEBUG, null, encoder, 0, "s" ) ) .isEqualTo( 59 ); assertThat( estimateBufferLength( BOOTERCODE_CONSOLE_WARNING, null, encoder, 0, "s" ) ) .isEqualTo( 61 ); assertThat( estimateBufferLength( BOOTERCODE_CONSOLE_ERROR, null, encoder, 0, "s" ) ) .isEqualTo( 59 ); assertThat( estimateBufferLength( BOOTERCODE_BYE, null, null, 0 ) ) .isEqualTo( 28 ); assertThat( estimateBufferLength( BOOTERCODE_STOP_ON_NEXT_TEST, null, null, 0 ) ) .isEqualTo( 42 ); assertThat( estimateBufferLength( BOOTERCODE_NEXT_TEST, null, null, 0 ) ) .isEqualTo( 34 ); assertThat( estimateBufferLength( BOOTERCODE_JVM_EXIT_ERROR, null, null, 0 ) ) .isEqualTo( 39 ); }
static int estimateBufferLength( ForkedProcessEventType eventType, RunMode runMode, CharsetEncoder encoder, int integersCounter, String... strings ) { assert !( encoder == null && strings.length != 0 ); int lengthOfMetadata = 1 + MAGIC_NUMBER_BYTES.length + 1 + 1 + 1 + eventType.getOpcode().length() + 1; if ( runMode != null ) { lengthOfMetadata += 1 + 1 + runMode.geRunmode().length() + 1; } if ( encoder != null ) { lengthOfMetadata += 1 + 1 + encoder.charset().name().length() + 1; } int lengthOfData = ( 1 + 4 + 1 ) * integersCounter; for ( String string : strings ) { String s = string == null ? "\u0000" : string; lengthOfData += 4 + 1 + (int) ceil( encoder.maxBytesPerChar() * s.length() ) + 1; } return lengthOfMetadata + lengthOfData; }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { static int estimateBufferLength( ForkedProcessEventType eventType, RunMode runMode, CharsetEncoder encoder, int integersCounter, String... strings ) { assert !( encoder == null && strings.length != 0 ); int lengthOfMetadata = 1 + MAGIC_NUMBER_BYTES.length + 1 + 1 + 1 + eventType.getOpcode().length() + 1; if ( runMode != null ) { lengthOfMetadata += 1 + 1 + runMode.geRunmode().length() + 1; } if ( encoder != null ) { lengthOfMetadata += 1 + 1 + encoder.charset().name().length() + 1; } int lengthOfData = ( 1 + 4 + 1 ) * integersCounter; for ( String string : strings ) { String s = string == null ? "\u0000" : string; lengthOfData += 4 + 1 + (int) ceil( encoder.maxBytesPerChar() * s.length() ) + 1; } return lengthOfMetadata + lengthOfData; } }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { static int estimateBufferLength( ForkedProcessEventType eventType, RunMode runMode, CharsetEncoder encoder, int integersCounter, String... strings ) { assert !( encoder == null && strings.length != 0 ); int lengthOfMetadata = 1 + MAGIC_NUMBER_BYTES.length + 1 + 1 + 1 + eventType.getOpcode().length() + 1; if ( runMode != null ) { lengthOfMetadata += 1 + 1 + runMode.geRunmode().length() + 1; } if ( encoder != null ) { lengthOfMetadata += 1 + 1 + encoder.charset().name().length() + 1; } int lengthOfData = ( 1 + 4 + 1 ) * integersCounter; for ( String string : strings ) { String s = string == null ? "\u0000" : string; lengthOfData += 4 + 1 + (int) ceil( encoder.maxBytesPerChar() * s.length() ) + 1; } return lengthOfMetadata + lengthOfData; } LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out ); protected  LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out, @Nonnull RunMode runMode ); }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { static int estimateBufferLength( ForkedProcessEventType eventType, RunMode runMode, CharsetEncoder encoder, int integersCounter, String... strings ) { assert !( encoder == null && strings.length != 0 ); int lengthOfMetadata = 1 + MAGIC_NUMBER_BYTES.length + 1 + 1 + 1 + eventType.getOpcode().length() + 1; if ( runMode != null ) { lengthOfMetadata += 1 + 1 + runMode.geRunmode().length() + 1; } if ( encoder != null ) { lengthOfMetadata += 1 + 1 + encoder.charset().name().length() + 1; } int lengthOfData = ( 1 + 4 + 1 ) * integersCounter; for ( String string : strings ) { String s = string == null ? "\u0000" : string; lengthOfData += 4 + 1 + (int) ceil( encoder.maxBytesPerChar() * s.length() ) + 1; } return lengthOfMetadata + lengthOfData; } LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out ); protected  LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out, @Nonnull RunMode runMode ); @Override MasterProcessChannelEncoder asRerunMode(); @Override MasterProcessChannelEncoder asNormalMode(); @Override boolean checkError(); @Override void onJvmExit(); @Override void sendSystemProperties( Map<String, String> sysProps ); @Override void testSetStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSetCompleted( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSucceeded( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testFailed( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSkipped( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testError( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testAssumptionFailure( ReportEntry reportEntry, boolean trimStackTraces ); @Override void stdOut( String msg, boolean newLine ); @Override void stdErr( String msg, boolean newLine ); @Override void consoleInfoLog( String message ); @Override void consoleErrorLog( String message ); @Override void consoleErrorLog( Throwable t ); @Override void consoleErrorLog( String message, Throwable t ); @Override void consoleErrorLog( StackTraceWriter stackTraceWriter, boolean trimStackTraces ); @Override void consoleDebugLog( String message ); @Override void consoleWarningLog( String message ); @Override void bye(); @Override void stopOnNextTest(); @Override void acquireNextTest(); @Override void sendExitError( StackTraceWriter stackTraceWriter, boolean trimStackTraces ); }
LegacyMasterProcessChannelEncoder implements MasterProcessChannelEncoder { static int estimateBufferLength( ForkedProcessEventType eventType, RunMode runMode, CharsetEncoder encoder, int integersCounter, String... strings ) { assert !( encoder == null && strings.length != 0 ); int lengthOfMetadata = 1 + MAGIC_NUMBER_BYTES.length + 1 + 1 + 1 + eventType.getOpcode().length() + 1; if ( runMode != null ) { lengthOfMetadata += 1 + 1 + runMode.geRunmode().length() + 1; } if ( encoder != null ) { lengthOfMetadata += 1 + 1 + encoder.charset().name().length() + 1; } int lengthOfData = ( 1 + 4 + 1 ) * integersCounter; for ( String string : strings ) { String s = string == null ? "\u0000" : string; lengthOfData += 4 + 1 + (int) ceil( encoder.maxBytesPerChar() * s.length() ) + 1; } return lengthOfMetadata + lengthOfData; } LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out ); protected  LegacyMasterProcessChannelEncoder( @Nonnull WritableBufferedByteChannel out, @Nonnull RunMode runMode ); @Override MasterProcessChannelEncoder asRerunMode(); @Override MasterProcessChannelEncoder asNormalMode(); @Override boolean checkError(); @Override void onJvmExit(); @Override void sendSystemProperties( Map<String, String> sysProps ); @Override void testSetStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSetCompleted( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testStarting( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSucceeded( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testFailed( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testSkipped( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testError( ReportEntry reportEntry, boolean trimStackTraces ); @Override void testAssumptionFailure( ReportEntry reportEntry, boolean trimStackTraces ); @Override void stdOut( String msg, boolean newLine ); @Override void stdErr( String msg, boolean newLine ); @Override void consoleInfoLog( String message ); @Override void consoleErrorLog( String message ); @Override void consoleErrorLog( Throwable t ); @Override void consoleErrorLog( String message, Throwable t ); @Override void consoleErrorLog( StackTraceWriter stackTraceWriter, boolean trimStackTraces ); @Override void consoleDebugLog( String message ); @Override void consoleWarningLog( String message ); @Override void bye(); @Override void stopOnNextTest(); @Override void acquireNextTest(); @Override void sendExitError( StackTraceWriter stackTraceWriter, boolean trimStackTraces );  }