You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2021/07/07 08:55:42 UTC

[nifi] branch main updated: NIFI-8741 Changed JettyServerGroovyTest to use NetworkUtils.getAvailableTcpPort()

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

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 1de01e3  NIFI-8741 Changed JettyServerGroovyTest to use NetworkUtils.getAvailableTcpPort()
1de01e3 is described below

commit 1de01e34daeb22e19fef88d5c9e26e19dc492fcd
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Tue Jul 6 13:18:57 2021 -0500

    NIFI-8741 Changed JettyServerGroovyTest to use NetworkUtils.getAvailableTcpPort()
    
    Signed-off-by: Pierre Villard <pi...@gmail.com>
    
    This closes #5200.
---
 .../nifi/web/server/JettyServerGroovyTest.groovy   | 23 ++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
index d00ed76..dc296a7 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
@@ -23,6 +23,7 @@ import org.apache.nifi.nar.ExtensionManagerHolder
 import org.apache.nifi.nar.ExtensionMapping
 import org.apache.nifi.nar.SystemBundle
 import org.apache.nifi.processor.DataUnit
+import org.apache.nifi.remote.io.socket.NetworkUtils
 import org.apache.nifi.security.util.StandardTlsConfiguration
 import org.apache.nifi.security.util.TlsConfiguration
 import org.apache.nifi.security.util.TlsPlatform
@@ -49,7 +50,6 @@ import org.junit.contrib.java.lang.system.SystemErrRule
 import org.junit.contrib.java.lang.system.SystemOutRule
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
-import org.mockito.ArgumentCaptor
 import org.mockito.ArgumentMatchers
 import org.mockito.Mockito
 import org.mockito.invocation.InvocationOnMock
@@ -77,7 +77,10 @@ class JettyServerGroovyTest extends GroovyTestCase {
     @Rule
     public final SystemErrRule systemErrRule = new SystemErrRule().enableLog()
 
-    private static final int HTTPS_PORT = 8443
+    private static final int DEFAULT_HTTP_PORT = 8080
+    private static final int DEFAULT_HTTPS_PORT = 8443
+
+    private static final int HTTPS_PORT = NetworkUtils.getAvailableTcpPort()
     private static final String HTTPS_HOSTNAME = "localhost"
 
     private static final String KEYSTORE_PATH = "src/test/resources/keystore.jks"
@@ -139,8 +142,8 @@ class JettyServerGroovyTest extends GroovyTestCase {
                 (NiFiProperties.WEB_THREADS)   : NiFiProperties.DEFAULT_WEB_THREADS
         ]
         NiFiProperties mockProps = Mockito.mock(NiFiProperties.class)
-        Mockito.when(mockProps.getPort()).thenReturn(8080)
-        Mockito.when(mockProps.getSslPort()).thenReturn(8443)
+        Mockito.when(mockProps.getPort()).thenReturn(DEFAULT_HTTP_PORT)
+        Mockito.when(mockProps.getSslPort()).thenReturn(DEFAULT_HTTPS_PORT)
 
         Mockito.when(mockProps.getProperty(ArgumentMatchers.anyString())).thenAnswer(new Answer<Object>() {
             @Override
@@ -168,7 +171,7 @@ class JettyServerGroovyTest extends GroovyTestCase {
                 (NiFiProperties.WEB_HTTPS_HOST): null,
         ]
         NiFiProperties httpProps = [
-                getPort    : { -> 8080 },
+                getPort    : { -> DEFAULT_HTTP_PORT },
                 getSslPort : { -> null },
                 getProperty: { String prop ->
                     String value = httpMap[prop] ?: "no_value"
@@ -183,7 +186,7 @@ class JettyServerGroovyTest extends GroovyTestCase {
         ]
         NiFiProperties httpsProps = [
                 getPort    : { -> null },
-                getSslPort : { -> 8443 },
+                getSslPort : { -> DEFAULT_HTTPS_PORT },
                 getProperty: { String prop ->
                     String value = httpsMap[prop] ?: "no_value"
                     logger.mock("getProperty(${prop}) -> ${value}")
@@ -216,8 +219,8 @@ class JettyServerGroovyTest extends GroovyTestCase {
                 (NiFiProperties.WEB_HTTPS_HOST): "secure.host.com",
         ]
         NiFiProperties mockProps = [
-                getPort            : { -> 8080 },
-                getSslPort         : { -> 8443 },
+                getPort            : { -> DEFAULT_HTTP_PORT },
+                getSslPort         : { -> DEFAULT_HTTPS_PORT },
                 getProperty        : { String prop ->
                     String value = badProps[prop] ?: "no_value"
                     logger.mock("getProperty(${prop}) -> ${value}")
@@ -463,7 +466,7 @@ class JettyServerGroovyTest extends GroovyTestCase {
     void testShouldEnableContentLengthFilterIfWebMaxContentSizeSet() {
         // Arrange
         Map defaultProps = [
-                (NiFiProperties.WEB_HTTP_PORT)       : "8080",
+                (NiFiProperties.WEB_HTTP_PORT)       : DEFAULT_HTTP_PORT as String,
                 (NiFiProperties.WEB_HTTP_HOST)       : "localhost",
                 (NiFiProperties.WEB_MAX_CONTENT_SIZE): "1 MB",
         ]
@@ -507,7 +510,7 @@ class JettyServerGroovyTest extends GroovyTestCase {
     void testShouldNotEnableContentLengthFilterIfWebMaxContentSizeEmpty() {
         // Arrange
         Map defaultProps = [
-                (NiFiProperties.WEB_HTTP_PORT): "8080",
+                (NiFiProperties.WEB_HTTP_PORT): DEFAULT_HTTP_PORT as String,
                 (NiFiProperties.WEB_HTTP_HOST): "localhost",
         ]
         NiFiProperties mockProps = new NiFiProperties(new Properties(defaultProps))