Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 139 additions & 51 deletions restcomm/restcomm.testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
</dependency>

<!-- <dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.application</artifactId>
<version>${project.version}</version> <type>war</type> <scope>test</scope>
</dependency> <dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.commons</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.dao</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.mgcp</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.sms</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.http</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.telephony</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.telephony.api</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.interpreter</artifactId>
<version>${project.version}</version> <scope>test</scope> </dependency> -->
<version>${project.version}</version> <type>war</type> <scope>test</scope>
</dependency> <dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.commons</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.dao</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.mgcp</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.sms</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.http</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.telephony</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.telephony.api</artifactId>
<version>${project.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.restcomm</groupId> <artifactId>restcomm-connect.interpreter</artifactId>
<version>${project.version}</version> <scope>test</scope> </dependency> -->

<dependency>
<groupId>org.scala-lang</groupId>
Expand Down Expand Up @@ -160,12 +160,12 @@

<!--Dependencies for Tomcat-6 -->
<!-- <dependency> <groupId>org.mobicents.servlet.sip.containers</groupId>
<artifactId>sip-servlets-catalina-6</artifactId> <version>${sipservletapi.version}</version>
<scope>test</scope> </dependency> <dependency> <groupId>org.mobicents.servlet.sip.containers</groupId>
<artifactId>sip-servlets-tomcat-jboss4</artifactId> <version>${sipservletapi.version}</version>
<scope>test</scope> </dependency> <dependency> <groupId>org.mobicents.arquillian.container</groupId>
<artifactId>mss-tomcat-embedded-6</artifactId> <version>${mss.arquillian.version}</version>
<scope>test</scope> </dependency> -->
<artifactId>sip-servlets-catalina-6</artifactId> <version>${sipservletapi.version}</version>
<scope>test</scope> </dependency> <dependency> <groupId>org.mobicents.servlet.sip.containers</groupId>
<artifactId>sip-servlets-tomcat-jboss4</artifactId> <version>${sipservletapi.version}</version>
<scope>test</scope> </dependency> <dependency> <groupId>org.mobicents.arquillian.container</groupId>
<artifactId>mss-tomcat-embedded-6</artifactId> <version>${mss.arquillian.version}</version>
<scope>test</scope> </dependency> -->

<!--Dependencies for Tomcat-6 -->

Expand Down Expand Up @@ -273,18 +273,18 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng-agent</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng-agent</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency> -->

<dependency>
<groupId>com.github.tomakehurst</groupId>
Expand Down Expand Up @@ -423,23 +423,111 @@
<resultFileMinClasspathCount>2</resultFileMinClasspathCount>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/CallLifecycleAnswerDelayTest.java</include>
<include>**/CallLifecycleTest.java</include>
<include>**/CallRegexSingleTest.java</include>
<include>**/CallRegexTest.java</include>
<include>**/ClientsDialAnswerDelayTest.java</include>
<include>**/ClientsDialTest.java</include>
<include>**/DialActionAnswerDelayTest.java</include>
<include>**/DialActionTest.java</include>
<include>**/DialForkAnswerDealyTest.java</include>
<include>**/DialForkTest.java</include>
<include>**/DialRecordingAnswerDelayTest.java</include>
<include>**/DialRecordingTest.java</include>
<include>**/DialStatusCallbackTest.java</include>
<include>**/ImsClientsDialAnswerDelayTest.java</include>
<include>**/ImsClientsDialTest.java</include>
<include>**/TestDialVerbPartOneAnswerDelay.java</include>
<include>**/TestDialVerbPartOne.java</include>
<include>**/TestDialVerbPartTwoAnswerDelay.java</include>
<include>**/TestDialVerbPartTwo.java</include>
<include>**/TestDialVerbPartThreeAnswerDelay.java</include>
<include>**/TestDialVerbPartThree.java</include>

<include>**/UserAgentManagerTest.java</include>
<include>**/sms/*Test.java</include>
<include>**/connect/testsuite/*Test.java</include>
</includes>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
<!-- let ci script set forkcount.Dont increase over 65
since that will make ports over the maximum allowed by OS.
on local env set depending on available mem
<forkCount>2</forkCount>
-->
<reuseForks>false</reuseForks>
<parallel>classes</parallel>
<threadCountClasses>5</threadCountClasses>
<!-- start with low memory to increase forks -->
<argLine>-Xms256m -Xmx2048m -XX:MaxPermSize=512m</argLine>
<systemPropertyVariables>
<!--use different arquillian configuration to tweak maps
depending on forked JVM-->
<arquillian.launch>mss-tomcat-embedded-7-forked</arquillian.launch>
<!-- this will ensure sip and http ports are diff for
every forked JVM/test class-->
<arquillian_http_port>${surefire.forkNumber}509</arquillian_http_port>
<arquillian_sip_port>${surefire.forkNumber}508</arquillian_sip_port>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xms1024m -Xmx2048m -XX:MaxPermSize=1024m</argLine>
<!-- <excludes> <exclude>**/SmsSessionTest.java</exclude> </excludes> -->
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<skipTests>${skipUTs}</skipTests>
<excludes>
<exclude>**/CallLifecycleAnswerDelayTest.java</exclude>
<exclude>**/CallLifecycleTest.java</exclude>
<exclude>**/CallRegexSingleTest.java</exclude>
<exclude>**/CallRegexTest.java</exclude>
<exclude>**/ClientsDialAnswerDelayTest.java</exclude>
<exclude>**/ClientsDialTest.java</exclude>
<exclude>**/DialActionAnswerDelayTest.java</exclude>
<exclude>**/DialActionTest.java</exclude>
<exclude>**/DialForkAnswerDealyTest.java</exclude>
<exclude>**/DialForkTest.java</exclude>
<exclude>**/DialRecordingAnswerDelayTest.java</exclude>
<exclude>**/DialRecordingTest.java</exclude>
<exclude>**/DialStatusCallbackTest.java</exclude>
<exclude>**/ImsClientsDialAnswerDelayTest.java</exclude>
<exclude>**/ImsClientsDialTest.java</exclude>
<exclude>**/TestDialVerbPartOneAnswerDelay.java</exclude>
<exclude>**/TestDialVerbPartOne.java</exclude>
<exclude>**/TestDialVerbPartTwoAnswerDelay.java</exclude>
<exclude>**/TestDialVerbPartTwo.java</exclude>
<exclude>**/TestDialVerbPartThreeAnswerDelay.java</exclude>
<exclude>**/TestDialVerbPartThree.java</exclude>

<exclude>**/UserAgentManagerTest.java</exclude>
<exclude>**/sms/*Test.java</exclude>
<exclude>**/connect/testsuite/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xms1024m -Xmx2048m -XX:MaxPermSize=1024m</argLine>
<!-- <excludes> <exclude>**/SmsSessionTest.java</exclude> </excludes> -->
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.restcomm.connect.testsuite;

import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.management.ManagementFactory;
import java.nio.channels.FileChannel;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.log4j.Logger;

/**
* Allows integration tests to be run in parallel by assigning a free port.
*
* A port range will be assigned based in JVM PID, and a circular sequence
* around this range will be provided. JVM PID are expected to be sequenced, so
* incremental PID will be received. It is assumed that low number of forked
* JMVs will be used to run parallel tests ( near cores in system), so the
* PORT_RANGE dont provide much collisions.
*
*/
public class NetworkPortAssigner {

private static final Logger LOGGER = Logger.getLogger(NetworkPortAssigner.class);
private static final int PORT_RANGE = 150;

//provide ports above system reserved range
private static final int PORT_MAX_BASE = 65534;

private static final int INITIAL_PORT_VALUE;

private static final AtomicInteger PORT_SEQ = new AtomicInteger(0);

private static final int PID;

static {
final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
final int index = jvmName.indexOf('@');

if (index < 1) {
// part before '@' empty (index = 0) / '@' not found (index = -1)
PID = 0;
} else {
PID = Integer.parseInt(jvmName.substring(0, index));
}

INITIAL_PORT_VALUE = PORT_MAX_BASE - ((PID % PORT_RANGE) * PORT_RANGE);
LOGGER.info("PID:" + PID);
LOGGER.info("PID:" + PID + ",INITIAL_PORT_VALUE:" + INITIAL_PORT_VALUE);
}

public synchronized static int retrieveNextPort() {
int nextPort = PORT_MAX_BASE;
nextPort = retrieveNextPortByFile();
LOGGER.info("PID:" + PID + ",nextPort:" + nextPort);
return nextPort;
}

public static int retrieveNextPortBySeq() {
int nextPort = INITIAL_PORT_VALUE - (PORT_SEQ.getAndAdd(1) % PORT_RANGE);
return nextPort;
}

public static int retrieveNextPortByFile() {
int nextPort = PORT_MAX_BASE;
//assume maven convention, create file under target so its cleaned
File portFile = new File("./target/portFile");
try {
if (!portFile.exists()) {
portFile.createNewFile();
LOGGER.info("PID:" + PID + ",portFile created");
} else {
LOGGER.info("PID:" + PID + ",portFile already exists");
}
} catch (IOException ex) {
LOGGER.info("PID:" + PID + ", there is problem when creating portFile");
}

RandomAccessFile aFile = null;
try {
aFile = new RandomAccessFile(portFile, "rwd");
FileChannel channel = aFile.getChannel();
channel.lock();
try {
int readInt = aFile.readInt();
nextPort = readInt - 1;
if (nextPort <= 0) {
nextPort = PORT_MAX_BASE - 1;
}
} catch (EOFException eExp) {
//file was empty, it was just created
nextPort = PORT_MAX_BASE - 1;
LOGGER.info("PID:" + PID + ",sequence resetted");
}
//rewrite existing value by resetting pointer to the start
aFile.seek(0);
aFile.writeInt(nextPort);
} catch (Exception ex) {
LOGGER.error("error getting port", ex);
} finally {
if (aFile != null) {
try {
aFile.close();
} catch (Exception e) {
LOGGER.error("error getting port", e);
}
}
}
return nextPort;
}
}
Loading