You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2015/12/24 21:59:48 UTC
maven-surefire git commit: [SUREFIRE] simplified
"skipAfterFailureCount" implementation
Repository: maven-surefire
Updated Branches:
refs/heads/master 3be5c30d6 -> d891907a7
[SUREFIRE] simplified "skipAfterFailureCount" implementation
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/d891907a
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/d891907a
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/d891907a
Branch: refs/heads/master
Commit: d891907a72a7014f86818147e8efd6ec9877c936
Parents: 3be5c30
Author: Tibor17 <ti...@lycos.com>
Authored: Thu Dec 24 21:59:21 2015 +0100
Committer: Tibor17 <ti...@lycos.com>
Committed: Thu Dec 24 21:59:21 2015 +0100
----------------------------------------------------------------------
.../common/junit4/JUnit4ProviderUtil.java | 13 ++--
.../maven/surefire/common/junit4/Notifier.java | 49 ++++++++++++++-
.../maven/surefire/common/junit4/Stoppable.java | 35 -----------
.../surefire/junit4/JUnit4FailFastListener.java | 49 ---------------
.../maven/surefire/junit4/JUnit4Provider.java | 13 +---
.../junitcore/JUnit47FailFastListener.java | 66 --------------------
.../surefire/junitcore/JUnitCoreWrapper.java | 21 +++----
7 files changed, 63 insertions(+), 183 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java
index 0809b08..075d9d9 100644
--- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java
+++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4ProviderUtil.java
@@ -27,11 +27,14 @@ import java.util.Map;
import java.util.Set;
import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.internal.StringUtils;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
+import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createRequest;
+import static org.apache.maven.surefire.util.internal.StringUtils.isBlank;
+import static org.junit.runner.Description.TEST_MECHANISM;
+
/**
*
* Utility method used among all JUnit4 providers
@@ -108,14 +111,12 @@ public final class JUnit4ProviderUtil
public static Description createSuiteDescription( Collection<Class<?>> classes )
{
- return JUnit4Reflector.createRequest( classes.toArray( new Class[classes.size()] ) )
- .getRunner()
- .getDescription();
+ return createRequest( classes.toArray( new Class[classes.size()] ) ).getRunner().getDescription();
}
public static boolean isFailureInsideJUnitItself( Description failure )
{
- return Description.TEST_MECHANISM.equals( failure );
+ return TEST_MECHANISM.equals( failure );
}
/**
@@ -149,7 +150,7 @@ public final class JUnit4ProviderUtil
private static String tryBlank( String s )
{
s = s.trim();
- return StringUtils.isBlank( s ) ? null : s;
+ return isBlank( s ) ? null : s;
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Notifier.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Notifier.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Notifier.java
index 5748e4b..0cd8d98 100644
--- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Notifier.java
+++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Notifier.java
@@ -19,14 +19,20 @@ package org.apache.maven.surefire.common.junit4;
* under the License.
*/
+import org.junit.runner.Description;
+import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
+import org.junit.runner.notification.StoppedByUserException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
+import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.cutTestClassAndMethod;
import static org.apache.maven.surefire.util.internal.ConcurrencyUtils.countDownToZero;
/**
@@ -37,15 +43,19 @@ import static org.apache.maven.surefire.util.internal.ConcurrencyUtils.countDown
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
* @since 2.19
*/
-public class Notifier
- extends RunNotifier implements Stoppable
+public final class Notifier
+ extends RunNotifier
{
private final Collection<RunListener> listeners = new ArrayList<RunListener>();
+ private final Queue<String> testClassNames = new ConcurrentLinkedQueue<String>();
+
private final AtomicInteger skipAfterFailureCount;
private final JUnit4RunListener reporter;
+ private volatile boolean failFast;
+
public Notifier( JUnit4RunListener reporter, int skipAfterFailureCount )
{
addListener( reporter );
@@ -53,7 +63,35 @@ public class Notifier
this.skipAfterFailureCount = new AtomicInteger( skipAfterFailureCount );
}
- public void fireStopEvent()
+ public Notifier asFailFast( boolean failFast )
+ {
+ this.failFast = failFast;
+ return this;
+ }
+
+ @Override
+ public void fireTestStarted( Description description ) throws StoppedByUserException
+ {
+ // If fireTestStarted() throws exception (== skipped test), the class must not be removed from testClassNames.
+ // Therefore this class will be removed only if test class started with some test method.
+ super.fireTestStarted( description );
+ testClassNames.remove( cutTestClassAndMethod( description ).getClazz() );
+ }
+
+ @Override
+ public void fireTestFailure( Failure failure )
+ {
+ if ( failFast )
+ {
+ fireStopEvent();
+ }
+ super.fireTestFailure( failure );
+ }
+
+ /**
+ * Fire stop even to plugin process and/or call {@link org.junit.runner.notification.RunNotifier#pleaseStop()}.
+ */
+ private void fireStopEvent()
{
if ( countDownToZero( skipAfterFailureCount ) )
{
@@ -104,4 +142,9 @@ public class Notifier
super.removeListener( listener );
}
}
+
+ public Queue<String> getRemainingTestClasses()
+ {
+ return testClassNames;
+ }
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Stoppable.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Stoppable.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Stoppable.java
deleted file mode 100644
index 376d631..0000000
--- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/Stoppable.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.maven.surefire.common.junit4;
-
-/*
- * 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.
- */
-
-/**
- * Covers configuration parameter <em>skipAfterFailureCount</em>.
- *
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @since 2.19
- * @see org.apache.maven.surefire.common.junit4.Notifier
- */
-public interface Stoppable
-{
- /**
- * Fire stop even to plugin process and/or call {@link org.junit.runner.notification.RunNotifier#pleaseStop()}.
- */
- void fireStopEvent();
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4FailFastListener.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4FailFastListener.java b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4FailFastListener.java
deleted file mode 100644
index 84346e7..0000000
--- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4FailFastListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.apache.maven.surefire.junit4;
-
-/*
- * 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.surefire.common.junit4.Notifier;
-import org.apache.maven.surefire.common.junit4.Stoppable;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
-
-/**
- * Calling {@link Notifier#fireStopEvent()} if failure happens.
- *
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @since 2.19
- */
-final class JUnit4FailFastListener
- extends RunListener
-{
- private final Stoppable stoppable;
-
- JUnit4FailFastListener( Notifier stoppable )
- {
- this.stoppable = stoppable;
- }
-
- @Override
- public void testFailure( Failure failure )
- throws Exception
- {
- stoppable.fireStopEvent();
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
index b9df034..fa767eb 100644
--- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
+++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
@@ -272,23 +272,14 @@ public class JUnit4Provider
try
{
- JUnit4FailFastListener failFastListener = null;
- if ( isFailFast() )
- {
- failFastListener = new JUnit4FailFastListener( notifier );
- notifier.addListener( failFastListener );
- }
-
try
{
+ notifier.asFailFast( isFailFast() );
execute( clazz, notifier, hasMethodFilter ? new TestResolverFilter() : new NullFilter() );
}
finally
{
- if ( failFastListener != null )
- {
- notifier.removeListener( failFastListener );
- }
+ notifier.asFailFast( false );
}
// Rerun failing tests if rerunFailingTestsCount is larger than 0
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnit47FailFastListener.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnit47FailFastListener.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnit47FailFastListener.java
deleted file mode 100644
index 3ccb3d2..0000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnit47FailFastListener.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package org.apache.maven.surefire.junitcore;
-
-/*
- * 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.surefire.common.junit4.Stoppable;
-import org.junit.runner.Description;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-/**
- * Calling {@link Stoppable#fireStopEvent()} if failure happens.
- *
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @since 2.19
- */
-final class JUnit47FailFastListener
- extends RunListener
-{
- private final Stoppable stoppable;
-
- private final Queue<String> testClassNames = new ConcurrentLinkedQueue<String>();
-
- JUnit47FailFastListener( Stoppable stoppable )
- {
- this.stoppable = stoppable;
- }
-
- Queue<String> getRemainingTestClasses()
- {
- return testClassNames;
- }
-
- @Override
- public void testStarted( Description description )
- throws Exception
- {
- testClassNames.remove( description.getClassName() );
- }
-
- @Override
- public void testFailure( Failure failure )
- throws Exception
- {
- stoppable.fireStopEvent();
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d891907a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
index 83d06c5..7ae3e75 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
@@ -42,6 +42,8 @@ import java.util.Queue;
import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createDescription;
import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createIgnored;
import static org.apache.maven.surefire.common.junit4.JUnit4RunListener.rethrowAnyTestMechanismFailures;
+import static org.junit.runner.Computer.serial;
+import static org.junit.runner.Request.classes;
/**
* Encapsulates access to JUnitCore
@@ -124,7 +126,7 @@ final class JUnitCoreWrapper
private void createRequestAndRun( Filter filter, Computer computer, JUnitCore junitCore, Class<?>... classesToRun )
throws TestSetFailedException
{
- Request req = Request.classes( computer, classesToRun );
+ Request req = classes( computer, classesToRun );
if ( filter != null )
{
req = new FilteringRequest( req, filter );
@@ -151,23 +153,16 @@ final class JUnitCoreWrapper
private Computer createComputer()
{
return jUnitCoreParameters.isNoThreading()
- ? Computer.serial()
+ ? serial()
: new ParallelComputerBuilder( logger, jUnitCoreParameters ).buildComputer();
}
private final class JUnitCore
extends org.apache.maven.surefire.junitcore.JUnitCore
{
- private final JUnit47FailFastListener failFastListener;
-
JUnitCore()
{
- super( notifier );
- failFastListener = failFast ? new JUnit47FailFastListener( notifier ) : null;
- if ( failFastListener != null )
- {
- notifier.addListener( failFastListener );
- }
+ super( JUnitCoreWrapper.this.notifier.asFailFast( JUnitCoreWrapper.this.failFast ) );
}
JUnitCore withReportedTests( Class<?>... tests )
@@ -188,7 +183,7 @@ final class JUnitCoreWrapper
protected void afterException( Throwable e )
throws TestSetFailedException
{
- if ( failFast && e instanceof StoppedByUserException )
+ if ( JUnitCoreWrapper.this.failFast && e instanceof StoppedByUserException )
{
Queue<String> stoppedTests = getRemainingTestClasses();
if ( stoppedTests != null )
@@ -198,7 +193,7 @@ final class JUnitCoreWrapper
for ( String clazz; ( clazz = stoppedTests.poll() ) != null; )
{
Description skippedTest = createDescription( clazz, reasonForSkippedTest );
- notifier.fireTestIgnored( skippedTest );
+ JUnitCoreWrapper.this.notifier.fireTestIgnored( skippedTest );
}
}
}
@@ -220,7 +215,7 @@ final class JUnitCoreWrapper
private Queue<String> getRemainingTestClasses()
{
- return failFastListener == null ? null : failFastListener.getRemainingTestClasses();
+ return JUnitCoreWrapper.this.failFast ? JUnitCoreWrapper.this.notifier.getRemainingTestClasses() : null;
}
}
}