/** * Creates a {@link GoogleApiTracer} that sets the trace destination on all calls that match the * given client type. */ public GoogleApiTracer addTraceFor(AbstractGoogleClient client, String traceDestination) { put(client.getClass().getCanonicalName(), traceDestination); return this; }
@Override public String create(PipelineOptions options) { return options.as(GcpOptions.class).getProject(); } }
private static String runGetProjectTest(File path, Map<String, String> environment) throws Exception { makePropertiesFileWithProject(path, "test-project"); DefaultProjectFactory projectFactory = spy(new DefaultProjectFactory()); when(projectFactory.getEnvironment()).thenReturn(environment); return projectFactory.create(PipelineOptionsFactory.create()); } }
@Override protected ReadableByteChannel open(GcsResourceId resourceId) throws IOException { return options.getGcsUtil().open(resourceId.getGcsPath()); }
@Test public void testCreationWithExecutorServiceProvided() { GcsOptions pipelineOptions = gcsOptionsWithTestCredential(); pipelineOptions.setExecutorService(Executors.newCachedThreadPool()); assertSame(pipelineOptions.getExecutorService(), pipelineOptions.getGcsUtil().executorService); }
@Test public void testCreationWithGcsUtilProvided() { GcsOptions pipelineOptions = PipelineOptionsFactory.as(GcsOptions.class); GcsUtil gcsUtil = Mockito.mock(GcsUtil.class); pipelineOptions.setGcsUtil(gcsUtil); assertSame(gcsUtil, pipelineOptions.getGcsUtil()); }
@Test public void testDefaultGcpTempLocation() throws Exception { GcpOptions options = PipelineOptionsFactory.as(GcpOptions.class); String tempLocation = "gs://bucket"; options.setTempLocation(tempLocation); options.as(GcsOptions.class).setPathValidatorClass(NoopPathValidator.class); assertEquals(tempLocation, options.getGcpTempLocation()); }
@Test public void regionFromZone() throws Exception { assertEquals("us-central1", GcpTempLocationFactory.getRegionFromZone("us-central1-a")); assertEquals("asia-east", GcpTempLocationFactory.getRegionFromZone("asia-east-a")); } }
@Test public void testDefaultGcpTempLocationInvalid() throws Exception { GcpOptions options = PipelineOptionsFactory.as(GcpOptions.class); options.setTempLocation("file://"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage( "Error constructing default value for gcpTempLocation: tempLocation is not" + " a valid GCS path"); options.getGcpTempLocation(); }
@Test public void testCreationWithDefaultOptions() { GcsOptions pipelineOptions = gcsOptionsWithTestCredential(); assertNotNull(pipelineOptions.getGcpCredential()); }
/** * Returns the project number or throws an exception if the project does not exist or has other * access exceptions. */ private static long getProjectNumber(String projectId, CloudResourceManager crmClient) throws IOException { return getProjectNumber( projectId, crmClient, BackOffAdapter.toGcpBackOff(BACKOFF_FACTORY.backoff()), Sleeper.DEFAULT); }
private static GcsOptions gcsOptionsWithTestCredential() { GcsOptions pipelineOptions = PipelineOptionsFactory.as(GcsOptions.class); pipelineOptions.setGcpCredential(new TestCredential()); return pipelineOptions; }
@Override public PathValidator create(PipelineOptions options) { GcsOptions gcsOptions = options.as(GcsOptions.class); return InstanceBuilder.ofType(PathValidator.class) .fromClass(gcsOptions.getPathValidatorClass()) .fromFactoryMethod("fromOptions") .withArg(PipelineOptions.class, options) .build(); } }
@Override protected void delete(Collection<GcsResourceId> resourceIds) throws IOException { options.getGcsUtil().remove(toFilenames(resourceIds)); }
@Override public String create(PipelineOptions options) { return "projects/" + options.as(GcpOptions.class).getProject() + "/topics/" + options.getJobName(); } }
/** * Creates a {@link GoogleApiTracer} that sets the trace {@code traceDestination} on all calls * that match for the given request type. */ public GoogleApiTracer addTraceFor( AbstractGoogleClientRequest<?> request, String traceDestination) { put(request.getClass().getCanonicalName(), traceDestination); return this; }
@Override protected void copy(List<GcsResourceId> srcResourceIds, List<GcsResourceId> destResourceIds) throws IOException { options.getGcsUtil().copy(toFilenames(srcResourceIds), toFilenames(destResourceIds)); }
@Override public String create(PipelineOptions options) { return "projects/" + options.as(GcpOptions.class).getProject() + "/subscriptions/" + options.getJobName(); } }
@Test public void testUploadBufferSizeDefault() { GcsOptions pipelineOptions = gcsOptionsWithTestCredential(); GcsUtil util = pipelineOptions.getGcsUtil(); assertNull(util.getUploadBufferSizeBytes()); }
@Test public void testInvalidCopyBatches() throws IOException { GcsUtil gcsUtil = gcsOptionsWithTestCredential().getGcsUtil(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Number of source files 3"); gcsUtil.makeCopyBatches(makeStrings("s", 3), makeStrings("d", 1)); }