Do not auto-start Inbound Channel Adapter

https://build.spring.io/browse/INTSAMPLES-NIGHTLY-JOB1-2397

To avoid race conditions with the test data and auto-started channel
adapter, it would be better to have channel adapter not started in the
beginning and prepare test data and only after that start it manually.

The race condition is when we have old data in the directory to poll
This commit is contained in:
Artem Bilan
2018-03-16 10:56:13 -04:00
parent ac02700300
commit 59d01cb6b3
2 changed files with 12 additions and 4 deletions

View File

@@ -71,7 +71,8 @@ public class Application {
Files.inboundAdapter(new File("/tmp/in"))
.preventDuplicates(false)
.patternFilter("*.txt"), e -> e.poller(Pollers.fixedDelay(5000)
.errorChannel("tfrErrors.input")))
.errorChannel("tfrErrors.input"))
.id("fileInboundChannelAdapter"))
.handle(Files.splitter(true, true))
.<Object, Class<?>>route(Object::getClass, m -> m
.channelMapping(FileSplitter.FileMarker.class, "markers.input")
@@ -133,7 +134,7 @@ public class Application {
.enrichHeaders(Mail.headers()
.subject("File successfully split and transferred")
.from("foo@bar")
.toFunction(m -> new String[]{"bar@baz"}))
.toFunction(m -> new String[] { "bar@baz" }))
.enrichHeaders(h -> h.header(EMAIL_SUCCESS_SUFFIX, ".success"))
.channel("toMail.input")));
}
@@ -176,7 +177,7 @@ public class Application {
.enrichHeaders(Mail.headers()
.subject("File split and transfer failed")
.from("foo@bar")
.toFunction(m -> new String[]{"bar@baz"}))
.toFunction(m -> new String[] { "bar@baz" }))
.enrichHeaders(h -> h.header(EMAIL_SUCCESS_SUFFIX, ".failed")
.headerExpression(FileHeaders.ORIGINAL_FILE, "payload.failedMessage.headers['"
+ FileHeaders.ORIGINAL_FILE + "']"))

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -44,8 +44,10 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.test.context.SpringIntegrationTest;
import org.springframework.integration.test.mail.TestMailServer;
import org.springframework.integration.test.mail.TestMailServer.SmtpServer;
import org.springframework.integration.test.util.TestUtils;
@@ -55,6 +57,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@SpringIntegrationTest(noAutoStartup = "fileInboundChannelAdapter")
public class ApplicationTests {
private static final SmtpServer smtpServer = TestMailServer.smtp(0);
@@ -62,6 +65,9 @@ public class ApplicationTests {
@Autowired
private Session<FTPFile> session;
@Autowired
private SourcePollingChannelAdapter fileInboundChannelAdapter;
@BeforeClass
public static void setup() {
// Configure the boot property to send email to the test email server.
@@ -74,6 +80,7 @@ public class ApplicationTests {
@Before
public void beforeTest() {
smtpServer.getMessages().clear();
this.fileInboundChannelAdapter.start();
}
@SuppressWarnings("unchecked")