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 2014/10/08 00:55:01 UTC

git commit: [SUREFIRE-1082] Parallelization does not work as expected when using jUnit Parameterized

Repository: maven-surefire
Updated Branches:
  refs/heads/master 99438ac9d -> 1c2698a75


[SUREFIRE-1082] Parallelization does not work as expected when using jUnit Parameterized


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/1c2698a7
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/1c2698a7
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/1c2698a7

Branch: refs/heads/master
Commit: 1c2698a7527401a4a68a97e905886075fe6c4efa
Parents: 99438ac
Author: tibordigana <ti...@lycos.com>
Authored: Wed Oct 8 00:34:53 2014 +0200
Committer: tibordigana <ti...@lycos.com>
Committed: Wed Oct 8 00:34:53 2014 +0200

----------------------------------------------------------------------
 ...urefire1082ParallelJUnitParameterizedIT.java | 87 ++++++++++++++++++++
 .../pom.xml                                     | 63 ++++++++++++++
 .../java/jiras/surefire1082/Jira1082Test.java   | 60 ++++++++++++++
 3 files changed, 210 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1c2698a7/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java
new file mode 100644
index 0000000..5beab2c
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1082ParallelJUnitParameterizedIT.java
@@ -0,0 +1,87 @@
+package org.apache.maven.surefire.its.jiras;
+
+/*
+ * 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.it.VerificationException;
+import org.apache.maven.surefire.its.fixture.OutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.AnyOf.anyOf;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author <a href="mailto:tibor.digana@gmail.com">Tibor Digana (tibor17)</a>
+ * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-1082}
+ * @since 2.18
+ */
+public class Surefire1082ParallelJUnitParameterizedIT
+    extends SurefireJUnit4IntegrationTestCase
+{
+
+    @Test
+    public void test()
+        throws VerificationException
+    {
+        OutputValidator validator = unpack().setTestToRun(
+            "Jira1082Test" ).parallelClasses().useUnlimitedThreads().executeTest().verifyErrorFree( 4 );
+
+        Set<String> log = printOnlyTestLines( validator );
+        assertThat( log.size(), is( 4 ) );
+
+        Set<String> expectedLogs1 = new TreeSet<String>();
+        expectedLogs1.add( "class jiras.surefire1082.Jira1082Test a 0 pool-1-thread-1" );
+        expectedLogs1.add( "class jiras.surefire1082.Jira1082Test b 0 pool-1-thread-1" );
+        expectedLogs1.add( "class jiras.surefire1082.Jira1082Test a 1 pool-1-thread-2" );
+        expectedLogs1.add( "class jiras.surefire1082.Jira1082Test b 1 pool-1-thread-2" );
+
+        Set<String> expectedLogs2 = new TreeSet<String>();
+        expectedLogs2.add( "class jiras.surefire1082.Jira1082Test a 1 pool-1-thread-1" );
+        expectedLogs2.add( "class jiras.surefire1082.Jira1082Test b 1 pool-1-thread-1" );
+        expectedLogs2.add( "class jiras.surefire1082.Jira1082Test a 0 pool-1-thread-2" );
+        expectedLogs2.add( "class jiras.surefire1082.Jira1082Test b 0 pool-1-thread-2" );
+
+        assertThat( log, anyOf( is( expectedLogs1 ), is( expectedLogs2 ) ) );
+    }
+
+    private SurefireLauncher unpack()
+    {
+        return unpack( "surefire-1082-parallel-junit-parameterized" );
+    }
+
+    private static Set<String> printOnlyTestLines( OutputValidator validator )
+        throws VerificationException
+    {
+        Set<String> log = new TreeSet<String>( validator.loadLogLines() );
+        for ( Iterator<String> it = log.iterator(); it.hasNext(); ) {
+            String line = it.next();
+            if ( !line.startsWith( "class jiras.surefire1082." ) ) {
+                it.remove();
+            }
+        }
+        return log;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1c2698a7/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/pom.xml b/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/pom.xml
new file mode 100644
index 0000000..3c475c7
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>it-parent</artifactId>
+    <version>1.0</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>jiras-surefire-1082</artifactId>
+  <version>1.0</version>
+  <url>http://maven.apache.org</url>
+  <contributors>
+    <contributor>
+      <name>Tibor Digana (tibor17)</name>
+      <email>tibor.digana@gmail.com</email>
+      <timezone>+1</timezone>
+    </contributor>
+  </contributors>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.7</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.5.1</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1c2698a7/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/src/test/java/jiras/surefire1082/Jira1082Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/src/test/java/jiras/surefire1082/Jira1082Test.java b/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/src/test/java/jiras/surefire1082/Jira1082Test.java
new file mode 100644
index 0000000..abf2a58
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-1082-parallel-junit-parameterized/src/test/java/jiras/surefire1082/Jira1082Test.java
@@ -0,0 +1,60 @@
+package jiras.surefire1082;
+
+/*
+ * 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.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
+
+@RunWith( Parameterized.class )
+public final class Jira1082Test
+{
+    private int x;
+
+    public Jira1082Test( int x )
+    {
+        this.x = x;
+    }
+
+    @Parameterized.Parameters
+    public static Iterable<Object[]> data()
+    {
+        return Arrays.asList( new Object[][]{ { 0 }, { 1 } } );
+    }
+
+    @Test
+    public void a()
+        throws InterruptedException
+    {
+        TimeUnit.MILLISECONDS.sleep( 500 );
+        System.out.println( getClass() + " a " + x + " " + Thread.currentThread().getName() );
+    }
+
+    @Test
+    public void b()
+        throws InterruptedException
+    {
+        TimeUnit.MILLISECONDS.sleep( 500 );
+        System.out.println( getClass() + " b " + x + " " + Thread.currentThread().getName() );
+    }
+}