Search in sources :

Example 1 with FiniteSpout

use of org.apache.flink.storm.util.FiniteSpout in project flink by apache.

the class SpoutWrapper method run.

@Override
public final void run(final SourceContext<OUT> ctx) throws Exception {
    final GlobalJobParameters config = super.getRuntimeContext().getExecutionConfig().getGlobalJobParameters();
    StormConfig stormConfig = new StormConfig();
    if (config != null) {
        if (config instanceof StormConfig) {
            stormConfig = (StormConfig) config;
        } else {
            stormConfig.putAll(config.toMap());
        }
    }
    final TopologyContext stormTopologyContext = WrapperSetupHelper.createTopologyContext((StreamingRuntimeContext) super.getRuntimeContext(), this.spout, this.name, this.stormTopology, stormConfig);
    SpoutCollector<OUT> collector = new SpoutCollector<OUT>(this.numberOfAttributes, stormTopologyContext.getThisTaskId(), ctx);
    this.spout.open(stormConfig, stormTopologyContext, new SpoutOutputCollector(collector));
    this.spout.activate();
    if (numberOfInvocations == null) {
        if (this.spout instanceof FiniteSpout) {
            final FiniteSpout finiteSpout = (FiniteSpout) this.spout;
            while (this.isRunning && !finiteSpout.reachedEnd()) {
                finiteSpout.nextTuple();
            }
        } else {
            while (this.isRunning) {
                this.spout.nextTuple();
            }
        }
    } else {
        int counter = this.numberOfInvocations;
        if (counter >= 0) {
            while ((--counter >= 0) && this.isRunning) {
                this.spout.nextTuple();
            }
        } else {
            do {
                collector.tupleEmitted = false;
                this.spout.nextTuple();
            } while (collector.tupleEmitted && this.isRunning);
        }
    }
}
Also used : StormConfig(org.apache.flink.storm.util.StormConfig) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) TopologyContext(org.apache.storm.task.TopologyContext) GlobalJobParameters(org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters) FiniteSpout(org.apache.flink.storm.util.FiniteSpout)

Example 2 with FiniteSpout

use of org.apache.flink.storm.util.FiniteSpout in project flink by apache.

the class SpoutWrapperTest method runAndExecuteFiniteSpout.

@SuppressWarnings("unchecked")
@Test
public void runAndExecuteFiniteSpout() throws Exception {
    final FiniteSpout stormSpout = mock(FiniteSpout.class);
    when(stormSpout.reachedEnd()).thenReturn(false, false, false, true, false, false, true);
    final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
    when(taskContext.getExecutionConfig()).thenReturn(mock(ExecutionConfig.class));
    when(taskContext.getTaskName()).thenReturn("name");
    final SpoutWrapper<?> wrapper = new SpoutWrapper<Object>(stormSpout);
    wrapper.setRuntimeContext(taskContext);
    wrapper.run(mock(SourceContext.class));
    verify(stormSpout, times(3)).nextTuple();
}
Also used : StreamingRuntimeContext(org.apache.flink.streaming.api.operators.StreamingRuntimeContext) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) SourceContext(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext) FiniteSpout(org.apache.flink.storm.util.FiniteSpout) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with FiniteSpout

use of org.apache.flink.storm.util.FiniteSpout in project flink by apache.

the class SpoutWrapperTest method runAndExecuteFiniteSpout2.

@SuppressWarnings("unchecked")
@Test
public void runAndExecuteFiniteSpout2() throws Exception {
    final FiniteSpout stormSpout = mock(FiniteSpout.class);
    when(stormSpout.reachedEnd()).thenReturn(true, false, true, false, true, false, true);
    final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
    when(taskContext.getExecutionConfig()).thenReturn(mock(ExecutionConfig.class));
    when(taskContext.getTaskName()).thenReturn("name");
    final SpoutWrapper<?> wrapper = new SpoutWrapper<Object>(stormSpout);
    wrapper.setRuntimeContext(taskContext);
    wrapper.run(mock(SourceContext.class));
    verify(stormSpout, never()).nextTuple();
}
Also used : StreamingRuntimeContext(org.apache.flink.streaming.api.operators.StreamingRuntimeContext) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) SourceContext(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext) FiniteSpout(org.apache.flink.storm.util.FiniteSpout) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FiniteSpout (org.apache.flink.storm.util.FiniteSpout)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 AbstractTest (org.apache.flink.storm.util.AbstractTest)2 SourceContext (org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext)2 StreamingRuntimeContext (org.apache.flink.streaming.api.operators.StreamingRuntimeContext)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 GlobalJobParameters (org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters)1 StormConfig (org.apache.flink.storm.util.StormConfig)1 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)1 TopologyContext (org.apache.storm.task.TopologyContext)1