Search in sources :

Example 26 with WorkItemStatus

use of com.google.api.services.dataflow.model.WorkItemStatus in project beam by apache.

the class WorkItemStatusClientTest method reportErrorAfterSetWorker.

/**
 * Reporting an error after setWorker has been called should also work.
 */
@Test
public void reportErrorAfterSetWorker() throws IOException {
    RuntimeException error = new RuntimeException();
    error.fillInStackTrace();
    when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
    statusClient.setWorker(worker, executionContext);
    statusClient.reportError(error);
    verify(workUnitClient).reportWorkItemStatus(statusCaptor.capture());
    WorkItemStatus workStatus = statusCaptor.getValue();
    assertThat(workStatus.getWorkItemId(), equalTo(Long.toString(WORK_ID)));
    assertThat(workStatus.getCompleted(), equalTo(true));
    assertThat(workStatus.getReportIndex(), equalTo(INITIAL_REPORT_INDEX));
    assertThat(workStatus.getErrors(), hasSize(1));
    Status status = workStatus.getErrors().get(0);
    assertThat(status.getCode(), equalTo(2));
    assertThat(status.getMessage(), containsString("WorkItemStatusClientTest"));
}
Also used : WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Status(com.google.api.services.dataflow.model.Status) WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Test(org.junit.Test)

Example 27 with WorkItemStatus

use of com.google.api.services.dataflow.model.WorkItemStatus in project beam by apache.

the class WorkItemStatusClientTest method reportOutOfMemoryErrorAfterSetWorker.

/**
 * Reporting an out of memory error should log it in addition to the regular flow.
 */
@Test
public void reportOutOfMemoryErrorAfterSetWorker() throws IOException {
    OutOfMemoryError error = new OutOfMemoryError();
    error.fillInStackTrace();
    when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
    statusClient.setWorker(worker, executionContext);
    statusClient.reportError(error);
    verify(workUnitClient).reportWorkItemStatus(statusCaptor.capture());
    WorkItemStatus workStatus = statusCaptor.getValue();
    assertThat(workStatus.getWorkItemId(), equalTo(Long.toString(WORK_ID)));
    assertThat(workStatus.getCompleted(), equalTo(true));
    assertThat(workStatus.getReportIndex(), equalTo(INITIAL_REPORT_INDEX));
    assertThat(workStatus.getErrors(), hasSize(1));
    Status status = workStatus.getErrors().get(0);
    assertThat(status.getCode(), equalTo(2));
    assertThat(status.getMessage(), containsString("WorkItemStatusClientTest"));
    assertThat(status.getMessage(), containsString("An OutOfMemoryException occurred."));
}
Also used : WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Status(com.google.api.services.dataflow.model.Status) WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Test(org.junit.Test)

Example 28 with WorkItemStatus

use of com.google.api.services.dataflow.model.WorkItemStatus in project beam by apache.

the class WorkItemStatusClientTest method populateSplitResultNull.

@Test
public void populateSplitResultNull() throws Exception {
    WorkItemStatus status = new WorkItemStatus();
    statusClient.setWorker(worker, executionContext);
    statusClient.populateSplitResult(status, null);
    assertThat(status.getDynamicSourceSplit(), nullValue());
    assertThat(status.getStopPosition(), nullValue());
}
Also used : WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Test(org.junit.Test)

Example 29 with WorkItemStatus

use of com.google.api.services.dataflow.model.WorkItemStatus in project beam by apache.

the class WorkItemStatusClientTest method populateMetricUpdatesNoStateSamplerInfo.

@Test
public void populateMetricUpdatesNoStateSamplerInfo() throws Exception {
    // When executionContext.getExecutionStateTracker() returns null, we get no metric updates.
    WorkItemStatus status = new WorkItemStatus();
    BatchModeExecutionContext executionContext = mock(BatchModeExecutionContext.class);
    when(executionContext.getExecutionStateTracker()).thenReturn(null);
    statusClient.setWorker(worker, executionContext);
    statusClient.populateMetricUpdates(status);
    assertThat(status.getMetricUpdates(), empty());
}
Also used : WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Test(org.junit.Test)

Example 30 with WorkItemStatus

use of com.google.api.services.dataflow.model.WorkItemStatus in project beam by apache.

the class WorkItemStatusClientTest method reportUpdateNullSplit.

@Test
public void reportUpdateNullSplit() throws Exception {
    when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
    statusClient.setWorker(worker, executionContext);
    statusClient.reportUpdate(null, LEASE_DURATION);
    verify(workUnitClient).reportWorkItemStatus(statusCaptor.capture());
    WorkItemStatus workStatus = statusCaptor.getValue();
    assertThat(workStatus.getCompleted(), equalTo(false));
}
Also used : WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) Test(org.junit.Test)

Aggregations

WorkItemStatus (com.google.api.services.dataflow.model.WorkItemStatus)32 Test (org.junit.Test)24 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)9 Status (com.google.api.services.dataflow.model.Status)5 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)3 ParallelInstruction (com.google.api.services.dataflow.model.ParallelInstruction)3 ReportWorkItemStatusRequest (com.google.api.services.dataflow.model.ReportWorkItemStatusRequest)3 ReportWorkItemStatusResponse (com.google.api.services.dataflow.model.ReportWorkItemStatusResponse)3 ArrayList (java.util.ArrayList)3 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)3 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)2 CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)2 MapTask (com.google.api.services.dataflow.model.MapTask)2 NameAndKind (com.google.api.services.dataflow.model.NameAndKind)2 WorkItem (com.google.api.services.dataflow.model.WorkItem)2 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 CounterSet (org.apache.beam.runners.dataflow.worker.counters.CounterSet)2 WorkItemCommitRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.WorkItemCommitRequest)2 MetricShortId (com.google.api.services.dataflow.model.MetricShortId)1