0

I often have a requirement to wait some async process is finished in my devKit connector (which then causes isConnected to return true )

@ValidateConnection
public boolean isConnected() {
    return isConnected;
}

How can I get my functional unit test to wait until this is completed. I would have thought the unit test would have waited until all the connectors in my flow were "connected".

Atm I am using a sleep in the unit test to get round this in my FunctionalTestCase

Thread.sleep(5000);

assertEquals(1, targetEngineApplication.getNumberOfMessagesReveived());

Edit_____________________

the connect code:

@Connect
public void connectMethod(final String configFileLocation) throws ConnectionException {

    System.out.println("Connect called with config:" + configFileLocation);
    try {
        Engine.doInitialise(configFileLocation);
        Engine.doStart();
    } catch (InitialisationException e) {
        throw new ConnectionException(ConnectionExceptionCode.UNKNOWN, "0", e.getCause().getMessage(), e);
    } catch (StartingException e) {
        throw new ConnectionException(ConnectionExceptionCode.UNKNOWN, "0", e.getCause().getMessage(), e);
    }
    // this will also tell the unit tests to start
    isConnected = true;
}
Nikos
  • 7,295
  • 7
  • 52
  • 88

1 Answers1

2

It's the case: when the functional test starts, everything that needs to be initialized and started is.

The notion of "connected" for DevKit connectors is different: connection happens on demand when a message processor is used.

So what do you want to wait for in your test: that an initialization sequence of the connector has been done or that a particular processor method has been executed?

For the record, chapter 12 of Mule in Action covers testing techniques that allow dealing with asynchronous scenarios.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • Hi David! My connector has to pool an external system waiting for a log on success – Nikos Jul 06 '13 at 07:11
  • How is annotated the method where this log on happens? – David Dossot Jul 06 '13 at 20:11
  • 1
    `@Connect`-annotated method is automatically called when using a message processor, not when Mule initializes. Create a test flow that uses a message processor from your connector: this will call `@Connect` indirectly. – David Dossot Jul 08 '13 at 14:59
  • I'm actually finding it called before any message processors, I actually think I need to use a flag in the connector (I use the @ValidateConnection) and just poll that in the unit test. – Nikos Jul 10 '13 at 07:53