Search in sources :

Example 1 with FiniteTestSpout

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);
}
Also used : StreamingRuntimeContext(org.apache.flink.streaming.api.operators.StreamingRuntimeContext) Tuple1(org.apache.flink.api.java.tuple.Tuple1) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) FiniteTestSpout(org.apache.flink.storm.util.FiniteTestSpout) LinkedList(java.util.LinkedList) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with FiniteTestSpout

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);
}
Also used : IRichSpout(org.apache.storm.topology.IRichSpout) StreamingRuntimeContext(org.apache.flink.streaming.api.operators.StreamingRuntimeContext) Tuple1(org.apache.flink.api.java.tuple.Tuple1) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) FiniteTestSpout(org.apache.flink.storm.util.FiniteTestSpout) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 Tuple1 (org.apache.flink.api.java.tuple.Tuple1)2 AbstractTest (org.apache.flink.storm.util.AbstractTest)2 FiniteTestSpout (org.apache.flink.storm.util.FiniteTestSpout)2 StreamingRuntimeContext (org.apache.flink.streaming.api.operators.StreamingRuntimeContext)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 LinkedList (java.util.LinkedList)1 IRichSpout (org.apache.storm.topology.IRichSpout)1