获取功能单元测试以等待连接devkit连接器 [英] Getting functional unit tests to wait until devkit connector is connected

查看:105
本文介绍了获取功能单元测试以等待连接devkit连接器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常需要等待我的devKit连接器中的一些异步过程完成(然后导致isConnected返回true)

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我正在单元测试中使用睡眠,以在我的FunctionalTestCase中解决这个问题

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_____________________

连接代码:

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

推荐答案

情况是这样的:当功能测试开始时,所有需要初始化和启动的东西都已经存在.

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

DevKit连接器的已连接"概念不同:使用消息处理器时按需进行连接.

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?

为便于记录, ule子在行中的第12章介绍了允许处理异步的测试技术.场景.

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

这篇关于获取功能单元测试以等待连接devkit连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