You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/04/19 11:02:21 UTC
[maven-wagon] branch stabilize updated: Test with port range for
ftp server
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch stabilize
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git
The following commit(s) were added to refs/heads/stabilize by this push:
new efb3e81 Test with port range for ftp server
efb3e81 is described below
commit efb3e81b9c257acd7bca73545d32e3c8775aeccd
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Apr 19 13:02:13 2019 +0200
Test with port range for ftp server
---
.../java/org/apache/maven/wagon/WagonTestCase.java | 18 ++++++++++++
wagon-providers/wagon-ftp/pom.xml | 2 +-
.../maven/wagon/providers/ftp/FtpWagonTest.java | 34 +++++++++++++++++-----
3 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
index 9d26555..1f265e3 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
@@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
+import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
@@ -141,6 +142,23 @@ public abstract class WagonTestCase
* @return the port number for the test server
*/
protected abstract int getTestRepositoryPort();
+
+ protected static ServerSocket newServerSocket( int... ports )
+ {
+ for ( int port : ports )
+ {
+ try
+ {
+ return new ServerSocket( port );
+ }
+ catch ( IOException ex )
+ {
+ continue;
+ }
+ }
+
+ throw new RuntimeException( "no port available" );
+ }
// ----------------------------------------------------------------------
// 1. Create a local file repository which mimic a users local file
diff --git a/wagon-providers/wagon-ftp/pom.xml b/wagon-providers/wagon-ftp/pom.xml
index 03be4b0..5b14c3c 100644
--- a/wagon-providers/wagon-ftp/pom.xml
+++ b/wagon-providers/wagon-ftp/pom.xml
@@ -43,7 +43,7 @@ under the License.
<dependency>
<groupId>org.apache.ftpserver</groupId>
<artifactId>ftpserver-core</artifactId>
- <version>1.0.6</version>
+ <version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java b/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
index 6c8f401..c880a02 100644
--- a/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
+++ b/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
@@ -19,6 +19,12 @@ package org.apache.maven.wagon.providers.ftp;
* under the License.
*/
+import java.io.File;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.commons.io.FileUtils;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
@@ -36,11 +42,6 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
*
@@ -49,15 +50,32 @@ public class FtpWagonTest
extends StreamingWagonTestCase
{
static private FtpServer server;
-
+
+// private static final int testRepositoryPort = 10023 + new Random().nextInt( 16 );
+
+ private static int testRepositoryPort;
+
protected String getProtocol()
{
return "ftp";
}
+
+ static
+ {
+ // claim number, release it again so it can be reclaimed by ftp server
+ try (ServerSocket socket = newServerSocket( 10023, 10024, 10025, 10026 ))
+ {
+ testRepositoryPort = socket.getLocalPort();
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
@Override
protected int getTestRepositoryPort() {
- return 10023;
+ return testRepositoryPort;
}
protected void setupWagonTestingFixtures()
@@ -77,7 +95,7 @@ public class FtpWagonTest
// set the port of the listener
factory.setPort(getTestRepositoryPort());
-
+
// replace the default listener
serverFactory.addListener("default", factory.createListener());