Mule 让功能单元测试等待devkit连接器连接

Mule 让功能单元测试等待devkit连接器连接,mule,mule-studio,devkit,Mule,Mule Studio,Devkit,我经常需要等待devKit连接器中的某个异步进程完成(这会导致isConnected返回true) 我怎样才能让我的功能单元测试等待,直到它完成。我本以为单元测试会一直等到流中的所有连接器都“连接”起来 Atm我在功能测试用例中使用单元测试中的睡眠来解决这个问题 Thread.sleep(5000); assertEquals(1, targetEngineApplication.getNumberOfMessagesReveived()); 编辑 连接代码: @Connect public

我经常需要等待devKit连接器中的某个异步进程完成(这会导致isConnected返回true)

我怎样才能让我的功能单元测试等待,直到它完成。我本以为单元测试会一直等到流中的所有连接器都“连接”起来

Atm我在功能测试用例中使用单元测试中的睡眠来解决这个问题

Thread.sleep(5000);

assertEquals(1, targetEngineApplication.getNumberOfMessagesReveived());
编辑

连接代码:

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

情况是这样的:当功能测试开始时,需要初始化和启动的所有内容都被删除了

DevKit连接器的“已连接”概念是不同的:当使用消息处理器时,根据需要进行连接

那么,在测试中您希望等待什么:连接器的初始化序列已经完成,或者特定的处理器方法已经执行


为了记录在案,第12章介绍了允许处理异步场景的测试技术。

Hi David!我的连接器必须共用一个等待登录成功的外部系统。如何对发生此登录的方法进行注释?
@Connect
-在使用消息处理器时,而不是在Mule初始化时,自动调用注释的方法。创建一个使用来自连接器的消息处理器的测试流:这将间接调用
@Connect
。我发现它在任何消息处理器之前被调用,我认为我需要在连接器中使用一个标志(我使用@ValidateConnection)并在单元测试中轮询它。
@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;
}