Author: krosenvold
Date: Tue Nov 30 19:09:23 2010
New Revision: 1040706
URL: http://svn.apache.org/viewvc?rev=1040706&view=rev
Log:
[SUREFIRE-661] Added ConfigurableParallelComputer
Added:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputer.java
(with props)
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
(with props)
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
(with props)
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml?rev=1040706&r1=1040705&r2=1040706&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml Tue Nov 30
19:09:23 2010
@@ -35,7 +35,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.7</version>
+ <version>4.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Added:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputer.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputer.java?rev=1040706&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputer.java
(added)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputer.java
Tue Nov 30 19:09:23 2010
@@ -0,0 +1,219 @@
+/*
+ * 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.
+ */
+package org.apache.maven.surefire.junitcore;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.junit.runner.Computer;
+import org.junit.runner.Runner;
+import org.junit.runners.ParentRunner;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+import org.junit.runners.model.RunnerScheduler;
+
+/*
+ * @author Kristian Rosenvold
+ */
+public class ConfigurableParallelComputer
+ extends Computer
+{
+ private final boolean fClasses;
+
+ private final boolean fMethods;
+
+ private final boolean fixedPool;
+
+ private final ExecutorService fService;
+
+ private final List<AsynchronousRunner> nonBlockers =
+ Collections.synchronizedList( new ArrayList<AsynchronousRunner>() );
+
+
+ public ConfigurableParallelComputer()
+ {
+ this( true, true, Executors.newCachedThreadPool(), false );
+ }
+
+ public ConfigurableParallelComputer(boolean fClasses, boolean fMethods) {
+ this ( fClasses, fMethods, Executors.newCachedThreadPool(), false);
+ }
+
+ public ConfigurableParallelComputer( boolean fClasses, boolean fMethods,
Integer numberOfThreads, boolean perCore )
+ {
+ this( fClasses, fMethods, Executors.newFixedThreadPool(
+ numberOfThreads * ( perCore ?
Runtime.getRuntime().availableProcessors() : 1 ) ), true );
+ }
+
+ private ConfigurableParallelComputer( boolean fClasses, boolean fMethods,
ExecutorService executorService,
+ boolean fixedPool )
+ {
+ this.fClasses = fClasses;
+ this.fMethods = fMethods;
+ fService = executorService;
+ this.fixedPool = fixedPool;
+ }
+
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ public void close()
+ throws ExecutionException
+ {
+ for ( AsynchronousRunner nonBlocker : nonBlockers )
+ {
+ nonBlocker.waitForCompletion();
+ }
+
+ fService.shutdown();
+ try
+ {
+ fService.awaitTermination( 10,
java.util.concurrent.TimeUnit.SECONDS );
+ }
+ catch ( InterruptedException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+
+ private Runner parallelize( Runner runner, RunnerScheduler
runnerInterceptor )
+ {
+ if ( runner instanceof ParentRunner<?> )
+ {
+ ( (ParentRunner<?>) runner ).setScheduler( runnerInterceptor );
+ }
+ return runner;
+ }
+
+ private RunnerScheduler getMethodInterceptor()
+ {
+ if ( fClasses && fMethods )
+ {
+ final AsynchronousRunner blockingAsynchronousRunner = new
AsynchronousRunner( fService );
+ nonBlockers.add( blockingAsynchronousRunner );
+ return blockingAsynchronousRunner;
+ }
+ return fMethods ? new AsynchronousRunner( fService ) : new
SynchronousRunner();
+ }
+
+ private RunnerScheduler getClassInterceptor()
+ {
+ if ( fClasses )
+ {
+ return fMethods ? new SynchronousRunner() : new
AsynchronousRunner( fService );
+ }
+ return new SynchronousRunner();
+ }
+
+ @Override
+ public Runner getSuite( RunnerBuilder builder, java.lang.Class<?>[]
classes )
+ throws InitializationError
+ {
+ Runner suite = super.getSuite( builder, classes );
+ return fClasses ? parallelize( suite, getClassInterceptor() ) : suite;
+ }
+
+ @Override
+ protected Runner getRunner( RunnerBuilder builder, Class<?> testClass )
+ throws Throwable
+ {
+ Runner runner = super.getRunner( builder, testClass );
+ return fMethods ? parallelize( runner, getMethodInterceptor() ) :
runner;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ConfigurableParallelComputer{" + "classes=" + fClasses + ",
methods=" + fMethods + ", fixedPool=" +
+ fixedPool + '}';
+ }
+
+ public class SynchronousRunner
+ implements RunnerScheduler
+ {
+ public void schedule( final Runnable childStatement )
+ {
+ childStatement.run();
+ }
+
+ public void finished()
+ {
+ }
+ }
+
+ public class AsynchronousRunner
+ implements RunnerScheduler
+ {
+ private final List<Future<Object>> futures =
Collections.synchronizedList( new ArrayList<Future<Object>>() );
+
+ private final ExecutorService fService;
+
+ public AsynchronousRunner( ExecutorService fService )
+ {
+ this.fService = fService;
+ }
+
+ public void schedule( final Runnable childStatement )
+ {
+ final Callable<Object> objectCallable = new Callable<Object>()
+ {
+ public Object call()
+ throws Exception
+ {
+ childStatement.run();
+ return null;
+ }
+ };
+ futures.add( fService.submit( objectCallable ) );
+ }
+
+
+ public void finished()
+ {
+ try
+ {
+ waitForCompletion();
+ }
+ catch ( ExecutionException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+
+ public void waitForCompletion()
+ throws ExecutionException
+ {
+ for ( Future<Object> each : futures )
+ {
+ try
+ {
+ each.get();
+ }
+ catch ( InterruptedException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+ }
+ }
+}
Propchange:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java?rev=1040706&r1=1040705&r2=1040706&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
Tue Nov 30 19:09:23 2010
@@ -34,8 +34,6 @@ class JUnitCoreParameters
private final Boolean useUnlimitedThreads;
- private final Boolean configurableParallelComputerPresent;
-
public static final String PARALLEL_KEY = "parallel";
public static final String PERCORETHREADCOUNT_KEY = "perCoreThreadCount";
@@ -44,8 +42,6 @@ class JUnitCoreParameters
public static final String USEUNLIMITEDTHREADS_KEY = "useUnlimitedThreads";
- public static final String CONFIGURABLEPARALLELCOMPUTERPRESENT_KEY =
"configurableParallelComputerPresent";
-
public JUnitCoreParameters( Properties properties )
{
@@ -54,8 +50,6 @@ class JUnitCoreParameters
this.threadCount = Integer.valueOf( properties.getProperty(
THREADCOUNT_KEY, "8" ) );
this.useUnlimitedThreads =
Boolean.valueOf( properties.getProperty( USEUNLIMITEDTHREADS_KEY,
"false" ).toLowerCase() );
- this.configurableParallelComputerPresent =
- Boolean.valueOf( properties.getProperty(
CONFIGURABLEPARALLELCOMPUTERPRESENT_KEY, "false" ).toLowerCase() );
}
public boolean isParallelMethod()
@@ -98,16 +92,10 @@ class JUnitCoreParameters
return !isNoThreading();
}
- public Boolean isConfigurableParallelComputerPresent()
- {
- return configurableParallelComputerPresent;
- }
-
@Override
public String toString()
{
return "JUnitCoreParameters{" + "parallel='" + parallel + '\'' + ",
perCoreThreadCount=" + perCoreThreadCount +
- ", threadCount=" + threadCount + ", useUnlimitedThreads=" +
useUnlimitedThreads +
- ", configurableParallelComputerPresent=" +
configurableParallelComputerPresent + '}';
+ ", threadCount=" + threadCount + ", useUnlimitedThreads=" +
useUnlimitedThreads + '}';
}
}
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java?rev=1040706&r1=1040705&r2=1040706&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
Tue Nov 30 19:09:23 2010
@@ -21,12 +21,10 @@ package org.apache.maven.surefire.junitc
import org.apache.maven.surefire.report.ReporterManagerFactory;
import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.junit.experimental.ParallelComputer;
import org.junit.runner.Computer;
import org.junit.runner.JUnitCore;
import org.junit.runner.notification.RunListener;
-import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -43,7 +41,7 @@ class JUnitCoreTestSet
{
private final Class testClass;
- private static final String className =
"org.jdogma.junit.ConfigurableParallelComputer";
+ private static final String className =
"org.apache.maven.surefire.junitcore.ConfigurableParallelComputer";
public String getName()
{
@@ -137,64 +135,22 @@ class JUnitCoreTestSet
{
return new Computer();
}
- return jUnitCoreParameters.isConfigurableParallelComputerPresent() ?
getConfigurableParallelComputer(
- jUnitCoreParameters ) : getParallelComputer( jUnitCoreParameters );
- }
-
- private static Computer getParallelComputer( JUnitCoreParameters
JUnitCoreParameters )
- {
- if ( JUnitCoreParameters.isUseUnlimitedThreads() )
- {
- return new ParallelComputer( true, true );
- }
- else
- {
- return new ParallelComputer(
JUnitCoreParameters.isParallelClasses(),
-
JUnitCoreParameters.isParallelMethod() );
- }
+ return getConfigurableParallelComputer( jUnitCoreParameters );
}
private static Computer getConfigurableParallelComputer(
JUnitCoreParameters JUnitCoreParameters )
throws TestSetFailedException
{
-
- try
- {
- Class<?> cpcClass = Class.forName( className );
- if ( JUnitCoreParameters.isUseUnlimitedThreads() )
- {
- Constructor<?> constructor = cpcClass.getConstructor();
- return (Computer) constructor.newInstance();
- }
- else
- {
- Constructor<?> constructor =
- cpcClass.getConstructor( boolean.class, boolean.class,
Integer.class, boolean.class );
- return (Computer) constructor.newInstance(
JUnitCoreParameters.isParallelClasses(),
-
JUnitCoreParameters.isParallelMethod(),
-
JUnitCoreParameters.getThreadCount(),
-
JUnitCoreParameters.isPerCoreThreadCount() );
- }
- }
- catch ( ClassNotFoundException e )
- {
- throw new TestSetFailedException( e );
- }
- catch ( NoSuchMethodException e )
- {
- throw new TestSetFailedException( e );
- }
- catch ( InvocationTargetException e )
- {
- throw new TestSetFailedException( e );
- }
- catch ( InstantiationException e )
+ if ( JUnitCoreParameters.isUseUnlimitedThreads() )
{
- throw new TestSetFailedException( e );
+ return new ConfigurableParallelComputer();
}
- catch ( IllegalAccessException e )
+ else
{
- throw new TestSetFailedException( e );
+ return new ConfigurableParallelComputer(
JUnitCoreParameters.isParallelClasses(),
+
JUnitCoreParameters.isParallelMethod(),
+
JUnitCoreParameters.getThreadCount(),
+
JUnitCoreParameters.isPerCoreThreadCount() );
}
}
Added:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java?rev=1040706&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
(added)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
Tue Nov 30 19:09:23 2010
@@ -0,0 +1,346 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.surefire.junitcore;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.experimental.ParallelComputer;
+import org.junit.runner.Computer;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.notification.RunListener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Simple test of ConfigurableParallelComputer.
+ *
+ * @author Kristian Rosenvold
+ */
+public class ConfigurableParallelComputerTest
+ extends TestCase
+{
+ private static final int NUMTESTS = 1000;
+
+ // I'm sorry about all the sout's in this test; but if you deadlock when
building you will appreciate it.
+
+ @Test
+ public void testAnythingYouWantToPlayWith()
+ throws Exception
+ {
+ Result result = new Result();
+ Class[] realClasses = new Class[]{ Dummy.class, Dummy2.class };
+
+ DiagnosticRunListener diagnosticRunListener = new
DiagnosticRunListener( false, result.createListener() );
+ JUnitCore jUnitCore = getJunitCore( diagnosticRunListener );
+ ConfigurableParallelComputer computer = new
ConfigurableParallelComputer( true, false );
+ jUnitCore.run( computer, realClasses );
+ computer.close();
+ assertEquals( "All tests should succeed, right ?", 5,
result.getRunCount() );
+ }
+
+ @Test
+ public void testOneMethod()
+ throws ExecutionException
+ {
+ JUnitCore jUnitCore = new JUnitCore();
+ ConfigurableParallelComputer computer = new
ConfigurableParallelComputer( false, true );
+ jUnitCore.run( computer, new Class[]{ Dummy.class, Dummy.class,
Dummy.class } );
+ computer.close();
+ }
+
+ @Test
+ public void testSerial()
+ throws Exception
+ {
+ Result result = new Result();
+ Class[] realClasses = getClassList();
+ JUnitCore jUnitCore = getJunitCore( result );
+ Computer computer = new Computer();
+ timedRun( NUMTESTS, result, realClasses, jUnitCore, computer );
+ }
+
+
+ @Test
+ public void testFullTestRunPC()
+ throws Exception
+ {
+ Result result = new Result();
+ Class[] realClasses = getClassList();
+ JUnitCore jUnitCore = getJunitCore( result );
+ Computer computer = new ConfigurableParallelComputer( true, true );
+ timedRun( NUMTESTS, result, realClasses, jUnitCore, computer );
+ }
+
+ @Test
+ public void testWithFailingAssertionCPC()
+ throws Exception
+ {
+ runWithFailingAssertion( new ConfigurableParallelComputer( false,
true, 6, true ) );
+ runWithFailingAssertion( new ConfigurableParallelComputer( true,
false, 12, false ) );
+ runWithFailingAssertion( new ConfigurableParallelComputer( true, true,
2, false ) );
+ }
+
+ @Test
+ public void testWithSlowTestJustAfew()
+ throws Exception
+ {
+ Result result = new Result();
+ final Computer computer = new ConfigurableParallelComputer( false,
true, 3, false );
+ Class[] realClasses = getClassList( SlowTest.class, 5 ); // 300 ms in
methods, 600 in classes
+
+ JUnitCore jUnitCore = getJunitCore( result );
+ runIt( realClasses, jUnitCore, computer );
+ }
+
+ @Test
+ public void testWithFailingAssertionC()
+ throws Exception
+ {
+ final ParallelComputer computer = new ParallelComputer( false, true );
+ runWithFailingAssertion( computer );
+ runWithFailingAssertion( new ParallelComputer( true, false ) );
+ }
+
+
+ private void runWithFailingAssertion( Computer computer )
+ throws ExecutionException
+ {
+ Result result = new Result();
+ Class[] realClasses = getClassList( FailingAssertions.class );
+ JUnitCore jUnitCore = getJunitCore( result );
+ runIt( realClasses, jUnitCore, computer );
+ assertEquals( "No tests should fail, right ?", NUMTESTS,
result.getFailures().size() );
+ assertEquals( "All tests should succeed, right ?", 0,
result.getIgnoreCount() );
+ assertEquals( "All tests should succeed, right ?", NUMTESTS * 3,
result.getRunCount() );
+ }
+
+ @Test
+ public void testWithFailure()
+ throws Exception
+ {
+ Computer computer = new ConfigurableParallelComputer( false, true, 4,
true );
+ Result result = new Result();
+ Class[] realClasses = getClassList( Failure.class );
+ JUnitCore jUnitCore = getJunitCore( result );
+ runIt( realClasses, jUnitCore, computer );
+ assertEquals( "No tests should fail, right ?", NUMTESTS,
result.getFailures().size() );
+ assertEquals( "All tests should succeed, right ?", 0,
result.getIgnoreCount() );
+ assertEquals( "All tests should succeed, right ?", NUMTESTS * 3,
result.getRunCount() );
+ }
+
+ @Test
+ public void testFixedThreadPool()
+ throws Exception
+ {
+ Result result = new Result();
+ Class[] realClasses = getClassList();
+ JUnitCore jUnitCore = getJunitCore( result );
+ ConfigurableParallelComputer computer = new
ConfigurableParallelComputer( false, true, 2, false );
+ long resp = timedRun( NUMTESTS, result, realClasses, jUnitCore,
computer );
+ }
+
+ @Test
+ public void testClassesUnlimited()
+ throws Exception
+ {
+ Result result = new Result();
+ Class[] realClasses = getClassList();
+ JUnitCore jUnitCore = getJunitCore( result );
+ ConfigurableParallelComputer computer = new
ConfigurableParallelComputer( true, false );
+ timedRun( NUMTESTS, result, realClasses, jUnitCore, computer );
+ }
+
+ @Test
+ public void testBothUnlimited()
+ throws Exception
+ {
+ Result result = new Result();
+ Class[] realClasses = getClassList();
+ DiagnosticRunListener diagnosticRunListener = new
DiagnosticRunListener( false, result.createListener() );
+ JUnitCore jUnitCore = getJunitCore( diagnosticRunListener );
+ ConfigurableParallelComputer computer = new
ConfigurableParallelComputer( true, true );
+ timedRun( NUMTESTS, result, realClasses, jUnitCore, computer );
+ }
+
+ private JUnitCore getJunitCore( Result result )
+ {
+ RunListener listener = result.createListener();
+ JUnitCore jUnitCore = new JUnitCore();
+ jUnitCore.addListener( listener );
+ return jUnitCore;
+ }
+
+ private JUnitCore getJunitCore( RunListener listener )
+ {
+ JUnitCore jUnitCore = new JUnitCore();
+ jUnitCore.addListener( listener );
+ return jUnitCore;
+ }
+
+ private long runIt( Class[] realClasses, JUnitCore jUnitCore, Computer
computer )
+ throws ExecutionException
+ {
+ long start = System.currentTimeMillis();
+ jUnitCore.run( computer, realClasses );
+ if ( computer instanceof ConfigurableParallelComputer )
+ {
+ ( (ConfigurableParallelComputer) computer ).close();
+ }
+ long rsult = System.currentTimeMillis() - start;
+ return rsult;
+ }
+
+ private long timedRun( int NUMTESTS, Result result, Class[] realClasses,
JUnitCore jUnitCore, Computer computer )
+ throws ExecutionException
+ {
+ long time = runIt( realClasses, jUnitCore, computer );
+ assertEquals( "No tests should fail, right ?", 0,
result.getFailures().size() );
+ assertEquals( "All tests should succeed, right ?", 0,
result.getIgnoreCount() );
+ assertEquals( "All tests should succeed, right ?", NUMTESTS * 3,
result.getRunCount() );
+ return time;
+ }
+
+ private Class[] getClassList()
+ {
+ return getClassList( Dummy.class, NUMTESTS );
+ }
+
+ private Class[] getClassList( Class testClass )
+ {
+ return getClassList( testClass, NUMTESTS );
+ }
+
+ private Class[] getClassList( Class testClass, int numItems )
+ {
+ List<Class> realClasses = new ArrayList<Class>();
+ for ( int i = 0; i < numItems; i++ )
+ {
+ realClasses.add( testClass );
+ }
+ return realClasses.toArray( new Class[realClasses.size()] );
+ }
+
+ public static class Dummy
+ {
+ @Test
+ public void testNotMuch()
+ {
+ }
+
+ @Test
+ public void testStub1()
+ {
+ // Add your code here
+ }
+
+ @Test
+ public void testStub2()
+ {
+ // Add your code here
+ }
+ }
+
+ public static class Dummy2
+ {
+ @Test
+ public void testNotMuch()
+ {
+
+ }
+
+ @Test
+ public void testDummy2()
+ {
+ // Add your code here
+ }
+ }
+
+ public static class SlowTest
+ {
+ final int scaling = 100;
+
+ @Test
+ public void testNotMuch()
+ throws InterruptedException
+ {
+ Thread.sleep( scaling );
+ }
+
+ @Test
+ public void testNotMuch2()
+ throws InterruptedException
+ {
+ Thread.sleep( 3 * scaling );
+ }
+
+ @Test
+ public void testNotMuch3()
+ throws InterruptedException
+ {
+ Thread.sleep( 2 * scaling );
+ }
+
+
+ }
+
+ public static class FailingAssertions
+ {
+ @Test
+ public void testNotMuch()
+ {
+ }
+
+ @Test
+ public void testNotMuch2()
+ {
+ }
+
+ @Test
+ public void testWithFail()
+ {
+ fail( "We excpect this" );
+ }
+ }
+
+ public static class Failure
+ {
+ @Test
+ public void testNotMuch()
+ {
+ }
+
+ @Test
+ public void testNotMuch2()
+ {
+ }
+
+
+ @Test
+ public void testWithException()
+ {
+ throw new RuntimeException( "We expect this" );
+ }
+
+
+ }
+}
\ No newline at end of file
Propchange:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java?rev=1040706&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
(added)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
Tue Nov 30 19:09:23 2010
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2002-2009 the original author or authors.
+ *
+ * Licensed 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.
+ *
+ * Also licensed under CPL http://junit.sourceforge.net/cpl-v10.html
+ */
+
+
+package org.apache.maven.surefire.junitcore;
+
+import org.junit.runner.notification.RunListener;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+
+import java.util.concurrent.atomic.AtomicInteger;
+/*
+ * @author Kristian Rosenvold, kristianAzeniorD0Tno
+ */
+
+public class DiagnosticRunListener extends RunListener {
+ private final AtomicInteger numTestStarted = new AtomicInteger();
+ private final AtomicInteger numTestFailed = new AtomicInteger();
+ private final AtomicInteger numTestAssumptionsFailed = new
AtomicInteger();
+ private final AtomicInteger numTestFinished = new AtomicInteger();
+ private final AtomicInteger numTestIgnored = new AtomicInteger();
+ private final boolean printToConsole;
+ private final RunListener target;
+
+
+ public AtomicInteger getNumTestStarted() {
+ return numTestStarted;
+ }
+
+ public AtomicInteger getNumTestFailed() {
+ return numTestFailed;
+ }
+
+ public AtomicInteger getNumTestAssumptionsFailed() {
+ return numTestAssumptionsFailed;
+ }
+
+ public AtomicInteger getNumTestFinished() {
+ return numTestFinished;
+ }
+
+ public AtomicInteger getNumTestIgnored() {
+ return numTestIgnored;
+ }
+
+ private void print(String event, Description description) {
+ if (printToConsole)
System.out.println(Thread.currentThread().toString() + ", event = " + event +
", " + description);
+ }
+ private void print(String event, Result description) {
+ if (printToConsole)
System.out.println(Thread.currentThread().toString() + ", event = " + event +
", " + description);
+ }
+ private void print(String event, Failure description) {
+ if (printToConsole)
System.out.println(Thread.currentThread().toString() + ", event = " + event +
", " + description);
+ }
+
+ public DiagnosticRunListener(boolean printToConsole, RunListener target) {
+ this.printToConsole = printToConsole;
+ this.target = target;
+ }
+
+ public DiagnosticRunListener(boolean printToConsole) {
+ this( printToConsole, null);
+ }
+
+ public DiagnosticRunListener() {
+ this(true);
+ }
+
+ @Override
+ public void testRunStarted(Description description) throws Exception {
+ print("testRunStarted", description);
+ if (target != null) target.testRunStarted( description);
+ }
+
+ @Override
+ public void testRunFinished(Result result) throws Exception {
+ print("testRunFinished", result);
+ if (target != null) target.testRunFinished( result);
+
+ }
+
+ @Override
+ public void testStarted(Description description) throws Exception {
+ numTestStarted.incrementAndGet();
+ print("testStarted", description);
+ if (target != null) target.testStarted( description);
+ }
+
+ @Override
+ public void testFinished(Description description) throws Exception {
+ numTestFinished.incrementAndGet();
+ print("testFinished", description);
+ if (target != null) target.testFinished( description);
+ }
+
+ @Override
+ public void testFailure(Failure failure) throws Exception {
+ numTestFailed.incrementAndGet();
+ print("testFailure", failure);
+ if (target != null) target.testFailure( failure);
+ }
+
+ @Override
+ public void testAssumptionFailure(Failure failure) {
+ numTestAssumptionsFailed.incrementAndGet();
+ print("testAssumptionFailure", failure);
+ if (target != null) target.testAssumptionFailure( failure);
+ }
+
+ @Override
+ public void testIgnored(Description description) throws Exception {
+ numTestIgnored.incrementAndGet();
+ print("testIgnored", description);
+ if (target != null) target.testIgnored( description);
+ }
+
+ @Override
+ public String toString() {
+ return "DiagnosticRunListener{" +
+ "numTestIgnored=" + numTestIgnored +
+ ", numTestStarted=" + numTestStarted +
+ ", numTestFailed=" + numTestFailed +
+ ", numTestAssumptionsFailed=" + numTestAssumptionsFailed +
+ ", numTestFinished=" + numTestFinished +
+ '}';
+ }
+}
Propchange:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java?rev=1040706&r1=1040705&r2=1040706&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java
Tue Nov 30 19:09:23 2010
@@ -103,14 +103,6 @@ public class JUnitCoreParametersTest
assertTrue( getTestSetBoth().isAnyParallelitySelected() );
}
- @Test
- public void testIsConfigurableParallelComputerPresent()
- throws Exception
- {
- assertFalse(
getTestSetClasses().isConfigurableParallelComputerPresent() );
- assertFalse(
getTestSetMethods().isConfigurableParallelComputerPresent() );
- assertTrue( getTestSetBoth().isConfigurableParallelComputerPresent() );
- }
@Test
public void testToString()
@@ -127,7 +119,6 @@ public class JUnitCoreParametersTest
props.setProperty( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false"
);
props.setProperty( JUnitCoreParameters.THREADCOUNT_KEY, "2" );
props.setProperty( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY,
"false" );
- props.setProperty(
JUnitCoreParameters.CONFIGURABLEPARALLELCOMPUTERPRESENT_KEY, "false" );
return props;
}
@@ -138,7 +129,6 @@ public class JUnitCoreParametersTest
props.setProperty( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false"
);
props.setProperty( JUnitCoreParameters.THREADCOUNT_KEY, "2" );
props.setProperty( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "true"
);
- props.setProperty(
JUnitCoreParameters.CONFIGURABLEPARALLELCOMPUTERPRESENT_KEY, "false" );
return props;
}
@@ -149,7 +139,6 @@ public class JUnitCoreParametersTest
props.setProperty( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "true"
);
props.setProperty( JUnitCoreParameters.THREADCOUNT_KEY, "7" );
props.setProperty( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY,
"false" );
- props.setProperty(
JUnitCoreParameters.CONFIGURABLEPARALLELCOMPUTERPRESENT_KEY, "true" );
return props;
}