Fix FtpTestSupport for 421 error from server

We fail sporadically in some FTP tests against
embedded Mina FTP server.
Turns out there was not enough concurrent logins allowed
on the server instance.

* Change the `ConnectionConfig` for FTP server to allow `1024`
concurrent logins instead of `10` by default
This commit is contained in:
Artem Bilan
2021-01-07 11:50:26 -05:00
parent d4bf66f582
commit e561e86fc8
2 changed files with 21 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 the original author or authors.
* Copyright 2015-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@ import java.util.HashMap;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.ftpserver.ConnectionConfigFactory;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.Authentication;
import org.apache.ftpserver.ftplet.AuthenticationFailedException;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.ftplet.UserManager;
@@ -50,6 +50,7 @@ import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
* @author Artem Bilan
* @author Gary Russell
* @author David Turanski
*
* @since 4.3
*/
public class FtpTestSupport extends RemoteFileTestSupport {
@@ -62,7 +63,10 @@ public class FtpTestSupport extends RemoteFileTestSupport {
public static void createServer() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(new TestUserManager(getRemoteTempFolder().getAbsolutePath()));
ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
connectionConfigFactory.setMaxLogins(1024);
connectionConfigFactory.setMaxAnonymousLogins(1024);
serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig());
ListenerFactory factory = new ListenerFactory();
factory.setPort(0);
serverFactory.addListener("default", factory.createListener());
@@ -79,7 +83,7 @@ public class FtpTestSupport extends RemoteFileTestSupport {
@AfterAll
public static void stopServer() throws Exception {
public static void stopServer() {
server.stop();
}
@@ -89,7 +93,7 @@ public class FtpTestSupport extends RemoteFileTestSupport {
}
public static SessionFactory<FTPFile> sessionFactory() {
return new CachingSessionFactory<FTPFile>(rawSessionFactory());
return new CachingSessionFactory<>(rawSessionFactory());
}
protected static DefaultFtpSessionFactory rawSessionFactory() {
@@ -121,13 +125,13 @@ public class FtpTestSupport extends RemoteFileTestSupport {
@Override
public User getUserByName(String s) throws FtpException {
public User getUserByName(String s) {
return this.testUser;
}
@Override
public String[] getAllUserNames() throws FtpException {
return new String[] { "TEST_USER" };
public String[] getAllUserNames() {
return new String[]{ "TEST_USER" };
}
@Override
@@ -135,26 +139,26 @@ public class FtpTestSupport extends RemoteFileTestSupport {
}
@Override
public void save(User user) throws FtpException {
public void save(User user) {
}
@Override
public boolean doesExist(String s) throws FtpException {
public boolean doesExist(String s) {
return true;
}
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
public User authenticate(Authentication authentication) {
return this.testUser;
}
@Override
public String getAdminName() throws FtpException {
public String getAdminName() {
return "admin";
}
@Override
public boolean isAdmin(String s) throws FtpException {
public boolean isAdmin(String s) {
return s.equals("admin");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -168,9 +169,7 @@ public class RotatingServersTests extends FtpTestSupport {
@Test
public void testVariableLocalDir() throws Exception {
try (AnnotationConfigApplicationContext ctx =
new AnnotationConfigApplicationContext(VariableLocalConfig.class)) {
try (ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VariableLocalConfig.class)) {
StandardConfig config = ctx.getBean(StandardConfig.class);
assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
ctx.getBean(SourcePollingChannelAdapter.class).stop();
@@ -211,9 +210,7 @@ public class RotatingServersTests extends FtpTestSupport {
@Test
public void testFairStreaming() throws Exception {
try (AnnotationConfigApplicationContext ctx =
new AnnotationConfigApplicationContext(FairStreamingConfig.class)) {
try (ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(FairStreamingConfig.class)) {
StandardConfig config = ctx.getBean(StandardConfig.class);
assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
ctx.getBean(SourcePollingChannelAdapter.class).stop();