Skip to content

Commit

Permalink
Enable parallel test (#3774)
Browse files Browse the repository at this point in the history
* 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
jihoonson authored and fjy committed Dec 15, 2016
1 parent ed322a4 commit 5e39578
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
1 change: 0 additions & 1 deletion bytebuffer-collections/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
13 changes: 11 additions & 2 deletions common/src/main/java/io/druid/common/utils/SocketUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
38 changes: 19 additions & 19 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
38 changes: 37 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5e39578

Please sign in to comment.