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);
});
}
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;
}
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;
}
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);
}
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;
}
Aggregations