~ubuntu-branches/ubuntu/precise/surefire/precise

« back to all changes in this revision

Viewing changes to surefire-integration-tests/src/test/resources/testng-parallel-with-annotations/src/test/java/testng/paralellwithannotations/TestNGParallelTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2011-10-10 20:42:16 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20111010204216-cemva69wkagf4fay
Tags: 2.10-1
* Team upload.
* New upstream release.
* Refresh and remove unneccesary patches.
* Add Build-Depends on libsurefire-java and
  libmaven-common-artifact-filters-java.
* Drop outdated Maven artifact surefire-junit.
* Provide new Maven artifacts: surefire-junit3, maven-surefire-common,
  common-junit3, common-junit4, surefire-junit47 and surefire-testng-utils.
* Fix clean target to allow "two in a row" builds.
* Update Vcs-Browser field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package testng.paralellwithannotations;
 
2
 
 
3
import static org.testng.Assert.*;
 
4
import org.testng.annotations.AfterSuite;
 
5
import org.testng.annotations.BeforeSuite;
 
6
import org.testng.annotations.Test;
 
7
import java.util.Date;
 
8
 
 
9
/**
 
10
 * Test that parallel tests actually run and complete within the expected time.
 
11
 */
 
12
public class TestNGParallelTest{
 
13
 
 
14
        static int testCount = 0;
 
15
        static long startTime;
 
16
 
 
17
        @BeforeSuite(alwaysRun = true)
 
18
        public void startClock(){
 
19
                startTime = new Date().getTime();
 
20
        }
 
21
        
 
22
        @AfterSuite(alwaysRun = true)
 
23
        public void checkTestResults(){
 
24
                long runtime = new Date().getTime() - startTime;
 
25
                System.out.println("Runtime was: " + runtime);
 
26
                assertTrue( testCount == 3,  "Expected test to be run 3 times, but was " + testCount);
 
27
        // Note, this can be < 1000 on Windows.
 
28
                assertTrue( runtime < 1400, "Runtime was " + runtime + ". It should be a little over 1000ms");
 
29
        }
 
30
        
 
31
        @Test(threadPoolSize = 2, invocationCount=3)
 
32
    public void incrementTestCountAndSleepForOneSecond() throws InterruptedException {
 
33
        incrementTestCount();
 
34
        Thread.sleep(500);
 
35
        System.out.println("Ran test");
 
36
    }
 
37
    
 
38
    private synchronized void incrementTestCount() {
 
39
            testCount++;
 
40
        }
 
41
        
 
42
}