You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by bh...@apache.org on 2020/06/09 23:34:37 UTC

[samza] branch master updated: Dynamically choose a port for Jersey test HTTP server (#1380)

This is an automated email from the ASF dual-hosted git repository.

bharathkk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/samza.git


The following commit(s) were added to refs/heads/master by this push:
     new 47a6890  Dynamically choose a port for Jersey test HTTP server (#1380)
47a6890 is described below

commit 47a6890cedb507b721fda369658feafbaa67e17d
Author: Alan Zhang <sh...@gmail.com>
AuthorDate: Tue Jun 9 16:34:29 2020 -0700

    Dynamically choose a port for Jersey test HTTP server (#1380)
---
 .../samza/rest/resources/BaseJerseyTest.java       | 31 ++++++++++++++++++++++
 .../samza/rest/resources/TestJobsResource.java     |  3 +--
 .../samza/rest/resources/TestTasksResource.java    |  3 +--
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/samza-rest/src/test/java/org/apache/samza/rest/resources/BaseJerseyTest.java b/samza-rest/src/test/java/org/apache/samza/rest/resources/BaseJerseyTest.java
new file mode 100644
index 0000000..5cd768c
--- /dev/null
+++ b/samza-rest/src/test/java/org/apache/samza/rest/resources/BaseJerseyTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.samza.rest.resources;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+
+
+public class BaseJerseyTest extends JerseyTest {
+
+  public BaseJerseyTest() {
+    // Configure port as 0 to let Jersey test HTTP server choose an available port dynamically
+    forceSet(TestProperties.CONTAINER_PORT, "0");
+  }
+}
diff --git a/samza-rest/src/test/java/org/apache/samza/rest/resources/TestJobsResource.java b/samza-rest/src/test/java/org/apache/samza/rest/resources/TestJobsResource.java
index 2a051c4..d19a181 100644
--- a/samza-rest/src/test/java/org/apache/samza/rest/resources/TestJobsResource.java
+++ b/samza-rest/src/test/java/org/apache/samza/rest/resources/TestJobsResource.java
@@ -36,7 +36,6 @@ import org.apache.samza.rest.resources.mock.MockResourceFactory;
 import org.apache.samza.serializers.model.SamzaObjectMapper;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.type.TypeReference;
-import org.glassfish.jersey.test.JerseyTest;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -45,7 +44,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 
-public class TestJobsResource extends JerseyTest {
+public class TestJobsResource extends BaseJerseyTest {
   ObjectMapper objectMapper = SamzaObjectMapper.getObjectMapper();
 
   @Override
diff --git a/samza-rest/src/test/java/org/apache/samza/rest/resources/TestTasksResource.java b/samza-rest/src/test/java/org/apache/samza/rest/resources/TestTasksResource.java
index a9dbfcf..7cb9527 100644
--- a/samza-rest/src/test/java/org/apache/samza/rest/resources/TestTasksResource.java
+++ b/samza-rest/src/test/java/org/apache/samza/rest/resources/TestTasksResource.java
@@ -35,14 +35,13 @@ import org.apache.samza.rest.resources.mock.MockTaskProxyFactory;
 import org.apache.samza.serializers.model.SamzaObjectMapper;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.type.TypeReference;
-import org.glassfish.jersey.test.JerseyTest;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 
-public class TestTasksResource extends JerseyTest {
+public class TestTasksResource extends BaseJerseyTest {
   private ObjectMapper objectMapper = SamzaObjectMapper.getObjectMapper();
 
   @Override