Search in sources :

Example 16 with Environment

use of org.apache.flink.runtime.execution.Environment in project flink by apache.

the class StreamSourceOperatorLatencyMetricsTest method testLatencyMarkEmissionDisabledOverrideViaExecutionConfig.

/**
 * Verifies that latency metrics can be disabled via the {@link ExecutionConfig} even if they
 * are enabled via the configuration.
 */
@Test
public void testLatencyMarkEmissionDisabledOverrideViaExecutionConfig() throws Exception {
    testLatencyMarkEmission(0, (operator, timeProvider) -> {
        Configuration tmConfig = new Configuration();
        tmConfig.setLong(MetricOptions.LATENCY_INTERVAL, latencyMarkInterval);
        Environment env = MockEnvironment.builder().setTaskManagerRuntimeInfo(new TestingTaskManagerRuntimeInfo(tmConfig)).build();
        ExecutionConfig executionConfig = new ExecutionConfig();
        executionConfig.setLatencyTrackingInterval(0);
        setupSourceOperator(operator, executionConfig, env, timeProvider);
    });
}
Also used : TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) Configuration(org.apache.flink.configuration.Configuration) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) Environment(org.apache.flink.runtime.execution.Environment) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 17 with Environment

use of org.apache.flink.runtime.execution.Environment in project flink by apache.

the class BoltWrapperTest method createMockStreamTask.

public static StreamTask<?, ?> createMockStreamTask(ExecutionConfig execConfig) {
    Environment env = mock(Environment.class);
    when(env.getTaskInfo()).thenReturn(new TaskInfo("Mock Task", 1, 0, 1, 0));
    when(env.getUserClassLoader()).thenReturn(BoltWrapperTest.class.getClassLoader());
    when(env.getMetricGroup()).thenReturn(new UnregisteredTaskMetricsGroup());
    when(env.getTaskManagerInfo()).thenReturn(new TestingTaskManagerRuntimeInfo());
    StreamTask<?, ?> mockTask = mock(StreamTask.class);
    when(mockTask.getCheckpointLock()).thenReturn(new Object());
    when(mockTask.getConfiguration()).thenReturn(new StreamConfig(new Configuration()));
    when(mockTask.getEnvironment()).thenReturn(env);
    when(mockTask.getExecutionConfig()).thenReturn(execConfig);
    return mockTask;
}
Also used : TaskInfo(org.apache.flink.api.common.TaskInfo) UnregisteredTaskMetricsGroup(org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) Configuration(org.apache.flink.configuration.Configuration) Environment(org.apache.flink.runtime.execution.Environment) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig)

Example 18 with Environment

use of org.apache.flink.runtime.execution.Environment in project flink by apache.

the class RocksDBStateBackendConfigTest method getMockEnvironment.

static Environment getMockEnvironment(File[] tempDirs) {
    final String[] tempDirStrings = new String[tempDirs.length];
    for (int i = 0; i < tempDirs.length; i++) {
        tempDirStrings[i] = tempDirs[i].getAbsolutePath();
    }
    IOManager ioMan = mock(IOManager.class);
    when(ioMan.getSpillingDirectories()).thenReturn(tempDirs);
    Environment env = mock(Environment.class);
    when(env.getJobID()).thenReturn(new JobID());
    when(env.getUserClassLoader()).thenReturn(RocksDBStateBackendConfigTest.class.getClassLoader());
    when(env.getIOManager()).thenReturn(ioMan);
    when(env.getTaskKvStateRegistry()).thenReturn(new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
    TaskInfo taskInfo = mock(TaskInfo.class);
    when(env.getTaskInfo()).thenReturn(taskInfo);
    when(taskInfo.getIndexOfThisSubtask()).thenReturn(0);
    TaskManagerRuntimeInfo tmInfo = new TestingTaskManagerRuntimeInfo(new Configuration(), tempDirStrings);
    when(env.getTaskManagerInfo()).thenReturn(tmInfo);
    return env;
}
Also used : KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) Configuration(org.apache.flink.configuration.Configuration) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) TaskManagerRuntimeInfo(org.apache.flink.runtime.taskmanager.TaskManagerRuntimeInfo) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) Mockito.anyString(org.mockito.Mockito.anyString) TaskInfo(org.apache.flink.api.common.TaskInfo) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) Environment(org.apache.flink.runtime.execution.Environment) JobID(org.apache.flink.api.common.JobID)

Example 19 with Environment

use of org.apache.flink.runtime.execution.Environment in project flink by apache.

the class ChainedDriver method setup.

public void setup(TaskConfig config, String taskName, Collector<OT> outputCollector, AbstractInvokable parent, ClassLoader userCodeClassLoader, ExecutionConfig executionConfig, Map<String, Accumulator<?, ?>> accumulatorMap) {
    this.config = config;
    this.taskName = taskName;
    this.userCodeClassLoader = userCodeClassLoader;
    this.metrics = parent.getEnvironment().getMetricGroup().addOperator(taskName);
    this.numRecordsIn = this.metrics.getIOMetricGroup().getNumRecordsInCounter();
    this.numRecordsOut = this.metrics.getIOMetricGroup().getNumRecordsOutCounter();
    this.outputCollector = new CountingCollector<>(outputCollector, numRecordsOut);
    Environment env = parent.getEnvironment();
    if (parent instanceof BatchTask) {
        this.udfContext = ((BatchTask<?, ?>) parent).createRuntimeContext(metrics);
    } else {
        this.udfContext = new DistributedRuntimeUDFContext(env.getTaskInfo(), userCodeClassLoader, parent.getExecutionConfig(), env.getDistributedCacheEntries(), accumulatorMap, metrics);
    }
    this.executionConfig = executionConfig;
    this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();
    setup(parent);
}
Also used : DistributedRuntimeUDFContext(org.apache.flink.runtime.operators.util.DistributedRuntimeUDFContext) BatchTask(org.apache.flink.runtime.operators.BatchTask) Environment(org.apache.flink.runtime.execution.Environment)

Example 20 with Environment

use of org.apache.flink.runtime.execution.Environment in project flink by apache.

the class StreamTask method createOperatorStateBackend.

public OperatorStateBackend createOperatorStateBackend(StreamOperator<?> op, Collection<OperatorStateHandle> restoreStateHandles) throws Exception {
    Environment env = getEnvironment();
    String opId = createOperatorIdentifier(op, getConfiguration().getVertexID());
    OperatorStateBackend operatorStateBackend = stateBackend.createOperatorStateBackend(env, opId);
    // let operator state backend participate in the operator lifecycle, i.e. make it responsive to cancelation
    cancelables.registerClosable(operatorStateBackend);
    // restore if we have some old state
    if (null != restoreStateHandles) {
        operatorStateBackend.restore(restoreStateHandles);
    }
    return operatorStateBackend;
}
Also used : OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) Environment(org.apache.flink.runtime.execution.Environment)

Aggregations

Environment (org.apache.flink.runtime.execution.Environment)33 Configuration (org.apache.flink.configuration.Configuration)15 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)14 Test (org.junit.Test)13 TestingTaskManagerRuntimeInfo (org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo)9 TaskInfo (org.apache.flink.api.common.TaskInfo)8 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)8 IOException (java.io.IOException)6 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)6 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)6 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)6 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)6 JobID (org.apache.flink.api.common.JobID)5 UnregisteredTaskMetricsGroup (org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup)5 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)4 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)4 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)4 ExecutionException (java.util.concurrent.ExecutionException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)3