I have a multi-step spring batch job. The last of which is an sftp step. I am trying to unit test the entire job (I am aware that I can unit test each step, but either way I will have to face this problem). I have defined a test profile in my application context which contains beans that I use for test. My non-test sftp works successfully and transmits files correctly. Yet, when attempting to use localhost for test, something goes wrong. I have read similar questions such as Using Apache Mina as a Mock/In Memory SFTP Server for Unit Testing which was helpful but is not exactly what I am looking for.
What currently happens when I run my test is that the program stops when it reaches following line in my code:
sftpChannel.send(message);
The application still runs but I can see from my debug that nothing is happening.
My problem is not a connection problem, as my logs indicate:
2813 [main] INFO com.jcraft.jsch - Connecting to localhost port 9000
2813 [main] INFO com.jcraft.jsch - Connection established
Here is my sftp code from my application context:
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="localhost"/>
<property name="user" value="user"/>
<property name="password" value="password"/>
<property name="port" value="9000"/>
</bean>
<int:channel id="outputChannel" />
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
session-factory="sftpSessionFactory"
channel="outputChannel"
charset="UTF-8"
remote-directory="testFolder/ftp"
remote-filename-generator="fileNameGenerator"
/>
<bean id="fileNameGenerator" class="org.springframework.integration.file.DefaultFileNameGenerator"/>
Any ideas why my file is not getting delivered?
Thanks in advance!
UPDATE
Let me add more code... My spring batch step simply calls a tasklet which takes in:
p:sftpChannel-ref="outputChannel"
My tasklet sets the sftpChannel like this
public void setSftpChannel(MessageChannel sftpChannel) {
this.sftpChannel = sftpChannel;
}
Upon doing some more research my problem is most certainly that MessageChannel blocks indefinitely - which is documented in spring docs here
For some reason when I use the overloaded method of send(Message, long) it still blocks indefinitely even once it has reached the time i specify in the long.
The question that remains for me is why is MessageChannel blocking? And why even when I specify a timeout?