You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/11/24 14:38:05 UTC
[sling-org-apache-sling-servlets-annotations] branch master
updated: SLING-9930 - use a different port for each OSGi framework instance
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-annotations.git
The following commit(s) were added to refs/heads/master by this push:
new 954fd3f SLING-9930 - use a different port for each OSGi framework instance
954fd3f is described below
commit 954fd3f4cf40f54167bc53e366834c23e57a566f
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Nov 24 15:37:40 2020 +0100
SLING-9930 - use a different port for each OSGi framework instance
---
.gitignore | 2 +-
src/it/annotations-it/pom.xml | 2 +-
.../annotations/AnnotationsTestSupport.java | 26 +++++++++++++++++-----
3 files changed, 22 insertions(+), 8 deletions(-)
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.mavenBundle;
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 @@ public class AnnotationsTestSupport extends TestSupport {
protected static int httpPort;
@ClassRule
- public static PaxExamServer serverRule = new PaxExamServer();
-
- public AnnotationsTestSupport() {
- if(httpPort == 0) {
- // findFreePort should probably be a static method
- httpPort = findFreePort();
+ 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();
+ }
+ };
+
+ /** 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);
}
}