use of org.apache.flink.runtime.executiongraph.ExecutionVertex in project flink by apache.
the class BackPressureStatsTrackerTest method mockExecutionVertex.
private ExecutionVertex mockExecutionVertex(ExecutionJobVertex jobVertex, int subTaskIndex) {
Execution exec = mock(Execution.class);
when(exec.getAttemptId()).thenReturn(new ExecutionAttemptID());
JobVertexID id = jobVertex.getJobVertexId();
ExecutionVertex vertex = mock(ExecutionVertex.class);
when(vertex.getJobvertexId()).thenReturn(id);
when(vertex.getCurrentExecutionAttempt()).thenReturn(exec);
when(vertex.getParallelSubtaskIndex()).thenReturn(subTaskIndex);
return vertex;
}
use of org.apache.flink.runtime.executiongraph.ExecutionVertex in project flink by apache.
the class StackTraceSampleCoordinatorTest method testCollectStackTraceForUnknownTask.
/** Tests that collecting for a unknown task fails. */
@Test(expected = IllegalArgumentException.class)
public void testCollectStackTraceForUnknownTask() throws Exception {
ExecutionVertex[] vertices = new ExecutionVertex[] { mockExecutionVertex(new ExecutionAttemptID(), ExecutionState.RUNNING, true) };
coord.triggerStackTraceSample(vertices, 1, Time.milliseconds(100L), 0);
coord.collectStackTraces(0, new ExecutionAttemptID(), new ArrayList<StackTraceElement[]>());
}
use of org.apache.flink.runtime.executiongraph.ExecutionVertex in project flink by apache.
the class StackTraceSampleCoordinatorTest method testCancelStackTraceSample.
/** Tests cancelling of a pending sample. */
@Test
public void testCancelStackTraceSample() throws Exception {
ExecutionVertex[] vertices = new ExecutionVertex[] { mockExecutionVertex(new ExecutionAttemptID(), ExecutionState.RUNNING, true) };
Future<StackTraceSample> sampleFuture = coord.triggerStackTraceSample(vertices, 1, Time.milliseconds(100L), 0);
assertFalse(sampleFuture.isDone());
// Cancel
coord.cancelStackTraceSample(0, null);
// Verify completed
assertTrue(sampleFuture.isDone());
// Verify no more pending samples
assertEquals(0, coord.getNumberOfPendingSamples());
}
use of org.apache.flink.runtime.executiongraph.ExecutionVertex in project flink by apache.
the class StackTraceSampleCoordinatorTest method testTriggerStackTraceSample.
/** Tests simple trigger and collect of stack trace samples. */
@Test
public void testTriggerStackTraceSample() throws Exception {
ExecutionVertex[] vertices = new ExecutionVertex[] { mockExecutionVertex(new ExecutionAttemptID(), ExecutionState.RUNNING, true), mockExecutionVertex(new ExecutionAttemptID(), ExecutionState.RUNNING, true), mockExecutionVertex(new ExecutionAttemptID(), ExecutionState.RUNNING, true), mockExecutionVertex(new ExecutionAttemptID(), ExecutionState.RUNNING, true) };
int numSamples = 1;
Time delayBetweenSamples = Time.milliseconds(100L);
int maxStackTraceDepth = 0;
Future<StackTraceSample> sampleFuture = coord.triggerStackTraceSample(vertices, numSamples, delayBetweenSamples, maxStackTraceDepth);
// Verify messages have been sent
for (ExecutionVertex vertex : vertices) {
ExecutionAttemptID expectedExecutionId = vertex.getCurrentExecutionAttempt().getAttemptId();
TriggerStackTraceSample expectedMsg = new TriggerStackTraceSample(0, expectedExecutionId, numSamples, delayBetweenSamples, maxStackTraceDepth);
verify(vertex.getCurrentExecutionAttempt()).requestStackTraceSample(eq(0), eq(numSamples), eq(delayBetweenSamples), eq(maxStackTraceDepth), any(Time.class));
}
assertFalse(sampleFuture.isDone());
StackTraceElement[] stackTraceSample = Thread.currentThread().getStackTrace();
List<StackTraceElement[]> traces = new ArrayList<>();
traces.add(stackTraceSample);
traces.add(stackTraceSample);
traces.add(stackTraceSample);
// Collect stack traces
for (int i = 0; i < vertices.length; i++) {
ExecutionAttemptID executionId = vertices[i].getCurrentExecutionAttempt().getAttemptId();
coord.collectStackTraces(0, executionId, traces);
if (i == vertices.length - 1) {
assertTrue(sampleFuture.isDone());
} else {
assertFalse(sampleFuture.isDone());
}
}
// Verify completed stack trace sample
StackTraceSample sample = sampleFuture.get();
assertEquals(0, sample.getSampleId());
assertTrue(sample.getEndTime() >= sample.getStartTime());
Map<ExecutionAttemptID, List<StackTraceElement[]>> tracesByTask = sample.getStackTraces();
for (ExecutionVertex vertex : vertices) {
ExecutionAttemptID executionId = vertex.getCurrentExecutionAttempt().getAttemptId();
List<StackTraceElement[]> sampleTraces = tracesByTask.get(executionId);
assertNotNull("Task not found", sampleTraces);
assertTrue(traces.equals(sampleTraces));
}
// Verify no more pending sample
assertEquals(0, coord.getNumberOfPendingSamples());
// Verify no error on late collect
coord.collectStackTraces(0, vertices[0].getCurrentExecutionAttempt().getAttemptId(), traces);
}
use of org.apache.flink.runtime.executiongraph.ExecutionVertex in project flink by apache.
the class StackTraceSampleCoordinatorTest method testTriggerStackTraceSampleTimeout.
/** Tests that samples time out if they don't finish in time. */
@Test(timeout = 1000L)
public void testTriggerStackTraceSampleTimeout() throws Exception {
int timeout = 100;
coord = new StackTraceSampleCoordinator(system.dispatcher(), timeout);
final ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(1);
try {
ExecutionVertex[] vertices = new ExecutionVertex[] { mockExecutionVertexWithTimeout(new ExecutionAttemptID(), ExecutionState.RUNNING, scheduledExecutorService, timeout) };
Future<StackTraceSample> sampleFuture = coord.triggerStackTraceSample(vertices, 1, Time.milliseconds(100L), 0);
// Wait for the timeout
Thread.sleep(timeout * 2);
boolean success = false;
for (int i = 0; i < 10; i++) {
if (sampleFuture.isDone()) {
success = true;
break;
}
Thread.sleep(timeout);
}
assertTrue("Sample did not time out", success);
try {
sampleFuture.get();
fail("Expected exception.");
} catch (ExecutionException e) {
assertTrue(e.getCause().getCause().getMessage().contains("Timeout"));
}
// Collect after the timeout (should be ignored)
ExecutionAttemptID executionId = vertices[0].getCurrentExecutionAttempt().getAttemptId();
coord.collectStackTraces(0, executionId, new ArrayList<StackTraceElement[]>());
} finally {
scheduledExecutorService.shutdownNow();
}
}
Aggregations