【发布时间】:2020-03-25 20:46:31
【问题描述】:
我正在尝试编写一个模拟“中断”阶段的测试。 所以我想
- 启动本地代理
- 发送消息1
- 停止代理
- 发送message2(当然不会到达)
- 再次启动代理
- 发送消息3
根据http://activemq.apache.org/how-do-i-restart-embedded-broker.html建议重新初始化一个BrokerService来重新启动broker。 所以代码看起来(几乎)是这样的:
private BrokerService _broker;
private void startBroker() throws Exception {
_broker = new BrokerService();
_broker.addConnector("vm://localhost?broker.persistent=false");
_broker.start();
_broker.waitUntilStarted();
}
private void stopBroker() throws Exception {
_broker.stop();
_broker.waitUntilStopped();
}
@Test
public void publishMessagesWithServerBreakdownInBetween()
throws Exception
{
startBroker();
... send and receive message (works fine)
stopBroker();
... send message (fails of course)
startBroker(); // this fails with java.io.IOException: VMTransportServer already bound at: vm://localhost?broker.persistent=false
... send and receive message
}
该问题已在代码中作为注释提到: 由于错误,代理重新启动失败:java.io.IOException: VMTransportServer already bound at: vm://localhost?broker.persistent=false
我在 ActiveMQ 论坛 (http://activemq.2283324.n4.nabble.com/VMTransportServer-already-bound-td2364603.html) 发现了类似的问题,但在我的情况下,主机名不为空。
另一个想法是设置 2 个不同的代理名称,但这也没有帮助。
我做错了什么?
【问题讨论】:
-
只是好奇,为什么需要在测试之间启动/停止代理?
标签: java unit-testing activemq