Search in sources :

Example 6 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class BoltWrapperTest method testOpen.

@SuppressWarnings("unchecked")
@Test
public void testOpen() throws Exception {
    // utility mocks
    final StormConfig stormConfig = new StormConfig();
    final Configuration flinkConfig = new Configuration();
    final ExecutionConfig taskConfig = mock(ExecutionConfig.class);
    when(taskConfig.getGlobalJobParameters()).thenReturn(null).thenReturn(stormConfig).thenReturn(flinkConfig);
    final StreamingRuntimeContext taskContext = mock(StreamingRuntimeContext.class);
    when(taskContext.getExecutionConfig()).thenReturn(taskConfig);
    when(taskContext.getTaskName()).thenReturn("name");
    when(taskContext.getMetricGroup()).thenReturn(new UnregisteredMetricsGroup());
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    declarer.declare(new Fields("dummy"));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    // (1) open with no configuration
    {
        ExecutionConfig execConfig = mock(ExecutionConfig.class);
        when(execConfig.getGlobalJobParameters()).thenReturn(null);
        final IRichBolt bolt = mock(IRichBolt.class);
        BoltWrapper<Object, Object> wrapper = new BoltWrapper<Object, Object>(bolt);
        wrapper.setup(createMockStreamTask(execConfig), new StreamConfig(new Configuration()), mock(Output.class));
        wrapper.open();
        verify(bolt).prepare(any(Map.class), any(TopologyContext.class), any(OutputCollector.class));
    }
    // (2) open with a storm specific configuration
    {
        ExecutionConfig execConfig = mock(ExecutionConfig.class);
        when(execConfig.getGlobalJobParameters()).thenReturn(stormConfig);
        final IRichBolt bolt = mock(IRichBolt.class);
        BoltWrapper<Object, Object> wrapper = new BoltWrapper<Object, Object>(bolt);
        wrapper.setup(createMockStreamTask(execConfig), new StreamConfig(new Configuration()), mock(Output.class));
        wrapper.open();
        verify(bolt).prepare(same(stormConfig), any(TopologyContext.class), any(OutputCollector.class));
    }
    // (3) open with a flink config
    {
        final Configuration cfg = new Configuration();
        cfg.setString("foo", "bar");
        cfg.setInteger("the end (the int)", Integer.MAX_VALUE);
        ExecutionConfig execConfig = mock(ExecutionConfig.class);
        when(execConfig.getGlobalJobParameters()).thenReturn(new UnmodifiableConfiguration(cfg));
        TestDummyBolt testBolt = new TestDummyBolt();
        BoltWrapper<Object, Object> wrapper = new BoltWrapper<Object, Object>(testBolt);
        wrapper.setup(createMockStreamTask(execConfig), new StreamConfig(new Configuration()), mock(Output.class));
        wrapper.open();
        for (Entry<String, String> entry : cfg.toMap().entrySet()) {
            Assert.assertEquals(entry.getValue(), testBolt.config.get(entry.getKey()));
        }
    }
}
Also used : StormConfig(org.apache.flink.storm.util.StormConfig) IRichBolt(org.apache.storm.topology.IRichBolt) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) Configuration(org.apache.flink.configuration.Configuration) StreamingRuntimeContext(org.apache.flink.streaming.api.operators.StreamingRuntimeContext) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Entry(java.util.Map.Entry) Fields(org.apache.storm.tuple.Fields) TestDummyBolt(org.apache.flink.storm.util.TestDummyBolt) UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class BoltWrapperTest method testClose.

@SuppressWarnings("unchecked")
@Test
public void testClose() throws Exception {
    final IRichBolt bolt = mock(IRichBolt.class);
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    declarer.declare(new Fields("dummy"));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    final BoltWrapper<Object, Object> wrapper = new BoltWrapper<Object, Object>(bolt);
    wrapper.setup(createMockStreamTask(), new StreamConfig(new Configuration()), mock(Output.class));
    wrapper.close();
    wrapper.dispose();
    verify(bolt).cleanup();
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) Fields(org.apache.storm.tuple.Fields) UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) Configuration(org.apache.flink.configuration.Configuration) Output(org.apache.flink.streaming.api.operators.Output) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class TwoInputStreamTask method init.

