use of com.google.api.services.dataflow.Dataflow in project beam by apache.
the class DataflowRunnerTest method testUpdateAlreadyUpdatedPipeline.
@Test
public void testUpdateAlreadyUpdatedPipeline() throws IOException {
DataflowPipelineOptions options = buildPipelineOptions();
options.setUpdate(true);
options.setJobName("oldJobName");
Dataflow mockDataflowClient = options.getDataflowClient();
Dataflow.Projects.Locations.Jobs.Create mockRequest = mock(Dataflow.Projects.Locations.Jobs.Create.class);
when(mockDataflowClient.projects().locations().jobs().create(eq(PROJECT_ID), eq(REGION_ID), any(Job.class))).thenReturn(mockRequest);
final Job resultJob = new Job();
resultJob.setId("newid");
// Return a different request id.
resultJob.setClientRequestId("different_request_id");
when(mockRequest.execute()).thenReturn(resultJob);
Pipeline p = buildDataflowPipeline(options);
thrown.expect(DataflowJobAlreadyUpdatedException.class);
thrown.expect(new TypeSafeMatcher<DataflowJobAlreadyUpdatedException>() {
@Override
public void describeTo(Description description) {
description.appendText("Expected job ID: " + resultJob.getId());
}
@Override
protected boolean matchesSafely(DataflowJobAlreadyUpdatedException item) {
return resultJob.getId().equals(item.getJob().getJobId());
}
});
thrown.expectMessage("The job named oldjobname with id: oldJobId has already been updated " + "into job id: newid and cannot be updated again.");
p.run();
}
use of com.google.api.services.dataflow.Dataflow in project beam by apache.
the class DataflowRunnerTest method testRunReturnDifferentRequestId.
@Test
public void testRunReturnDifferentRequestId() throws IOException {
DataflowPipelineOptions options = buildPipelineOptions();
Dataflow mockDataflowClient = options.getDataflowClient();
Dataflow.Projects.Locations.Jobs.Create mockRequest = mock(Dataflow.Projects.Locations.Jobs.Create.class);
when(mockDataflowClient.projects().locations().jobs().create(eq(PROJECT_ID), eq(REGION_ID), any(Job.class))).thenReturn(mockRequest);
Job resultJob = new Job();
resultJob.setId("newid");
// Return a different request id.
resultJob.setClientRequestId("different_request_id");
when(mockRequest.execute()).thenReturn(resultJob);
Pipeline p = buildDataflowPipeline(options);
try {
p.run();
fail("Expected DataflowJobAlreadyExistsException");
} catch (DataflowJobAlreadyExistsException expected) {
assertThat(expected.getMessage(), containsString("If you want to submit a second job, try again by setting a " + "different name using --jobName."));
assertEquals(expected.getJob().getJobId(), resultJob.getId());
}
}
use of com.google.api.services.dataflow.Dataflow in project beam by apache.
the class DebugCaptureTest method buildMockDataflow.
private Dataflow buildMockDataflow() throws Exception {
Dataflow mockDataflowClient = mock(Dataflow.class);
Dataflow.Projects mockProjects = mock(Dataflow.Projects.class);
Dataflow.Projects.Locations mockRegion = mock(Dataflow.Projects.Locations.class);
Dataflow.Projects.Locations.Jobs mockJobs = mock(Dataflow.Projects.Locations.Jobs.class);
Dataflow.Projects.Locations.Jobs.Debug mockDebug = mock(Dataflow.Projects.Locations.Jobs.Debug.class);
Dataflow.Projects.Locations.Jobs.Debug.GetConfig mockGetConfig = mock(Dataflow.Projects.Locations.Jobs.Debug.GetConfig.class);
when(mockDataflowClient.projects()).thenReturn(mockProjects);
when(mockProjects.locations()).thenReturn(mockRegion);
when(mockRegion.jobs()).thenReturn(mockJobs);
when(mockJobs.debug()).thenReturn(mockDebug);
when(mockDebug.getConfig(eq(PROJECT_ID), eq(REGION), eq(JOB_ID), isA(GetDebugConfigRequest.class))).thenReturn(mockGetConfig);
when(mockDebug.sendCapture(eq(PROJECT_ID), eq(REGION), eq(JOB_ID), isA(SendDebugCaptureRequest.class))).thenReturn(mockSendCapture);
when(mockGetConfig.execute()).thenReturn(fakeGetConfigResponse);
return mockDataflowClient;
}
Aggregations