Permalink
Browse files

Enable parallel test (#3774)

* Enable parallel test

* Remove unnecessary NotThreadSafe annocation

* Randomize the start port when finding available ports

* Fix test failure

* Change to handle all negatives
  • Loading branch information...
1 parent ed322a4 commit 5e39578eeedb03634affc57c155137af9f671ac8 @jihoonson jihoonson committed with fjy Dec 15, 2016
View
@@ -5,7 +5,7 @@ jdk:
- oraclejdk8
script:
- - mvn test -B && mvn clean -Pstrict compile test-compile -B
+ - mvn test -B -Pparallel-test -Dmaven.fork.count=2 && mvn clean -Pstrict compile test-compile -B
sudo: false
View
@@ -159,7 +159,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
</plugin>
</plugins>
</pluginManagement>
@@ -112,7 +112,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.18.1</version>
<configuration>
<excludedGroups>io.druid.test.annotation.Benchmark</excludedGroups>
</configuration>
@@ -21,15 +21,24 @@
import java.io.IOException;
import java.net.ServerSocket;
+import java.util.Random;
import io.druid.java.util.common.ISE;
/**
*/
public class SocketUtil
{
- public static int findOpenPort(int startPort)
+
+ private static final Random rnd = new Random(System.currentTimeMillis());
+
+ public static int findOpenPort(int basePort)
{
+ final int startPort = basePort < 0 ? -1 : rnd.nextInt(0x7fff) + basePort;
+ return findOpenPortFrom(startPort);
+ }
+
+ public static int findOpenPortFrom(int startPort) {
int currPort = startPort;
while (currPort < 0xffff) {
@@ -53,6 +62,6 @@ public static int findOpenPort(int startPort)
}
}
- throw new ISE("Unable to find open port between[%d] and [%d]", startPort, currPort);
+ throw new ISE("Unable to find open port between [%d] and [%d]", startPort, currPort);
}
}
@@ -133,25 +133,25 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>org.testng.TestNG</mainClass>
- </manifest>
- </archive>
- </configuration>
- <executions>
- <execution>
- <id>test-jar</id>
- <phase>package</phase>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.testng.TestNG</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ <executions>
+ <execution>
+ <id>test-jar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
View
@@ -729,11 +729,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19.1</version>
<configuration>
<!-- locale settings must be set on the command line before startup -->
<!-- set heap size to work around https://github.com/travis-ci/travis-ci/issues/3396 -->
<argLine>-Xmx1024m -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8
- -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
+ -Duser.timezone=UTC -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
</argLine>
<!-- our tests are very verbose, let's keep the volume down -->
<redirectTestOutputToFile>true</redirectTestOutputToFile>
@@ -895,5 +896,40 @@
<module>distribution</module>
</modules>
</profile>
+
+ <profile>
+ <id>parallel-test</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration combine.self="override">
+ <forkCount>${maven.fork.count}</forkCount>
+ <reuseForks>true</reuseForks>
+ <trimStackTrace>false</trimStackTrace>
+ <!-- locale settings must be set on the command line before startup -->
+ <!-- set heap size to work around https://github.com/travis-ci/travis-ci/issues/3396 -->
+ <argLine>-Xmx1024m -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8
+ -Duser.timezone=UTC -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
+ </argLine>
+ <!-- our tests are very verbose, let's keep the volume down -->
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
</project>
@@ -84,8 +84,8 @@ public void setup() throws Exception
Injector injector = setupInjector();
final DruidNode node = injector.getInstance(Key.get(DruidNode.class, Self.class));
port = node.getPort();
- port1 = SocketUtil.findOpenPort(port + 1);
- port2 = SocketUtil.findOpenPort(port1 + 1);
+ port1 = SocketUtil.findOpenPortFrom(port + 1);
+ port2 = SocketUtil.findOpenPortFrom(port1 + 1);
lifecycle = injector.getInstance(Lifecycle.class);
lifecycle.start();

0 comments on commit 5e39578

Please sign in to comment.