2

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?

Community
  • 1
  • 1
user821863
  • 479
  • 5
  • 15
  • 1. Are you really sure that `sftpChannel` is exactly your `outputChannel` from config? 2. Try to switch on DEBUG logging for `org.springframework.integration`category and take a look into result logs afte Message sendidng. – Artem Bilan Dec 27 '13 at 15:11
  • @ArtemBilan 1. Yes. I can see in debug that it has a bean outputChannel. Additionally, it works outside of test. 2. How do I switch on logging? It's not enabled automatically? Thank you for your help! – user821863 Dec 27 '13 at 15:34
  • No, it's not by default. You should create `log4j.properties` (or apropriate for your logging framework) in test resources and configure DEBUG for SI package – Artem Bilan Dec 27 '13 at 15:38
  • @ArtemBilan Well, I added debugging. And there are no messages after the connection established message that i wrote above. It's not getting to the message sending phase... I did however notice this in the debugs logs which I have to look into... `ResourcelessTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT` – user821863 Dec 27 '13 at 16:08
  • Well, show your unit test, please – Artem Bilan Dec 27 '13 at 16:13
  • @ArtemBilan I updated my question. My unit test simply calls the spring batch job. And the sftp step just calls the tasklet passing in the outputChannel above. Tasklet is working up until that `send(Message)` line of my code. Thanks again for your help. – user821863 Dec 27 '13 at 20:42
  • Well, as it is your code and your test-case, so just put a break point within your Taskelt and try to investigate what's going on. – Artem Bilan Dec 27 '13 at 20:55
  • @ArtemBilan I have. All it does it stop at the send method. never reaches next line of code. Nothing is getting logged. But the program continues to run, just waits at that point though. – user821863 Dec 27 '13 at 21:10
  • How about to do 'step in' into `channel.send()` and dig further, where your Thread is blocked?.. – Artem Bilan Dec 28 '13 at 11:15

0 Answers0