Skip to content

Commit

Permalink
[SUREFIRE-2015] Implement testRunId and RunMode in the SimpleReportEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor17 committed Mar 1, 2022
1 parent c14aacb commit 20a24de
Show file tree
Hide file tree
Showing 70 changed files with 1,241 additions and 593 deletions.
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 @@ -139,10 +139,11 @@ private final class TestSetCompletedListener
public void handle( RunMode runMode, 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 );
}
}
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 @@ -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,21 @@
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.RunMode;
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 +49,7 @@
* @author Kristian Rosenvold
*/
public class TestSetRunListener
implements TestReportListener
implements TestReportListener<TestOutputReportEntry>
{
private final Queue<TestMethodStats> testMethodStats = new ConcurrentLinkedQueue<>();

Expand Down Expand Up @@ -282,13 +281,6 @@ public void testExecutionSkippedByUser()
{
}

public RunMode markAs( RunMode currentRunMode )
{
RunMode runMode = this.runMode;
this.runMode = requireNonNull( currentRunMode );
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 @@ -58,14 +58,15 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.ReadableByteChannel;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.FutureTask;

import static java.util.Collections.emptyMap;
import static org.apache.maven.surefire.api.booter.Constants.MAGIC_NUMBER_FOR_EVENTS_BYTES;
import static org.apache.maven.surefire.api.report.CategorizedReportEntry.reportEntry;
import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
import static org.apache.maven.surefire.api.stream.SegmentType.DATA_INTEGER;
import static org.apache.maven.surefire.api.stream.SegmentType.DATA_STRING;
import static org.apache.maven.surefire.api.stream.SegmentType.END_OF_FRAME;
Expand Down Expand Up @@ -382,8 +383,8 @@ static TestSetReportEntry newReportEntry( // ReportEntry:
throws NumberFormatException
{
StackTraceWriter stackTraceWriter = toTrace( traceMessage, smartTrimmedStackTrace, stackTrace );
return reportEntry( source, sourceText, name, nameText, group, stackTraceWriter, timeElapsed, message,
Collections.<String, String>emptyMap() );
return reportEntry( NORMAL_RUN /*todo*/, 0L /*todo*/, source, sourceText, name, nameText, group,
stackTraceWriter, timeElapsed, message, emptyMap() );
}

private static Map<Segment, ForkedProcessEventType> segmentsToEvents()
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.maven.plugin.surefire.extensions.EventConsumerThread;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.surefire.api.booter.ForkingRunListener;
import org.apache.maven.surefire.api.report.TestOutputReportEntry;
import org.apache.maven.surefire.booter.spi.EventChannelEncoder;
import org.apache.maven.surefire.api.event.Event;
import org.apache.maven.surefire.extensions.EventHandler;
Expand Down Expand Up @@ -58,6 +59,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
import static org.apache.maven.surefire.api.report.TestOutputReportEntry.stdOut;
import static org.apache.maven.surefire.api.util.internal.Channels.newBufferedChannel;
import static org.apache.maven.surefire.api.util.internal.Channels.newChannel;
Expand Down Expand Up @@ -182,8 +184,8 @@ public void testConsole() throws Exception
public void testConsoleOutput() throws Exception
{
final StandardTestRun standardTestRun = new StandardTestRun();
TestOutputReceiver directConsoleReporter = standardTestRun.run();
directConsoleReporter.writeTestOutput( stdOut( "HeyYou" ) );
TestOutputReceiver<TestOutputReportEntry> directConsoleReporter = standardTestRun.run();
directConsoleReporter.writeTestOutput( (TestOutputReportEntry) stdOut( "HeyYou" ) );
standardTestRun.assertExpected( MockReporter.STDOUT, "HeyYou" );
}

Expand Down Expand Up @@ -276,19 +278,19 @@ public void test2DifferentChannels()
}

MockReporter reporter = (MockReporter) forkStreamClient.getReporter();
assertEquals( MockReporter.TEST_STARTING, reporter.getFirstEvent() );
assertEquals( expected, reporter.getFirstData() );
assertEquals( 1, reporter.getEvents().size() );
assertThat( reporter.getFirstEvent() ).isEqualTo( MockReporter.TEST_STARTING );
//assertThat( reporter.getFirstData() ).isEqualTo( expected ); /*toto uncomment in SUREFIRE-2014*/
assertThat( reporter.getEvents() ).hasSize( 1 );

forkStreamClient = new ForkClient( providerReporterFactory, notifiableTestStream, 2 );
for ( Event e : streamToEvent( anotherContent.toByteArray() ) )
{
forkStreamClient.handleEvent( e );
}
MockReporter reporter2 = (MockReporter) forkStreamClient.getReporter();
assertEquals( MockReporter.TEST_SKIPPED, reporter2.getFirstEvent() );
assertEquals( secondExpected, reporter2.getFirstData() );
assertEquals( 1, reporter2.getEvents().size() );
assertThat( reporter2.getFirstEvent() ).isEqualTo( MockReporter.TEST_SKIPPED );
//assertThat( reporter2.getFirstData() ).isEqualTo( secondExpected ); /*toto uncomment in SUREFIRE-2014*/
assertThat( reporter2.getEvents() ).hasSize( 1 );
}

private static List<Event> streamToEvent( byte[] stream ) throws Exception
Expand Down Expand Up @@ -422,7 +424,8 @@ public void handleEvent( @Nonnull Event event )

private SimpleReportEntry createDefaultReportEntry( Map<String, String> sysProps )
{
return new SimpleReportEntry( "com.abc.TestClass", null, "testMethod", null, null, 22, sysProps );
return new SimpleReportEntry( NORMAL_RUN, 1L,
"com.abc.TestClass", null, "testMethod", null, null, 22, sysProps );
}

private SimpleReportEntry createDefaultReportEntry()
Expand All @@ -432,7 +435,8 @@ private SimpleReportEntry createDefaultReportEntry()

private SimpleReportEntry createAnotherDefaultReportEntry()
{
return new SimpleReportEntry( "com.abc.AnotherTestClass", null, "testAnotherMethod", null, 42 );
return new SimpleReportEntry( NORMAL_RUN, 0L,
"com.abc.AnotherTestClass", null, "testAnotherMethod", null, 42 );
}

private SimpleReportEntry createReportEntryWithStackTrace()
Expand All @@ -445,7 +449,8 @@ private SimpleReportEntry createReportEntryWithStackTrace()
{
StackTraceWriter stackTraceWriter =
new LegacyPojoStackTraceWriter( "org.apache.tests.TestClass", "testMethod11", e );
return new CategorizedReportEntry( "com.abc.TestClass", "testMethod", "aGroup", stackTraceWriter, 77 );
return new CategorizedReportEntry( NORMAL_RUN, 0L,
"com.abc.TestClass", "testMethod", "aGroup", stackTraceWriter, 77 );
}
}

