Getting functional unit tests to wait until devkit connector is connected

廉价感情. 提交于 2019-12-25 07:31:13

问题


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;
}

回答1:


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.



来源:https://stackoverflow.com/questions/17491031/getting-functional-unit-tests-to-wait-until-devkit-connector-is-connected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!