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

Test Indexes and Reporters #616

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ private void mergeTestHistoryResult()
// Merge all the stats for tests from listeners
for ( TestSetRunListener listener : listeners )
{
// this method should not be here
// it should be centralized in one place in the state machine - processor
for ( TestMethodStats methodStats : listener.getTestMethodStats() )
{
List<TestMethodStats> currentMethodStats =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
* under the License.
*/

import static java.util.Objects.requireNonNull;

/**
* Type of an entry in the report
* Type of entry in the report.
*
*/
public enum ReportEntryType
{

TEST_SET_STARTING(),
TEST_SET_COMPLETED(),
TEST_STARTING(),
TEST_ASSUMPTION_FAILURE(),
ERROR( "error", "flakyError", "rerunError" ),
FAILURE( "failure", "flakyFailure", "rerunFailure" ),
SKIPPED( "skipped", "", "" ),
Expand All @@ -37,6 +42,11 @@ public enum ReportEntryType

private final String rerunXmlTag;

ReportEntryType()
{
this( null, null, null );
}

ReportEntryType( String xmlTag, String flakyXmlTag, String rerunXmlTag )
{
this.xmlTag = xmlTag;
Expand All @@ -46,16 +56,16 @@ public enum ReportEntryType

public String getXmlTag()
{
return xmlTag;
return requireNonNull( xmlTag );
}

public String getFlakyXmlTag()
{
return flakyXmlTag;
return requireNonNull( flakyXmlTag );
}

public String getRerunXmlTag()
{
return rerunXmlTag;
return requireNonNull( rerunXmlTag );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package org.apache.maven.plugin.surefire.report;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
import org.apache.maven.surefire.extensions.StatelessReportEventListener;
import org.apache.maven.surefire.extensions.StatelessTestSetSummaryListener;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoFileReportEventListener;

/**
*
*/
public final class ReportersAggregator
{
private StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> consoleReporter;
private StatelessTestsetInfoFileReportEventListener<WrappedReportEntry, TestSetStats> fileReporter;
private StatelessReportEventListener<WrappedReportEntry, TestSetStats> simpleXMLReporter;
private ConsoleOutputReportEventListener testOutputReceiver;
private StatisticsReporter statisticsReporter;
private StatelessTestSetSummaryListener testSetSummaryReporter;
private boolean trimStackTrace;
private boolean isPlainFormat;
private boolean briefOrPlainFormat;

public StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> getConsoleReporter()
{
return consoleReporter;
}

public void setConsoleReporter(
StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> consoleReporter )
{
this.consoleReporter = consoleReporter;
}

public StatelessTestsetInfoFileReportEventListener<WrappedReportEntry, TestSetStats> getFileReporter()
{
return fileReporter;
}

public void setFileReporter(
StatelessTestsetInfoFileReportEventListener<WrappedReportEntry, TestSetStats> fileReporter )
{
this.fileReporter = fileReporter;
}

public StatelessReportEventListener<WrappedReportEntry, TestSetStats> getSimpleXMLReporter()
{
return simpleXMLReporter;
}

public void setSimpleXMLReporter( StatelessReportEventListener<WrappedReportEntry, TestSetStats> simpleXMLReporter )
{
this.simpleXMLReporter = simpleXMLReporter;
}

public ConsoleOutputReportEventListener getTestOutputReceiver()
{
return testOutputReceiver;
}

public void setTestOutputReceiver( ConsoleOutputReportEventListener testOutputReceiver )
{
this.testOutputReceiver = testOutputReceiver;
}

public StatisticsReporter getStatisticsReporter()
{
return statisticsReporter;
}

public void setStatisticsReporter( StatisticsReporter statisticsReporter )
{
this.statisticsReporter = statisticsReporter;
}

public StatelessTestSetSummaryListener getTestSetSummaryReporter()
{
return testSetSummaryReporter;
}

public void setTestSetSummaryReporter( StatelessTestSetSummaryListener testSetSummaryReporter )
{
this.testSetSummaryReporter = testSetSummaryReporter;
}

public boolean isTrimStackTrace()
{
return trimStackTrace;
}

public void setTrimStackTrace( boolean trimStackTrace )
{
this.trimStackTrace = trimStackTrace;
}

public boolean isPlainFormat()
{
return isPlainFormat;
}

public void setPlainFormat( boolean plainFormat )
{
isPlainFormat = plainFormat;
}

public boolean isBriefOrPlainFormat()
{
return briefOrPlainFormat;
}

public void setBriefOrPlainFormat( boolean briefOrPlainFormat )
{
this.briefOrPlainFormat = briefOrPlainFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
*/

import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton;
import org.apache.maven.surefire.extensions.ReportData;
import org.apache.maven.surefire.api.report.UniqueID;
import org.apache.maven.surefire.shared.utils.xml.PrettyPrintXMLWriter;
import org.apache.maven.surefire.shared.utils.xml.XMLWriter;
import org.apache.maven.surefire.extensions.StatelessReportEventListener;
import org.apache.maven.surefire.api.report.SafeThrowable;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -43,6 +44,7 @@
import java.util.concurrent.ConcurrentLinkedDeque;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.newOutputStream;
import static org.apache.maven.plugin.surefire.report.DefaultReporterFactory.TestResultType;
import static org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIllegalFilenameChars;
import static org.apache.maven.plugin.surefire.report.ReportEntryType.SKIPPED;
Expand Down Expand Up @@ -134,10 +136,22 @@ public StatelessXmlReporter( File reportsDirectory, String reportNameSuffix, boo
this.phrasedMethodName = phrasedMethodName;
}

@Override
public void testSetCompleted( UniqueID sourceId, ReportData testSetStats )
{
TestMethodCalls methodCalls = new TestMethodCalls();

testSetStats.filterOperations( sourceId )
.forEach( methodCalls::addOperation );

testSetStats.filterRerunOperations( sourceId )
.forEach( methodCalls::addRerunOperation );
}

@Override
public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStats testSetStats )
{
Map<String, Map<String, List<WrappedReportEntry>>> classMethodStatistics =
Map<UniqueID, Map<UniqueID, List<WrappedReportEntry>>> classMethodStatistics =
arrangeMethodStatistics( testSetReportEntry, testSetStats );

// The Java Language Spec:
Expand All @@ -151,9 +165,9 @@ public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStat

showProperties( ppw, testSetReportEntry.getSystemProperties() );

for ( Entry<String, Map<String, List<WrappedReportEntry>>> statistics : classMethodStatistics.entrySet() )
for ( Entry<UniqueID, Map<UniqueID, List<WrappedReportEntry>>> statistics : classMethodStatistics.entrySet() )
{
for ( Entry<String, List<WrappedReportEntry>> thisMethodRuns : statistics.getValue().entrySet() )
for ( Entry<UniqueID, List<WrappedReportEntry>> thisMethodRuns : statistics.getValue().entrySet() )
{
serializeTestClass( outputStream, fw, ppw, thisMethodRuns.getValue() );
}
Expand All @@ -171,38 +185,33 @@ public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStat
}
}

private Map<String, Map<String, List<WrappedReportEntry>>> arrangeMethodStatistics(
WrappedReportEntry testSetReportEntry, TestSetStats testSetStats )
private Map<UniqueID, Map<UniqueID, List<WrappedReportEntry>>> arrangeMethodStatistics(
UniqueID sourceId, TestMethodCalls methodCalls )
{
Map<String, Map<String, List<WrappedReportEntry>>> classMethodStatistics = new LinkedHashMap<>();
for ( WrappedReportEntry methodEntry : aggregateCacheFromMultipleReruns( testSetReportEntry, testSetStats ) )
Map<UniqueID, TestMethodCalls> methodStatistics = new LinkedHashMap<>();

for ( WrappedReportEntry methodEntry : methodCalls )
{
String testClassName = methodEntry.getSourceName();
Map<String, List<WrappedReportEntry>> stats = classMethodStatistics.get( testClassName );
if ( stats == null )
{
stats = new LinkedHashMap<>();
classMethodStatistics.put( testClassName, stats );
}
String methodName = methodEntry.getName();
List<WrappedReportEntry> methodRuns = stats.get( methodName );
if ( methodRuns == null )
{
methodRuns = new ArrayList<>();
stats.put( methodName, methodRuns );
}
UniqueID methodId = methodEntry.getTestRunUniqueId();

Map<UniqueID, List<WrappedReportEntry>> stats =
classMethodStatistics.computeIfAbsent( methodId.toSourceUniqueId(), k -> new LinkedHashMap<>() );

List<WrappedReportEntry> methodRuns =
stats.computeIfAbsent( methodId, k -> new ArrayList<>() );

methodRuns.add( methodEntry );
}
return classMethodStatistics;
}

private Deque<WrappedReportEntry> aggregateCacheFromMultipleReruns( WrappedReportEntry testSetReportEntry,
TestSetStats testSetStats )
TestSetStats testSetStats )
{
String suiteClassName = testSetReportEntry.getSourceName();
/*String suiteClassName = testSetReportEntry.getSourceName();
Deque<WrappedReportEntry> methodRunHistory = getAddMethodRunHistoryMap( suiteClassName );
methodRunHistory.addAll( testSetStats.getReportEntries() );
return methodRunHistory;
return methodRunHistory;*/
}

private void serializeTestClass( OutputStream outputStream, OutputStreamWriter fw, XMLWriter ppw,
Expand Down Expand Up @@ -364,7 +373,7 @@ private OutputStream getOutputStream( WrappedReportEntry testSetReportEntry )
reportFile.delete();
//noinspection ResultOfMethodCallIgnored
reportDir.mkdirs();
return new BufferedOutputStream( new FileOutputStream( reportFile ), 64 * 1024 );
return new BufferedOutputStream( newOutputStream( reportFile.toPath() ), 64 * 1024 );
}

private static OutputStreamWriter getWriter( OutputStream fos )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.apache.maven.plugin.surefire.report;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.maven.surefire.api.report.UniqueID;
import org.apache.maven.surefire.extensions.ReportData;
import org.apache.maven.surefire.extensions.testoperations.TestOperation;

import static java.util.stream.Collectors.toMap;

final class TestMethodCalls
{
private final ReportData reportData = new ReportData();

void addOperation( TestOperation<?> op )
{
reportData.addOperation( op );
}

void addRerunOperation( TestOperation<?> op )
{
reportData.addRetryOperation( op );
}

Map<UniqueID, ReportData> mapTestStats()
{
return reportData.getIds()
.stream()
.collect( toMap(
id -> id,
id ->
{
ReportData rep = new ReportData();
reportData.filterOperations( id ).forEach( rep::addOperation );
reportData.filterRerunOperations( id ).forEach( rep::addRetryOperation );
return rep;
}, (u, v) -> { throw new IllegalStateException(); }, LinkedHashMap::new ) );
}
}
Loading