@Override
public void init() throws Exception {
    StreamConfig configuration = getConfiguration();
    ClassLoader userClassLoader = getUserCodeClassLoader();
    TypeSerializer<IN1> inputDeserializer1 = configuration.getTypeSerializerIn1(userClassLoader);
    TypeSerializer<IN2> inputDeserializer2 = configuration.getTypeSerializerIn2(userClassLoader);
    int numberOfInputs = configuration.getNumberOfInputs();
    ArrayList<InputGate> inputList1 = new ArrayList<InputGate>();
    ArrayList<InputGate> inputList2 = new ArrayList<InputGate>();
    List<StreamEdge> inEdges = configuration.getInPhysicalEdges(userClassLoader);
    for (int i = 0; i < numberOfInputs; i++) {
        int inputType = inEdges.get(i).getTypeNumber();
        InputGate reader = getEnvironment().getInputGate(i);
        switch(inputType) {
            case 1:
                inputList1.add(reader);
                break;
            case 2:
                inputList2.add(reader);
                break;
            default:
                throw new RuntimeException("Invalid input type number: " + inputType);
        }
    }
    this.inputProcessor = new StreamTwoInputProcessor<>(inputList1, inputList2, inputDeserializer1, inputDeserializer2, this, configuration.getCheckpointMode(), getCheckpointLock(), getEnvironment().getIOManager(), getEnvironment().getTaskManagerInfo().getConfiguration(), getStreamStatusMaintainer(), this.headOperator);
    // make sure that stream tasks report their I/O statistics
    inputProcessor.setMetricGroup(getEnvironment().getMetricGroup().getIOMetricGroup());
}
Also used : ArrayList(java.util.ArrayList) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) StreamEdge(org.apache.flink.streaming.api.graph.StreamEdge) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate)

Example 9 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class AsyncWaitOperatorTest method testTimeoutCleanup.

/**
	 * FLINK-5652
	 * Tests that registered timers are properly canceled upon completion of a
	 * {@link StreamRecordQueueEntry} in order to avoid resource leaks because TriggerTasks hold
	 * a reference on the StreamRecordQueueEntry.
	 */
@Test
public void testTimeoutCleanup() throws Exception {
    final Object lock = new Object();
    final long timeout = 100000L;
    final long timestamp = 1L;
    Environment environment = mock(Environment.class);
    when(environment.getMetricGroup()).thenReturn(new UnregisteredTaskMetricsGroup());
    when(environment.getTaskManagerInfo()).thenReturn(new TestingTaskManagerRuntimeInfo());
    when(environment.getUserClassLoader()).thenReturn(getClass().getClassLoader());
    when(environment.getTaskInfo()).thenReturn(new TaskInfo("testTask", 1, 0, 1, 0));
    ScheduledFuture<?> scheduledFuture = mock(ScheduledFuture.class);
    ProcessingTimeService processingTimeService = mock(ProcessingTimeService.class);
    when(processingTimeService.getCurrentProcessingTime()).thenReturn(timestamp);
    doReturn(scheduledFuture).when(processingTimeService).registerTimer(anyLong(), any(ProcessingTimeCallback.class));
    StreamTask<?, ?> containingTask = mock(StreamTask.class);
    when(containingTask.getEnvironment()).thenReturn(environment);
    when(containingTask.getCheckpointLock()).thenReturn(lock);
    when(containingTask.getProcessingTimeService()).thenReturn(processingTimeService);
    StreamConfig streamConfig = mock(StreamConfig.class);
    doReturn(IntSerializer.INSTANCE).when(streamConfig).getTypeSerializerIn1(any(ClassLoader.class));
    Output<StreamRecord<Integer>> output = mock(Output.class);
    AsyncWaitOperator<Integer, Integer> operator = new AsyncWaitOperator<>(new AsyncFunction<Integer, Integer>() {

        private static final long serialVersionUID = -3718276118074877073L;

        @Override
        public void asyncInvoke(Integer input, AsyncCollector<Integer> collector) throws Exception {
            collector.collect(Collections.singletonList(input));
        }
    }, timeout, 1, AsyncDataStream.OutputMode.UNORDERED);
    operator.setup(containingTask, streamConfig, output);
    operator.open();
    final StreamRecord<Integer> streamRecord = new StreamRecord<>(42, timestamp);
    synchronized (lock) {
        // processing an element will register a timeout
        operator.processElement(streamRecord);
    }
    synchronized (lock) {
        // closing the operator waits until all inputs have been processed
        operator.close();
    }
    // check that we actually outputted the result of the single input
    verify(output).collect(eq(streamRecord));
    verify(processingTimeService).registerTimer(eq(processingTimeService.getCurrentProcessingTime() + timeout), any(ProcessingTimeCallback.class));
    // check that we have cancelled our registered timeout
    verify(scheduledFuture).cancel(eq(true));
}
Also used : UnregisteredTaskMetricsGroup(org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TaskInfo(org.apache.flink.api.common.TaskInfo) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) ProcessingTimeCallback(org.apache.flink.streaming.runtime.tasks.ProcessingTimeCallback) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) ProcessingTimeService(org.apache.flink.streaming.runtime.tasks.ProcessingTimeService) Environment(org.apache.flink.runtime.execution.Environment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) StreamMockEnvironment(org.apache.flink.streaming.runtime.tasks.StreamMockEnvironment) Test(org.junit.Test)