Expand All @@ -459,11 +464,12 @@ private SimpleReportEntry createReportEntryWithSpecialMessage( String message )
{
StackTraceWriter stackTraceWriter =
new LegacyPojoStackTraceWriter( "org.apache.tests.TestClass", "testMethod11", e );
return new CategorizedReportEntry( "com.abc.TestClass", "testMethod", "aGroup", stackTraceWriter, 77 );
return new CategorizedReportEntry( NORMAL_RUN, 0L,
"com.abc.TestClass", "testMethod", "aGroup", stackTraceWriter, 77 );
}
}

private TestReportListener createForkingRunListener()
private TestReportListener<TestOutputReportEntry> createForkingRunListener()
{
WritableBufferedByteChannel channel = (WritableBufferedByteChannel) newChannel( printStream );
return new ForkingRunListener( new EventChannelEncoder( channel ), false );
Expand All @@ -473,7 +479,7 @@ private class StandardTestRun
{
private MockReporter reporter;

public TestReportListener run()
public TestReportListener<TestOutputReportEntry> run()
throws ReporterException
{
reset();
Expand Down
Expand Up @@ -23,7 +23,6 @@
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.api.report.RunMode;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -33,7 +32,7 @@
* Internal tests use only.
*/
public class MockReporter
implements TestReportListener
implements TestReportListener<TestOutputReportEntry>
{
private final List<String> events = new ArrayList<>();

Expand Down Expand Up @@ -131,17 +130,6 @@ public void testExecutionSkippedByUser()
{
}

@Override
public RunMode markAs( RunMode currentRunMode )
{
return null;
}

public void testSkippedByUser( ReportEntry report )
{
testSkipped( report );
}

public List<String> getEvents()
{
return events;
Expand Down
Expand Up @@ -1296,7 +1296,8 @@ public void shouldSendTestSucceeded()
when( reportEntry.getStackTraceWriter() ).thenReturn( stackTraceWriter );

ForkClient client = new ForkClient( factory, notifiableTestStream, 0 );
SimpleReportEntry testStarted = new SimpleReportEntry( reportEntry.getSourceName(), null, null, null );
SimpleReportEntry testStarted =
new SimpleReportEntry( NORMAL_RUN, 1L, reportEntry.getSourceName(), null, null, null );
client.handleEvent( new TestStartingEvent( NORMAL_RUN, testStarted ) );

assertThat( client.testsInProgress() )
Expand Down Expand Up @@ -1400,7 +1401,8 @@ public void shouldSendTestFailed()
when( reportEntry.getStackTraceWriter() ).thenReturn( stackTraceWriter );

ForkClient client = new ForkClient( factory, notifiableTestStream, 0 );
SimpleReportEntry testClass = new SimpleReportEntry( reportEntry.getSourceName(), null, null, null );
SimpleReportEntry testClass =
new SimpleReportEntry( NORMAL_RUN, 1L, reportEntry.getSourceName(), null, null, null );
client.handleEvent( new TestStartingEvent( NORMAL_RUN, testClass ) );

assertThat( client.testsInProgress() )
Expand Down Expand Up @@ -1510,7 +1512,8 @@ public void shouldSendTestSkipped()
when( reportEntry.getStackTraceWriter() ).thenReturn( stackTraceWriter );

ForkClient client = new ForkClient( factory, notifiableTestStream, 0 );
SimpleReportEntry testStarted = new SimpleReportEntry( reportEntry.getSourceName(), null, null, null );
SimpleReportEntry testStarted =
new SimpleReportEntry( NORMAL_RUN, 1L, reportEntry.getSourceName(), null, null, null );
client.handleEvent( new TestStartingEvent( NORMAL_RUN, testStarted ) );

assertThat( client.testsInProgress() )
Expand Down Expand Up @@ -1619,8 +1622,8 @@ public void shouldSendTestError()
when( reportEntry.getStackTraceWriter() ).thenReturn( stackTraceWriter );

ForkClient client = new ForkClient( factory, notifiableTestStream, 0 );
SimpleReportEntry testStarted =
new SimpleReportEntry( reportEntry.getSourceName(), reportEntry.getSourceText(), null, null );
SimpleReportEntry testStarted = new SimpleReportEntry( NORMAL_RUN, 1L, reportEntry.getSourceName(),
reportEntry.getSourceText(), null, null );
client.handleEvent( new TestStartingEvent( NORMAL_RUN, testStarted ) );

assertThat( client.testsInProgress() )
Expand Down Expand Up @@ -1725,7 +1728,8 @@ public void shouldSendTestAssumptionFailure()
when( reportEntry.getStackTraceWriter() ).thenReturn( stackTraceWriter );

ForkClient client = new ForkClient( factory, notifiableTestStream, 0 );
SimpleReportEntry testStarted = new SimpleReportEntry( reportEntry.getSourceName(), null, null, null );
SimpleReportEntry testStarted =
new SimpleReportEntry( NORMAL_RUN, 1L, reportEntry.getSourceName(), null, null, null );
client.handleEvent( new TestStartingEvent( NORMAL_RUN, testStarted ) );

assertThat( client.testsInProgress() )
Expand Down

0 comments on commit 20a24de

Please sign in to comment.