[英]How to test Spouts in Storm
I am struggling with a task to unit test my Apache Storm spout which actually reads from a queue and emits a message as a tuple. 我正在努力对我的Apache Storm喷口进行单元测试,该喷口实际上是从队列中读取并以元组的形式发出消息。 I want to use embedded queue, put a message onto the queue and asset that message is emitted by my spout.
我想使用嵌入式队列,将一条消息放到队列中,并确定该喷口发出该消息的资产。 Could anyone help what to use to accomplish that?
任何人都可以帮助使用什么来完成该任务吗?
There are probably a ton of ways you can do this but here is an example of a simple test using mockito and testng (\\src\\test\\java\\com\\example\\storm\\spout\\DummySpoutTest.java): 您可能有很多方法可以执行此操作,但是以下是使用模仿和testng(\\ src \\ test \\ java \\ com \\ example \\ storm \\ spout \\ DummySpoutTest.java)进行的简单测试的示例:
package com.example.storm.spout;
import static org.mockito.Matchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.testng.annotations.Test;
import backtype.storm.spout.SpoutOutputCollector;
import com.example.storm.spout.DummySpout;
public class DummySpoutTest {
@SuppressWarnings("unchecked")
@Test
public void shouldCreateDummyMessage() {
// given
DummySpout spout = new DummySpout();
SpoutOutputCollector collector = mock(SpoutOutputCollector.class);
spout.open(null, null, collector);
// when
spout.nextTuple();
// then
verify(collector).emit(anyList());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.