Skip to content

Commit b6eab9a

Browse files
committed
Fix race condition in the FtpServerOutboundTests
Looks like there might be several `SessionClosedEvent` emitted in the application context, but we are interested only in the specific one for the `this.clientAddress` * Add condition to the `SessionClosedEvent` `if` * Remove `TestApplicationContextAware` since we can just rely on the `FunctionExpression` to extract a payload from the `Message` instead
1 parent 29e97b8 commit b6eab9a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpServerOutboundTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
import org.springframework.context.ApplicationContext;
4848
import org.springframework.context.annotation.Bean;
4949
import org.springframework.context.event.EventListener;
50-
import org.springframework.expression.spel.standard.SpelExpressionParser;
5150
import org.springframework.integration.IntegrationMessageHeaderAccessor;
5251
import org.springframework.integration.channel.DirectChannel;
5352
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
53+
import org.springframework.integration.expression.FunctionExpression;
5454
import org.springframework.integration.file.FileHeaders;
5555
import org.springframework.integration.file.filters.FileListFilter;
5656
import org.springframework.integration.file.remote.MessageSessionCallback;
@@ -71,7 +71,6 @@
7171
import org.springframework.integration.ftp.session.FtpRemoteFileTemplate;
7272
import org.springframework.integration.support.MessageBuilder;
7373
import org.springframework.integration.support.PartialSuccessException;
74-
import org.springframework.integration.test.context.TestApplicationContextAware;
7574
import org.springframework.integration.test.util.TestUtils;
7675
import org.springframework.messaging.Message;
7776
import org.springframework.messaging.MessagingException;
@@ -99,7 +98,7 @@
9998
*/
10099
@SpringJUnitConfig
101100
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
102-
public class FtpServerOutboundTests extends FtpTestSupport implements TestApplicationContextAware {
101+
public class FtpServerOutboundTests extends FtpTestSupport {
103102

104103
@Autowired
105104
private SessionFactory<FTPFile> ftpSessionFactory;
@@ -376,8 +375,7 @@ public void testInt3100RawGET() throws Exception {
376375
@Test
377376
public void testRawGETWithTemplate() {
378377
RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(this.ftpSessionFactory);
379-
template.setFileNameExpression(new SpelExpressionParser().parseExpression("payload"));
380-
template.setBeanFactory(TEST_INTEGRATION_CONTEXT);
378+
template.setFileNameExpression(new FunctionExpression<Message<?>>(Message::getPayload));
381379
template.afterPropertiesSet();
382380
final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
383381
assertThat(template.get(new GenericMessage<>("ftpSource/ ftpSource1.txt"),
@@ -846,7 +844,9 @@ public void handleEvent(ApacheMinaFtpEvent event) {
846844
else if (event.getSession().getClientAddress().equals(this.clientAddress)) {
847845
this.events.add(event);
848846
}
849-
if (event instanceof SessionClosedEvent) {
847+
if (event instanceof SessionClosedEvent
848+
&& event.getSession().getClientAddress().equals(this.clientAddress)) {
849+
850850
this.latch.countDown();
851851
}
852852
}

0 commit comments

Comments
 (0)