use of org.apache.flink.storm.util.FiniteTestSpout in project flink by apache.
the class SpoutWrapperTest method testRunExecuteFinite.
@Test
public void testRunExecuteFinite() throws Exception {
final int numberOfCalls = this.r.nextInt(50);
final LinkedList<Tuple1<Integer>> expectedResult = new LinkedList<Tuple1<Integer>>();
for (int i = numberOfCalls - 1; i >= 0; --i) {
expectedResult.add(new Tuple1<Integer>(new Integer(i)));
}
final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
when(taskContext.getExecutionConfig()).thenReturn(mock(ExecutionConfig.class));
when(taskContext.getTaskName()).thenReturn("name");
final FiniteTestSpout spout = new FiniteTestSpout(numberOfCalls);
final SpoutWrapper<Tuple1<Integer>> spoutWrapper = new SpoutWrapper<Tuple1<Integer>>(spout, -1);
spoutWrapper.setRuntimeContext(taskContext);
final TestContext collector = new TestContext();
spoutWrapper.run(collector);
Assert.assertEquals(expectedResult, collector.result);
}
use of org.apache.flink.storm.util.FiniteTestSpout in project flink by apache.
the class SpoutWrapperTest method testCancel.
@Test
public void testCancel() throws Exception {
final int numberOfCalls = 5 + this.r.nextInt(5);
final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
when(taskContext.getExecutionConfig()).thenReturn(mock(ExecutionConfig.class));
when(taskContext.getTaskName()).thenReturn("name");
final IRichSpout spout = new FiniteTestSpout(numberOfCalls);
final SpoutWrapper<Tuple1<Integer>> spoutWrapper = new SpoutWrapper<Tuple1<Integer>>(spout);
spoutWrapper.setRuntimeContext(taskContext);
spoutWrapper.cancel();
final TestContext collector = new TestContext();
spoutWrapper.run(collector);
Assert.assertEquals(new LinkedList<Tuple1<Integer>>(), collector.result);
}
Aggregations