Search in sources :

Example 6 with TestCredential

use of org.apache.beam.sdk.extensions.gcp.auth.TestCredential in project beam by apache.

the class BigtableIOTest method testUsePipelineOptionsCredentialsIfNotSpecifiedInBigtableOptions.

/** Tests that credentials are used from PipelineOptions if not supplied by BigtableOptions. */
@Test
public void testUsePipelineOptionsCredentialsIfNotSpecifiedInBigtableOptions() throws Exception {
    BigtableOptions options = BIGTABLE_OPTIONS.toBuilder().setCredentialOptions(CredentialOptions.defaultCredentials()).build();
    GcpOptions pipelineOptions = PipelineOptionsFactory.as(GcpOptions.class);
    pipelineOptions.setGcpCredential(new TestCredential());
    BigtableService readService = BigtableIO.read().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    BigtableService writeService = BigtableIO.write().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    assertEquals(CredentialType.SuppliedCredentials, readService.getBigtableOptions().getCredentialOptions().getCredentialType());
    assertEquals(CredentialType.SuppliedCredentials, writeService.getBigtableOptions().getCredentialOptions().getCredentialType());
}
Also used : GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) Test(org.junit.Test)

Example 7 with TestCredential

use of org.apache.beam.sdk.extensions.gcp.auth.TestCredential in project beam by apache.

the class BigtableIOTest method testDontUsePipelineOptionsCredentialsIfSpecifiedInBigtableOptions.

/** Tests that credentials are not used from PipelineOptions if supplied by BigtableOptions. */
@Test
public void testDontUsePipelineOptionsCredentialsIfSpecifiedInBigtableOptions() throws Exception {
    BigtableOptions options = BIGTABLE_OPTIONS.toBuilder().setCredentialOptions(CredentialOptions.nullCredential()).build();
    GcpOptions pipelineOptions = PipelineOptionsFactory.as(GcpOptions.class);
    pipelineOptions.setGcpCredential(new TestCredential());
    BigtableService readService = BigtableIO.read().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    BigtableService writeService = BigtableIO.write().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    assertEquals(CredentialType.None, readService.getBigtableOptions().getCredentialOptions().getCredentialType());
    assertEquals(CredentialType.None, writeService.getBigtableOptions().getCredentialOptions().getCredentialType());
}
Also used : GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) Test(org.junit.Test)

Example 8 with TestCredential

use of org.apache.beam.sdk.extensions.gcp.auth.TestCredential in project beam by apache.

the class MonitoringUtilTest method testOverridesEndpointWithStagedDataflowEndpoint.

@Test
public void testOverridesEndpointWithStagedDataflowEndpoint() {
    DataflowPipelineOptions options = PipelineOptionsFactory.create().as(DataflowPipelineOptions.class);
    options.setProject(PROJECT_ID);
    options.setGcpCredential(new TestCredential());
    String stagingDataflowEndpoint = "v0neverExisted";
    options.setDataflowEndpoint(stagingDataflowEndpoint);
    String cancelCommand = MonitoringUtil.getGcloudCancelCommand(options, JOB_ID);
    assertEquals("CLOUDSDK_API_ENDPOINT_OVERRIDES_DATAFLOW=https://dataflow.googleapis.com/v0neverExisted/ " + "gcloud beta dataflow jobs --project=someProject cancel 1234", cancelCommand);
}
Also used : TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) DataflowPipelineOptions(org.apache.beam.runners.dataflow.options.DataflowPipelineOptions) Test(org.junit.Test)

Example 9 with TestCredential

use of org.apache.beam.sdk.extensions.gcp.auth.TestCredential in project beam by apache.

the class GcsPathValidatorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(mockGcsUtil.bucketAccessible(any(GcsPath.class))).thenReturn(true);
    GcsOptions options = PipelineOptionsFactory.as(GcsOptions.class);
    options.setGcpCredential(new TestCredential());
    options.setGcsUtil(mockGcsUtil);
    validator = GcsPathValidator.fromOptions(options);
}
Also used : TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) GcsPath(org.apache.beam.sdk.util.gcsfs.GcsPath) GcsOptions(org.apache.beam.sdk.extensions.gcp.options.GcsOptions) Before(org.junit.Before)

Example 10 with TestCredential

use of org.apache.beam.sdk.extensions.gcp.auth.TestCredential in project beam by apache.

the class GcsUtilTest method gcsOptionsWithTestCredential.

private static GcsOptions gcsOptionsWithTestCredential() {
    GcsOptions pipelineOptions = PipelineOptionsFactory.as(GcsOptions.class);
    pipelineOptions.setGcpCredential(new TestCredential());
    return pipelineOptions;
}
Also used : TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) GcsOptions(org.apache.beam.sdk.extensions.gcp.options.GcsOptions)

Aggregations

TestCredential (org.apache.beam.sdk.extensions.gcp.auth.TestCredential)28 Test (org.junit.Test)19 DataflowPipelineOptions (org.apache.beam.runners.dataflow.options.DataflowPipelineOptions)14 Before (org.junit.Before)5 GcsPath (org.apache.beam.sdk.util.gcsfs.GcsPath)4 Pipeline (org.apache.beam.sdk.Pipeline)3 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 BigtableOptions (com.google.cloud.bigtable.config.BigtableOptions)2 ImmutableList (com.google.common.collect.ImmutableList)2 File (java.io.File)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 GcpOptions (org.apache.beam.sdk.extensions.gcp.options.GcpOptions)2 GcsOptions (org.apache.beam.sdk.extensions.gcp.options.GcsOptions)2 GoogleApiTracer (org.apache.beam.sdk.extensions.gcp.options.GoogleApiDebugOptions.GoogleApiTracer)2 GcsUtil (org.apache.beam.sdk.util.GcsUtil)2 TupleTagList (org.apache.beam.sdk.values.TupleTagList)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.anyString (org.mockito.Matchers.anyString)2