use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class MapTaskExecutorTest 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 (MapTaskExecutor executor = new MapTaskExecutor(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 MapTaskExecutorTest method testExceptionInStartAbortsAllOperations.
@Test
public void testExceptionInStartAbortsAllOperations() 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 start")).when(o2).start();
ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
try (MapTaskExecutor executor = new MapTaskExecutor(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();
// 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 MapTaskExecutorTest 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 (MapTaskExecutor executor = new MapTaskExecutor(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 MapTaskExecutorTest method testGetOutputCounters.
@Test
@SuppressWarnings("unchecked")
public void testGetOutputCounters() throws Exception {
List<Operation> operations = Arrays.asList(new Operation[] { createOperation("o1", 1), createOperation("o2", 2), createOperation("o3", 3) });
ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
try (MapTaskExecutor executor = new MapTaskExecutor(operations, counterSet, stateTracker)) {
CounterSet counterSet = executor.getOutputCounters();
CounterUpdateExtractor<?> updateExtractor = Mockito.mock(CounterUpdateExtractor.class);
counterSet.extractUpdates(false, updateExtractor);
verify(updateExtractor).longSum(eq(named("test-o1-ElementCount")), anyBoolean(), eq(1L));
verify(updateExtractor).longSum(eq(named("test-o2-ElementCount")), anyBoolean(), eq(2L));
verify(updateExtractor).longSum(eq(named("test-o3-ElementCount")), anyBoolean(), eq(3L));
verifyNoMoreInteractions(updateExtractor);
}
}
use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.
the class MapTaskExecutorTest 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 (MapTaskExecutor executor = new MapTaskExecutor(operations, counterSet, stateTracker)) {
Assert.assertEquals(operations.get(0), executor.getReadOperation());
}
}
Aggregations