Search in sources :

Example 6 with Dataflow

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();
}
Also used : DataflowPipelineOptions(org.apache.beam.runners.dataflow.options.DataflowPipelineOptions) Description(org.hamcrest.Description) Job(com.google.api.services.dataflow.model.Job) DataflowRunner.getContainerImageForJob(org.apache.beam.runners.dataflow.DataflowRunner.getContainerImageForJob) Dataflow(com.google.api.services.dataflow.Dataflow) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with Dataflow

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());
    }
}
Also used : DataflowPipelineOptions(org.apache.beam.runners.dataflow.options.DataflowPipelineOptions) Job(com.google.api.services.dataflow.model.Job) DataflowRunner.getContainerImageForJob(org.apache.beam.runners.dataflow.DataflowRunner.getContainerImageForJob) Dataflow(com.google.api.services.dataflow.Dataflow) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with Dataflow

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;
}
Also used : SendDebugCaptureRequest(com.google.api.services.dataflow.model.SendDebugCaptureRequest) GetDebugConfigRequest(com.google.api.services.dataflow.model.GetDebugConfigRequest) Dataflow(com.google.api.services.dataflow.Dataflow)

Aggregations

Dataflow (com.google.api.services.dataflow.Dataflow)8 Job (com.google.api.services.dataflow.model.Job)5 DataflowRunner.getContainerImageForJob (org.apache.beam.runners.dataflow.DataflowRunner.getContainerImageForJob)4 ListJobsResponse (com.google.api.services.dataflow.model.ListJobsResponse)2 DataflowPipelineOptions (org.apache.beam.runners.dataflow.options.DataflowPipelineOptions)2 DataflowWorkerHarnessOptions (org.apache.beam.runners.dataflow.options.DataflowWorkerHarnessOptions)2 Pipeline (org.apache.beam.sdk.Pipeline)2 TestCredential (org.apache.beam.sdk.extensions.gcp.auth.TestCredential)2 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)2 Before (org.junit.Before)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 GetDebugConfigRequest (com.google.api.services.dataflow.model.GetDebugConfigRequest)1 SendDebugCaptureRequest (com.google.api.services.dataflow.model.SendDebugCaptureRequest)1 Description (org.hamcrest.Description)1