Example 10 with StreamConfig

use of org.apache.flink.streaming.api.graph.StreamConfig in project flink by apache.

the class StreamSourceOperatorTest method setupSourceOperator.

@SuppressWarnings("unchecked")
private static <T> void setupSourceOperator(StreamSource<T, ?> operator, TimeCharacteristic timeChar, long watermarkInterval, long latencyMarkInterval, final ProcessingTimeService timeProvider) {
    ExecutionConfig executionConfig = new ExecutionConfig();
    executionConfig.setAutoWatermarkInterval(watermarkInterval);
    executionConfig.setLatencyTrackingInterval(latencyMarkInterval);
    StreamConfig cfg = new StreamConfig(new Configuration());
    cfg.setStateBackend(new MemoryStateBackend());
    cfg.setTimeCharacteristic(timeChar);
    Environment env = new DummyEnvironment("MockTwoInputTask", 1, 0);
    StreamStatusMaintainer streamStatusMaintainer = mock(StreamStatusMaintainer.class);
    when(streamStatusMaintainer.getStreamStatus()).thenReturn(StreamStatus.ACTIVE);
    StreamTask<?, ?> mockTask = mock(StreamTask.class);
    when(mockTask.getName()).thenReturn("Mock Task");
    when(mockTask.getCheckpointLock()).thenReturn(new Object());
    when(mockTask.getConfiguration()).thenReturn(cfg);
    when(mockTask.getEnvironment()).thenReturn(env);
    when(mockTask.getExecutionConfig()).thenReturn(executionConfig);
    when(mockTask.getAccumulatorMap()).thenReturn(Collections.<String, Accumulator<?, ?>>emptyMap());
    when(mockTask.getStreamStatusMaintainer()).thenReturn(streamStatusMaintainer);
    doAnswer(new Answer<ProcessingTimeService>() {

        @Override
        public ProcessingTimeService answer(InvocationOnMock invocation) throws Throwable {
            if (timeProvider == null) {
                throw new RuntimeException("The time provider is null.");
            }
            return timeProvider;
        }
    }).when(mockTask).getProcessingTimeService();
    operator.setup(mockTask, cfg, (Output<StreamRecord<T>>) mock(Output.class));
}
Also used : StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) StreamStatusMaintainer(org.apache.flink.streaming.runtime.streamstatus.StreamStatusMaintainer) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) ProcessingTimeService(org.apache.flink.streaming.runtime.tasks.ProcessingTimeService) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) Environment(org.apache.flink.runtime.execution.Environment)

Aggregations

StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)98 Test (org.junit.Test)57 Configuration (org.apache.flink.configuration.Configuration)41 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)40 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)16 Task (org.apache.flink.runtime.taskmanager.Task)16 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)14 ArrayList (java.util.ArrayList)13 StreamEdge (org.apache.flink.streaming.api.graph.StreamEdge)13 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)12 NettyShuffleEnvironmentBuilder (org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder)12 StreamMap (org.apache.flink.streaming.api.operators.StreamMap)12 Environment (org.apache.flink.runtime.execution.Environment)9 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)8 CoStreamMap (org.apache.flink.streaming.api.operators.co.CoStreamMap)8 OneInputStreamTaskTestHarness (org.apache.flink.streaming.runtime.tasks.OneInputStreamTaskTestHarness)8 MockStreamTaskBuilder (org.apache.flink.streaming.util.MockStreamTaskBuilder)8 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)7