Author: krosenvold
Date: Wed Dec 29 13:41:45 2010
New Revision: 1053634

URL: http://svn.apache.org/viewvc?rev=1053634&view=rev
Log:
[SUREFIRE-546] Test case for @Test(threadPoolSize)

Patch applied with modifications

Added:
    
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgParallelWithAnnotations.java
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/pom.xml
   (with props)
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/
    
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java
   (with props)

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgParallelWithAnnotations.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgParallelWithAnnotations.java?rev=1053634&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgParallelWithAnnotations.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgParallelWithAnnotations.java
 Wed Dec 29 13:41:45 2010
@@ -0,0 +1,43 @@
+package org.apache.maven.surefire.its;
+/*
+ * 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.
+ */
+
+
+/**
+ * Test that TestNG's @Test(threadPoolSize = n, invocationCount=n) causes 
tests to be run in parallel.
+ * 
+ * @author <a href="mailto:[email protected]";>Haikal Saadh</a>
+ * 
+ */
+public class TestNgParallelWithAnnotations
+   extends SurefireVerifierTestClass
+{
+    public TestNgParallelWithAnnotations()
+    {
+        super( "/testng-parallel-with-annotations" );
+    }
+
+    public void testTestNgGroupThreadParallel ()
+        throws Exception
+    {
+        executeTest();
+        verifyErrorFreeLog();
+        assertTestSuiteResults( 3, 0, 0, 0 );
+    }
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgParallelWithAnnotations.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/pom.xml?rev=1053634&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/pom.xml
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/pom.xml
 Wed Dec 29 13:41:45 2010
@@ -0,0 +1,46 @@
+<?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>
+
+       <groupId>org.apache.maven.plugins.surefire</groupId>
+       <artifactId>testng-group-thread-parallel</artifactId>
+       <version>1.0-SNAPSHOT</version>
+       <name>TestNG group/parallel thread tests, with parallel settings set by 
@Test(threadPoolSize)</name>
+       <dependencies>
+               <dependency>
+                       <groupId>org.testng</groupId>
+                       <artifactId>testng</artifactId>
+                       <version>5.8</version>
+                       <classifier>jdk15</classifier>
+                       <scope>test</scope>
+               </dependency>
+       </dependencies>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-surefire-plugin</artifactId>
+                               <version>${surefire.version}</version>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <configuration>
+                                       <source>1.5</source>
+                                       <target>1.5</target>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java?rev=1053634&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java
 (added)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java
 Wed Dec 29 13:41:45 2010
@@ -0,0 +1,42 @@
+package testng.paralellwithannotations;
+
+import static org.testng.Assert.*;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+import java.util.Date;
+
+/**
+ * Test that parallel tests actually run and complete within the expected time.
+ */
+public class TestNGParallelTest{
+
+       static int testCount = 0;
+       static long startTime;
+
+       @BeforeSuite(alwaysRun = true)
+       public void startClock(){
+               startTime = new Date().getTime();
+       }
+       
+       @AfterSuite(alwaysRun = true)
+       public void checkTestResults(){
+               long runtime = new Date().getTime() - startTime;
+               System.out.println("Runtime was: " + runtime);
+               assertTrue( testCount == 3,  "Expected test to be run 3 times, 
but was " + testCount);
+        // Note, this can be < 1000 on Windows.
+               assertTrue( runtime < 1400, "Runtime was " + runtime + ". It 
should be a little over 1000ms");
+       }
+       
+       @Test(threadPoolSize = 2, invocationCount=3)
+    public void incrementTestCountAndSleepForOneSecond() throws 
InterruptedException {
+        incrementTestCount();
+               Thread.sleep(500);
+        System.out.println("Ran test");
+    }
+    
+    private synchronized void incrementTestCount() {
+           testCount++;
+       }
+       
+}

Propchange: 
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to