Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-2015] Implement testRunId and RunMode in the SimpleReportEntry #482

Merged
merged 2 commits into from Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -80,7 +80,7 @@ public final class ForkClient

private final int forkNumber;

private volatile TestReportListener testSetReporter;
private volatile TestReportListener<TestOutputReportEntry> testSetReporter;

/**
* Written by one Thread and read by another: Main Thread and ForkStarter's Thread.
Expand Down Expand Up @@ -125,7 +125,7 @@ private final class TestSetStartingListener
implements ForkedProcessReportEventListener<TestSetReportEntry>
{
@Override
public void handle( RunMode runMode, TestSetReportEntry reportEntry )
public void handle( TestSetReportEntry reportEntry )
{
getTestSetReporter().testSetStarting( reportEntry );
setCurrentStartTime();
Expand All @@ -136,21 +136,22 @@ private final class TestSetCompletedListener
implements ForkedProcessReportEventListener<TestSetReportEntry>
{
@Override
public void handle( RunMode runMode, TestSetReportEntry reportEntry )
public void handle( TestSetReportEntry reportEntry )
{
testsInProgress.clear();
TestSetReportEntry entry = reportEntry( reportEntry.getSourceName(), reportEntry.getSourceText(),
reportEntry.getName(), reportEntry.getNameText(),
reportEntry.getGroup(), reportEntry.getStackTraceWriter(), reportEntry.getElapsed(),
reportEntry.getMessage(), getTestVmSystemProperties() );
TestSetReportEntry entry = reportEntry( reportEntry.getRunMode(), reportEntry.getTestRunId(),
reportEntry.getSourceName(), reportEntry.getSourceText(),
reportEntry.getName(), reportEntry.getNameText(),
reportEntry.getGroup(), reportEntry.getStackTraceWriter(), reportEntry.getElapsed(),
reportEntry.getMessage(), getTestVmSystemProperties() );
getTestSetReporter().testSetCompleted( entry );
}
}

private final class TestStartingListener implements ForkedProcessReportEventListener<ReportEntry>
{
@Override
public void handle( RunMode runMode, ReportEntry reportEntry )
public void handle( ReportEntry reportEntry )
{
testsInProgress.offer( reportEntry.getSourceName() );
getTestSetReporter().testStarting( reportEntry );
Expand All @@ -160,7 +161,7 @@ public void handle( RunMode runMode, ReportEntry reportEntry )
private final class TestSucceededListener implements ForkedProcessReportEventListener<ReportEntry>
{
@Override
public void handle( RunMode runMode, ReportEntry reportEntry )
public void handle( ReportEntry reportEntry )
{
testsInProgress.remove( reportEntry.getSourceName() );
getTestSetReporter().testSucceeded( reportEntry );
Expand All @@ -170,7 +171,7 @@ public void handle( RunMode runMode, ReportEntry reportEntry )
private final class TestFailedListener implements ForkedProcessReportEventListener<ReportEntry>
{
@Override
public void handle( RunMode runMode, ReportEntry reportEntry )
public void handle( ReportEntry reportEntry )
{
testsInProgress.remove( reportEntry.getSourceName() );
getTestSetReporter().testFailed( reportEntry );
Expand All @@ -180,7 +181,7 @@ public void handle( RunMode runMode, ReportEntry reportEntry )
private final class TestSkippedListener implements ForkedProcessReportEventListener<ReportEntry>
{
@Override
public void handle( RunMode runMode, ReportEntry reportEntry )
public void handle( ReportEntry reportEntry )
{
testsInProgress.remove( reportEntry.getSourceName() );
getTestSetReporter().testSkipped( reportEntry );
Expand All @@ -190,7 +191,7 @@ public void handle( RunMode runMode, ReportEntry reportEntry )
private final class TestErrorListener implements ForkedProcessReportEventListener<ReportEntry>
{
@Override
public void handle( RunMode runMode, ReportEntry reportEntry )
public void handle( ReportEntry reportEntry )
{
testsInProgress.remove( reportEntry.getSourceName() );
getTestSetReporter().testError( reportEntry );
Expand All @@ -200,7 +201,7 @@ public void handle( RunMode runMode, ReportEntry reportEntry )
private final class TestAssumptionFailureListener implements ForkedProcessReportEventListener<ReportEntry>
{
@Override
public void handle( RunMode runMode, ReportEntry reportEntry )
public void handle( ReportEntry reportEntry )
{
testsInProgress.remove( reportEntry.getSourceName() );
getTestSetReporter().testAssumptionFailure( reportEntry );
Expand Down Expand Up @@ -370,7 +371,7 @@ public boolean hadTimeout()
/**
* Only {@link #getConsoleOutputReceiver()} may call this method in another Thread.
*/
private TestReportListener getTestSetReporter()
private TestReportListener<TestOutputReportEntry> getTestSetReporter()
{
if ( testSetReporter == null )
{
Expand Down Expand Up @@ -414,7 +415,7 @@ public RunListener getReporter()
return getTestSetReporter();
}

public TestOutputReceiver getConsoleOutputReceiver()
public TestOutputReceiver<TestOutputReportEntry> getConsoleOutputReceiver()
{
return getTestSetReporter();
}
Expand Down
Expand Up @@ -225,11 +225,10 @@ else if ( event.isTestCategory() )
{
ForkedProcessReportEventListener listener = reportEventListeners.get( eventType );
AbstractTestControlEvent testControlEvent = (AbstractTestControlEvent) event;
RunMode mode = testControlEvent.getRunMode();
ReportEntry reportEntry = testControlEvent.getReportEntry();
if ( listener != null )
{
listener.handle( mode, reportEntry );
listener.handle( reportEntry );
}
}
else if ( event.isJvmExitError() )
Expand Down
Expand Up @@ -20,7 +20,6 @@
*/

import org.apache.maven.surefire.api.report.ReportEntry;
import org.apache.maven.surefire.api.report.RunMode;

/**
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
Expand All @@ -29,5 +28,5 @@
*/
public interface ForkedProcessReportEventListener<T extends ReportEntry>
{
void handle( RunMode runMode, T reportEntry );
void handle( T reportEntry );
}
Expand Up @@ -23,6 +23,7 @@
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.log.api.Level;
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
import org.apache.maven.surefire.api.report.TestOutputReportEntry;
import org.apache.maven.surefire.shared.utils.logging.MessageBuilder;
import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
import org.apache.maven.surefire.extensions.StatelessReportEventListener;
Expand Down Expand Up @@ -97,7 +98,7 @@ public DefaultReporterFactory( StartupReportConfiguration reportConfiguration, C
}

@Override
public TestReportListener createTestReportListener()
public TestReportListener<TestOutputReportEntry> createTestReportListener()
{
TestSetRunListener testSetRunListener =
new TestSetRunListener( createConsoleReporter(),
Expand Down
Expand Up @@ -26,22 +26,19 @@
import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
import org.apache.maven.surefire.api.report.ReportEntry;
import org.apache.maven.surefire.api.report.TestOutputReportEntry;
import org.apache.maven.surefire.api.report.TestReportListener;
import org.apache.maven.surefire.api.report.TestSetReportEntry;
import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
import org.apache.maven.surefire.extensions.StatelessReportEventListener;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoFileReportEventListener;
import org.apache.maven.surefire.api.report.ReportEntry;
import org.apache.maven.surefire.api.report.RunMode;
import org.apache.maven.surefire.api.report.TestReportListener;
import org.apache.maven.surefire.api.report.TestSetReportEntry;

import static org.apache.maven.plugin.surefire.report.ReportEntryType.ERROR;
import static org.apache.maven.plugin.surefire.report.ReportEntryType.FAILURE;
import static org.apache.maven.plugin.surefire.report.ReportEntryType.SKIPPED;
import static org.apache.maven.plugin.surefire.report.ReportEntryType.SUCCESS;
import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
import static java.util.Objects.requireNonNull;

/**
* Reports data for a single test set.
Expand All @@ -50,7 +47,7 @@
* @author Kristian Rosenvold
*/
public class TestSetRunListener
implements TestReportListener
implements TestReportListener<TestOutputReportEntry>
{
private final Queue<TestMethodStats> testMethodStats = new ConcurrentLinkedQueue<>();

Expand All @@ -74,8 +71,6 @@ public class TestSetRunListener

private Utf8RecodingDeferredFileOutputStream testStdErr = initDeferred( "stderr" );

private volatile RunMode runMode = NORMAL_RUN;

@SuppressWarnings( "checkstyle:parameternumber" )
public TestSetRunListener( StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats>
consoleReporter,
Expand Down Expand Up @@ -282,13 +277,6 @@ public void testExecutionSkippedByUser()
{
}

public RunMode markAs( RunMode currentRunMode )
{
RunMode runMode = this.runMode;
this.runMode = requireNonNull( currentRunMode );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private field runMode can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, done :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RunMode will be finally removed in AbstractStandardStreamEvent and EventChannelEncoder in the SUREFIRE-2014.

return runMode;
}

@Override
public void testAssumptionFailure( ReportEntry report )
{
Expand Down
Expand Up @@ -20,14 +20,15 @@
*/

import org.apache.maven.surefire.api.report.TestOutputReceiver;
import org.apache.maven.surefire.api.report.TestOutputReportEntry;
import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
import org.apache.maven.surefire.api.report.TestSetReportEntry;

/**
* @author Kristian Rosenvold
*/
public interface TestcycleConsoleOutputReceiver
extends TestOutputReceiver, ConsoleOutputReportEventListener
extends TestOutputReceiver<TestOutputReportEntry>, ConsoleOutputReportEventListener
{
void testSetStarting( TestSetReportEntry reportEntry );

Expand Down
Expand Up @@ -20,9 +20,11 @@
*/

import org.apache.maven.surefire.api.report.ReportEntry;
import org.apache.maven.surefire.api.report.RunMode;
import org.apache.maven.surefire.api.report.StackTraceWriter;
import org.apache.maven.surefire.api.report.TestSetReportEntry;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;

Expand Down Expand Up @@ -224,6 +226,19 @@ public String getReportNameWithGroup()
return original.getReportNameWithGroup();
}

@Nonnull
@Override
public RunMode getRunMode()
{
return original.getRunMode();
}

@Override
public Long getTestRunId()
{
return original.getTestRunId();
}

@Override
public Map<String, String> getSystemProperties()
{
Expand Down
Expand Up @@ -38,7 +38,6 @@
import static org.apache.maven.surefire.api.booter.MasterProcessCommand.SHUTDOWN;
import static org.apache.maven.surefire.api.booter.MasterProcessCommand.SKIP_SINCE_NEXT_TEST;
import static org.apache.maven.surefire.api.booter.MasterProcessCommand.TEST_SET_FINISHED;
import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;

/**
*
Expand All @@ -56,52 +55,50 @@ public CommandEncoder( WritableByteChannel out )
public void sendRunClass( String testClassName ) throws IOException
{
CharsetEncoder encoder = newCharsetEncoder();
int bufferMaxLength =
estimateBufferLength( RUN_CLASS.getOpcodeLength(), NORMAL_RUN, encoder, 0, testClassName );
int bufferMaxLength = estimateBufferLength( RUN_CLASS.getOpcodeLength(), null, encoder, 0, 0, testClassName );
ByteBuffer result = ByteBuffer.allocate( bufferMaxLength );
encode( encoder, result, RUN_CLASS, NORMAL_RUN, testClassName );
encode( encoder, result, RUN_CLASS, testClassName );
write( result, true );
}

public void sendTestSetFinished() throws IOException
{
int bufferMaxLength = estimateBufferLength( TEST_SET_FINISHED.getOpcodeLength(), null, null, 0 );
int bufferMaxLength = estimateBufferLength( TEST_SET_FINISHED.getOpcodeLength(), null, null, 0, 0 );
ByteBuffer result = ByteBuffer.allocate( bufferMaxLength );
encodeHeader( result, TEST_SET_FINISHED, null );
encodeHeader( result, TEST_SET_FINISHED );
write( result, true );
}

public void sendSkipSinceNextTest() throws IOException
{
int bufferMaxLength = estimateBufferLength( SKIP_SINCE_NEXT_TEST.getOpcodeLength(), null, null, 0 );
int bufferMaxLength = estimateBufferLength( SKIP_SINCE_NEXT_TEST.getOpcodeLength(), null, null, 0, 0 );
ByteBuffer result = ByteBuffer.allocate( bufferMaxLength );
encodeHeader( result, SKIP_SINCE_NEXT_TEST, null );
encodeHeader( result, SKIP_SINCE_NEXT_TEST );
write( result, true );
}

public void sendShutdown( String shutdownData ) throws IOException
{
CharsetEncoder encoder = newCharsetEncoder();
int bufferMaxLength =
estimateBufferLength( SHUTDOWN.getOpcodeLength(), null, encoder, 0, shutdownData );
int bufferMaxLength = estimateBufferLength( SHUTDOWN.getOpcodeLength(), null, encoder, 0, 0, shutdownData );
ByteBuffer result = ByteBuffer.allocate( bufferMaxLength );
encode( encoder, result, SHUTDOWN, null, shutdownData );
encode( encoder, result, SHUTDOWN, shutdownData );
write( result, true );
}

public void sendNoop() throws IOException
{
int bufferMaxLength = estimateBufferLength( NOOP.getOpcodeLength(), null, null, 0 );
int bufferMaxLength = estimateBufferLength( NOOP.getOpcodeLength(), null, null, 0, 0 );
ByteBuffer result = ByteBuffer.allocate( bufferMaxLength );
encodeHeader( result, NOOP, null );
encodeHeader( result, NOOP );
write( result, true );
}

public void sendByeAck() throws IOException
{
int bufferMaxLength = estimateBufferLength( BYE_ACK.getOpcodeLength(), null, null, 0 );
int bufferMaxLength = estimateBufferLength( BYE_ACK.getOpcodeLength(), null, null, 0, 0 );
ByteBuffer result = ByteBuffer.allocate( bufferMaxLength );
encodeHeader( result, BYE_ACK, null );
encodeHeader( result, BYE_ACK );
write( result, true );
}

Expand Down