use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class IntrinsicMapTaskExecutorTest method testExceptionInFinishAbortsAllOperations.
@Test
public void testExceptionInFinishAbortsAllOperations() throws Exception {
Operation o1 = Mockito.mock(Operation.class);
Operation o2 = Mockito.mock(Operation.class);
Operation o3 = Mockito.mock(Operation.class);
Mockito.doThrow(new Exception("in finish")).when(o2).finish();
ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
try (IntrinsicMapTaskExecutor executor = IntrinsicMapTaskExecutor.withSharedCounterSet(Arrays.<Operation>asList(o1, o2, o3), counterSet, stateTracker)) {
executor.execute();
fail("Should have thrown");
} catch (Exception e) {
InOrder inOrder = Mockito.inOrder(o1, o2, o3);
inOrder.verify(o3).start();
inOrder.verify(o2).start();
inOrder.verify(o1).start();
inOrder.verify(o1).finish();
inOrder.verify(o2).finish();
// Order of abort doesn't matter
Mockito.verify(o1).abort();
Mockito.verify(o2).abort();
Mockito.verify(o3).abort();
Mockito.verifyNoMoreInteractions(o1, o2, o3);
}
}
use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class IntrinsicMapTaskExecutorTest method testValidOperations.
@Test
public void testValidOperations() throws Exception {
TestOutputReceiver receiver = new TestOutputReceiver(counterSet, NameContextsForTests.nameContextForTest());
List<Operation> operations = Arrays.<Operation>asList(new TestReadOperation(receiver, createContext("ReadOperation")));
ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
try (IntrinsicMapTaskExecutor executor = IntrinsicMapTaskExecutor.withSharedCounterSet(operations, counterSet, stateTracker)) {
Assert.assertEquals(operations.get(0), executor.getReadOperation());
}
}
use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class IntrinsicMapTaskExecutorTest method testGetMetricContainers.
@Test
@SuppressWarnings("unchecked")
public /**
* This test makes sure that any metrics reported within an operation are part of the metric
* containers returned by {@link getMetricContainers}.
*/
void testGetMetricContainers() throws Exception {
ExecutionStateTracker stateTracker = new DataflowExecutionStateTracker(ExecutionStateSampler.newForTest(), new TestDataflowExecutionState(NameContext.forStage("testStage"), "other", null, /* requestingStepName */
null, /* sideInputIndex */
null, /* metricsContainer */
NoopProfileScope.NOOP), new CounterSet(), PipelineOptionsFactory.create(), "test-work-item-id");
final String o1 = "o1";
TestOperationContext context1 = createContext(o1, stateTracker);
final String o2 = "o2";
TestOperationContext context2 = createContext(o2, stateTracker);
final String o3 = "o3";
TestOperationContext context3 = createContext(o3, stateTracker);
List<Operation> operations = Arrays.asList(new Operation(new OutputReceiver[] {}, context1) {
@Override
public void start() throws Exception {
super.start();
try (Closeable scope = context.enterStart()) {
Metrics.counter("TestMetric", "MetricCounter").inc(1L);
}
}
}, new Operation(new OutputReceiver[] {}, context2) {
@Override
public void start() throws Exception {
super.start();
try (Closeable scope = context.enterStart()) {
Metrics.counter("TestMetric", "MetricCounter").inc(2L);
}
}
}, new Operation(new OutputReceiver[] {}, context3) {
@Override
public void start() throws Exception {
super.start();
try (Closeable scope = context.enterStart()) {
Metrics.counter("TestMetric", "MetricCounter").inc(3L);
}
}
});
try (IntrinsicMapTaskExecutor executor = IntrinsicMapTaskExecutor.withSharedCounterSet(operations, counterSet, stateTracker)) {
// Call execute so that we run all the counters
executor.execute();
assertThat(context1.metricsContainer().getUpdates().counterUpdates(), contains(metricUpdate("TestMetric", "MetricCounter", o1, 1L)));
assertThat(context2.metricsContainer().getUpdates().counterUpdates(), contains(metricUpdate("TestMetric", "MetricCounter", o2, 2L)));
assertThat(context3.metricsContainer().getUpdates().counterUpdates(), contains(metricUpdate("TestMetric", "MetricCounter", o3, 3L)));
}
}
use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class IntrinsicMapTaskExecutorTest method testExceptionInAbortSuppressed.
@Test
public void testExceptionInAbortSuppressed() throws Exception {
Operation o1 = Mockito.mock(Operation.class);
Operation o2 = Mockito.mock(Operation.class);
Operation o3 = Mockito.mock(Operation.class);
Operation o4 = Mockito.mock(Operation.class);
Mockito.doThrow(new Exception("in finish")).when(o2).finish();
Mockito.doThrow(new Exception("suppressed in abort")).when(o3).abort();
ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
try (IntrinsicMapTaskExecutor executor = IntrinsicMapTaskExecutor.withSharedCounterSet(Arrays.<Operation>asList(o1, o2, o3, o4), counterSet, stateTracker)) {
executor.execute();
fail("Should have thrown");
} catch (Exception e) {
InOrder inOrder = Mockito.inOrder(o1, o2, o3, o4);
inOrder.verify(o4).start();
inOrder.verify(o3).start();
inOrder.verify(o2).start();
inOrder.verify(o1).start();
inOrder.verify(o1).finish();
// this fails
inOrder.verify(o2).finish();
// Order of abort doesn't matter
Mockito.verify(o1).abort();
Mockito.verify(o2).abort();
// will throw an exception, but we shouldn't fail
Mockito.verify(o3).abort();
Mockito.verify(o4).abort();
Mockito.verifyNoMoreInteractions(o1, o2, o3, o4);
// Make sure the failure while aborting shows up as a suppressed error
assertThat(e.getMessage(), equalTo("in finish"));
assertThat(e.getSuppressed(), arrayWithSize(1));
assertThat(e.getSuppressed()[0].getMessage(), equalTo("suppressed in abort"));
}
}
use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class DataflowExecutionStateTrackerTest method testTakesSampleOnDeactivate.
/**
* {@link DataflowExecutionStateTrackerTest} should take one last sample when a tracker is
* deactivated.
*/
@Test
public void testTakesSampleOnDeactivate() throws IOException {
enableTimePerElementExperiment();
ExecutionStateTracker tracker = createTracker();
try (Closeable c1 = tracker.activate(new Thread())) {
try (Closeable c2 = tracker.enterState(step1Process)) {
sampler.doSampling(100);
assertThat(step1Process.getTotalMillis(), equalTo(100L));
}
}
sampler.doSampling(100);
assertThat(step1Process.getTotalMillis(), equalTo(100L));
}
Aggregations