Skip to content

Commit

Permalink
[SUREFIRE] Using JUnit 4.12 Stopwatch in surefire-junit47
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor17 committed Apr 4, 2015
1 parent 7116043 commit 6d28e29
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 67 deletions.
2 changes: 1 addition & 1 deletion surefire-providers/surefire-junit47/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<version>4.12</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public final class OptimizedParallelComputerTest
@Rule
public final ExpectedException exception = ExpectedException.none();

@Rule
public final Stopwatch runtime = new Stopwatch();

@BeforeClass
public static void beforeClass()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Stopwatch;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
Expand All @@ -48,6 +49,7 @@
import static org.hamcrest.core.IsNot.not;
import static org.apache.maven.surefire.junitcore.pc.RangeMatcher.between;
import static org.junit.Assert.*;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
* @author Tibor Digana (tibor17)
Expand All @@ -62,7 +64,7 @@ public class ParallelComputerBuilderTest
private static volatile Runnable shutdownTask;

@Rule
public final Stopwatch runtime = new Stopwatch();
public final Stopwatch stopwatch = new Stopwatch() {};

private static void testKeepBeforeAfter( ParallelComputerBuilder builder, Class<?>... classes )
{
Expand Down Expand Up @@ -118,7 +120,7 @@ public void parallelMethodsReuseOneOrTwoThreads()

ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 0 ) );
Expand Down Expand Up @@ -153,7 +155,7 @@ public void suiteAndClassInOnePool()

ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 1 ) );
Expand All @@ -179,7 +181,7 @@ public void onePoolWithUnlimitedParallelMethods()

ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 1 ) );
Expand Down Expand Up @@ -211,7 +213,7 @@ public void underflowParallelism()

ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 0 ) );
Expand All @@ -235,7 +237,7 @@ public void separatePoolsWithSuite()

ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 0 ) );
Expand All @@ -262,7 +264,7 @@ public void separatePoolsWithSuiteAndClass()
// Each group takes 0.5s.
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 1 ) );
Expand All @@ -286,7 +288,7 @@ public void separatePoolsWithSuiteAndSequentialClasses()

ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );

assertThat( computer.suites.size(), is( 1 ) );
assertThat( computer.classes.size(), is( 1 ) );
Expand All @@ -303,7 +305,7 @@ public void separatePoolsWithSuiteAndSequentialClasses()
public void shutdown()
{
Result result = new ShutdownTest().run( false );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
assertTrue( result.wasSuccessful() );
assertTrue( beforeShutdown );
assertThat( timeSpent, between( 450, 1250 ) );
Expand All @@ -313,7 +315,7 @@ public void shutdown()
public void shutdownWithInterrupt()
{
new ShutdownTest().run( true );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
assertTrue( beforeShutdown );
assertThat( timeSpent, between( 450, 1250 ) );
}
Expand Down Expand Up @@ -536,7 +538,7 @@ private static Collection<Thread> jvmThreads()
Thread.enumerate( t );
ArrayList<Thread> appThreads = new ArrayList<Thread>( t.length );
Collections.addAll( appThreads, t );
appThreads.removeAll( Collections.singleton( null ) );
appThreads.removeAll( Collections.singleton( (Thread) null ) );
Collections.sort( appThreads, new Comparator<Thread>()
{
public int compare( Thread t1, Thread t2 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.rules.ExpectedException;
import org.junit.rules.Stopwatch;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
Expand All @@ -42,6 +43,7 @@
import static org.apache.maven.surefire.junitcore.JUnitCoreParameters.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
* Testing an algorithm in {@link ParallelComputerUtil} which configures
Expand All @@ -64,7 +66,7 @@ public final class ParallelComputerUtilTest
public final ExpectedException exception = ExpectedException.none();

@Rule
public final Stopwatch runtime = new Stopwatch();
public final Stopwatch stopwatch = new Stopwatch() {};

@BeforeClass
public static void beforeClass()
Expand Down Expand Up @@ -969,7 +971,7 @@ public void withoutShutdown()
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
ParallelComputer pc = pcBuilder.buildComputer();
Result result = new JUnitCore().run( pc, TestClass.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
long deltaTime = 500L;

assertTrue( result.wasSuccessful() );
Expand All @@ -993,7 +995,7 @@ public void shutdown()
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
ParallelComputer pc = pcBuilder.buildComputer();
new JUnitCore().run( pc, TestClass.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
long deltaTime = 500L;

assertEquals( 5000L, timeSpent, deltaTime );
Expand All @@ -1016,7 +1018,7 @@ public void forcedShutdown()
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
ParallelComputer pc = pcBuilder.buildComputer();
new JUnitCore().run( pc, TestClass.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
long deltaTime = 500L;

assertEquals( 2500L, timeSpent, deltaTime );
Expand All @@ -1042,7 +1044,7 @@ public void timeoutAndForcedShutdown()
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
ParallelComputer pc = pcBuilder.buildComputer();
new JUnitCore().run( pc, TestClass.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
long deltaTime = 500L;

assertEquals( 3500L, timeSpent, deltaTime );
Expand All @@ -1066,7 +1068,7 @@ public void forcedTimeoutAndShutdown()
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
ParallelComputer pc = pcBuilder.buildComputer();
new JUnitCore().run( pc, TestClass.class );
long timeSpent = runtime.stop();
long timeSpent = stopwatch.runtime( MILLISECONDS );
long deltaTime = 500L;

assertEquals( 3500L, timeSpent, deltaTime );
Expand Down

This file was deleted.

0 comments on commit 6d28e29

Please sign in to comment.