SLING-9930 - use a different port for each OSGi framework instance
diff --git a/.gitignore b/.gitignore
index 1930ad4..658337c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-/target/
+target/
/.project
/.settings/
/.classpath
diff --git a/src/it/annotations-it/pom.xml b/src/it/annotations-it/pom.xml
index 22bc895..9366a27 100644
--- a/src/it/annotations-it/pom.xml
+++ b/src/it/annotations-it/pom.xml
@@ -31,7 +31,7 @@
<!-- compile with java 7 -->
<properties>
<sling.java.version>8</sling.java.version>
- <org.ops4j.pax.exam.version>4.13.3</org.ops4j.pax.exam.version>
+ <org.ops4j.pax.exam.version>4.13.4</org.ops4j.pax.exam.version>
<!-- additional options that can be passed to Pax before executing the tests -->
<pax.vm.options />
<bundle.filename>${basedir}/target/${project.build.finalName}.jar</bundle.filename>
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java
index f1efd80..5042ac8 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java
@@ -35,6 +35,7 @@
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import java.net.URI;
+import java.net.ServerSocket;
public class AnnotationsTestSupport extends TestSupport {
@@ -44,12 +45,25 @@
protected static int httpPort;
@ClassRule
- public static PaxExamServer serverRule = new PaxExamServer();
+ public static PaxExamServer serverRule = new PaxExamServer() {
+ @Override
+ protected void before() throws Exception {
+ // Use a different port for each OSGi framework instance
+ // that's started - they can overlap if the previous one
+ // is not fully stopped when the next one starts.
+ setHttpPort();
+ super.before();
+ }
+ };
- public AnnotationsTestSupport() {
- if(httpPort == 0) {
- // findFreePort should probably be a static method
- httpPort = findFreePort();
+ /** TODO this duplicates TestSupport.findFreePort, which is not static */
+ static void setHttpPort() {
+ try {
+ final ServerSocket serverSocket = new ServerSocket(0);
+ httpPort = serverSocket.getLocalPort();
+ serverSocket.close();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}