Search in sources :

Example 1 with ExecutionStateTracker

use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.

the class BeamFnStatusClientTest method testActiveBundleState.

@Test
public void testActiveBundleState() {
    ProcessBundleHandler handler = mock(ProcessBundleHandler.class);
    BundleProcessorCache processorCache = mock(BundleProcessorCache.class);
    Map<String, BundleProcessor> bundleProcessorMap = new HashMap<>();
    for (int i = 0; i < 11; i++) {
        BundleProcessor processor = mock(BundleProcessor.class);
        ExecutionStateTracker executionStateTracker = mock(ExecutionStateTracker.class);
        when(processor.getStateTracker()).thenReturn(executionStateTracker);
        when(executionStateTracker.getMillisSinceLastTransition()).thenReturn(Integer.toUnsignedLong((10 - i) * 1000));
        when(executionStateTracker.getTrackedThread()).thenReturn(Thread.currentThread());
        String instruction = Integer.toString(i);
        when(processorCache.find(instruction)).thenReturn(processor);
        bundleProcessorMap.put(instruction, processor);
    }
    when(handler.getBundleProcessorCache()).thenReturn(processorCache);
    when(processorCache.getActiveBundleProcessors()).thenReturn(bundleProcessorMap);
    ManagedChannelFactory channelFactory = ManagedChannelFactory.createInProcess();
    BeamFnStatusClient client = new BeamFnStatusClient(apiServiceDescriptor, channelFactory::forDescriptor, handler.getBundleProcessorCache(), PipelineOptionsFactory.create(), Caches.noop());
    StringJoiner joiner = new StringJoiner("\n");
    joiner.add(client.getActiveProcessBundleState());
    String actualState = joiner.toString();
    List<String> expectedInstructions = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        expectedInstructions.add(String.format("Instruction %d", i));
    }
    assertThat(actualState, stringContainsInOrder(expectedInstructions));
    assertThat(actualState, not(containsString("Instruction 10")));
}
Also used : HashMap(java.util.HashMap) BundleProcessorCache(org.apache.beam.fn.harness.control.ProcessBundleHandler.BundleProcessorCache) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessBundleHandler(org.apache.beam.fn.harness.control.ProcessBundleHandler) ManagedChannelFactory(org.apache.beam.sdk.fn.channel.ManagedChannelFactory) ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) BundleProcessor(org.apache.beam.fn.harness.control.ProcessBundleHandler.BundleProcessor) StringJoiner(java.util.StringJoiner) Test(org.junit.Test)

Example 2 with ExecutionStateTracker

use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.

the class MapTaskExecutorTest method testGetProgressAndRequestSplit.

@Test
public void testGetProgressAndRequestSplit() throws Exception {
    TestOutputReceiver receiver = new TestOutputReceiver(counterSet, NameContextsForTests.nameContextForTest());
    TestReadOperation operation = new TestReadOperation(receiver, createContext("ReadOperation"));
    ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
    try (MapTaskExecutor executor = new MapTaskExecutor(Arrays.asList(new Operation[] { operation }), counterSet, stateTracker)) {
        operation.setProgress(approximateProgressAtIndex(1L));
        Assert.assertEquals(positionAtIndex(1L), positionFromProgress(executor.getWorkerProgress()));
        Assert.assertEquals(positionAtIndex(1L), positionFromSplitResult(executor.requestDynamicSplit(splitRequestAtIndex(1L))));
    }
}
Also used : ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) DataflowExecutionStateTracker(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker) Test(org.junit.Test)

Example 3 with ExecutionStateTracker

use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.

the class MapTaskExecutorTest method testNoOperation.

@Test
public void testNoOperation() throws Exception {
    // Test MapTaskExecutor without a single operation.
    ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
    try (MapTaskExecutor executor = new MapTaskExecutor(new ArrayList<Operation>(), counterSet, stateTracker)) {
        thrown.expect(IllegalStateException.class);
        thrown.expectMessage("has no operation");
        executor.getReadOperation();
    }
}
Also used : ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) DataflowExecutionStateTracker(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker) Test(org.junit.Test)

Example 4 with ExecutionStateTracker

use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.

the class MapTaskExecutorTest method testExecuteMapTaskExecutor.

@Test
public void testExecuteMapTaskExecutor() throws Exception {
    Operation o1 = Mockito.mock(Operation.class);
    Operation o2 = Mockito.mock(Operation.class);
    Operation o3 = Mockito.mock(Operation.class);
    List<Operation> operations = Arrays.asList(new Operation[] { o1, o2, o3 });
    ExecutionStateTracker stateTracker = Mockito.mock(ExecutionStateTracker.class);
    try (MapTaskExecutor executor = new MapTaskExecutor(operations, counterSet, stateTracker)) {
        executor.execute();
    }
    InOrder inOrder = Mockito.inOrder(stateTracker, o1, o2, o3);
    inOrder.verify(o3).start();
    inOrder.verify(o2).start();
    inOrder.verify(o1).start();
    inOrder.verify(o1).finish();
    inOrder.verify(o2).finish();
    inOrder.verify(o3).finish();
}
Also used : InOrder(org.mockito.InOrder) ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) DataflowExecutionStateTracker(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker) Test(org.junit.Test)

Example 5 with ExecutionStateTracker

use of org.apache.beam.runners.core.metrics.ExecutionStateTracker in project beam by apache.

the class MapTaskExecutorTest method testAbort.

@Test
public void testAbort() throws Exception {
    // Operation must be an instance of ReadOperation or ReceivingOperation per preconditions
    // in MapTaskExecutor.
    ReadOperation o1 = Mockito.mock(ReadOperation.class);
    ReadOperation o2 = Mockito.mock(ReadOperation.class);
    ExecutionStateTracker stateTracker = ExecutionStateTracker.newForTest();
    MapTaskExecutor executor = new MapTaskExecutor(Arrays.<Operation>asList(o1, o2), counterSet, stateTracker);
    Mockito.doAnswer(invocation -> {
        executor.abort();
        return null;
    }).when(o1).finish();
    executor.execute();
    Mockito.verify(o1, atLeastOnce()).abortReadLoop();
    Mockito.verify(o2, atLeastOnce()).abortReadLoop();
}
Also used : ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) DataflowExecutionStateTracker(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker) Test(org.junit.Test)

Aggregations

ExecutionStateTracker (org.apache.beam.runners.core.metrics.ExecutionStateTracker)39 Test (org.junit.Test)34 DataflowExecutionStateTracker (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowExecutionStateTracker)24 ReadOperation (org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation)11 Operation (org.apache.beam.runners.dataflow.worker.util.common.worker.Operation)10 ParDoOperation (org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoOperation)10 ExpectedException (org.junit.rules.ExpectedException)8 InOrder (org.mockito.InOrder)8 Closeable (java.io.Closeable)6 CounterSet (org.apache.beam.runners.dataflow.worker.counters.CounterSet)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)4 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)3 BundleProcessor (org.apache.beam.fn.harness.control.ProcessBundleHandler.BundleProcessor)3 PTransformFunctionRegistry (org.apache.beam.fn.harness.data.PTransformFunctionRegistry)3 ExecutionStateSampler (org.apache.beam.runners.core.metrics.ExecutionStateSampler)3 MetricsContainerStepMap (org.apache.beam.runners.core.metrics.MetricsContainerStepMap)3 ThrowingRunnable (org.apache.beam.sdk.function.ThrowingRunnable)3 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)3