File tree Expand file tree Collapse file tree
sdks/java/extensions/google-cloud-platform-core/src
main/java/org/apache/beam/sdk/extensions/gcp/util
test/java/org/apache/beam/sdk/extensions/gcp/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -261,12 +261,18 @@ public boolean shouldRetry(IOException e) {
261261 this .credentials = credentials ;
262262 this .maxBytesRewrittenPerCall = null ;
263263 this .numRewriteTokensUsed = null ;
264- googleCloudStorageOptions =
264+ GoogleCloudStorageOptions . Builder optionsBuilder =
265265 GoogleCloudStorageOptions .builder ()
266266 .setAppName ("Beam" )
267267 .setReadChannelOptions (gcsReadOptions )
268- .setGrpcEnabled (shouldUseGrpc )
269- .build ();
268+ .setGrpcEnabled (shouldUseGrpc );
269+ if (storageClient .getRootUrl () != null ) {
270+ optionsBuilder .setStorageRootUrl (storageClient .getRootUrl ());
271+ }
272+ if (storageClient .getServicePath () != null ) {
273+ optionsBuilder .setStorageServicePath (storageClient .getServicePath ());
274+ }
275+ googleCloudStorageOptions = optionsBuilder .build ();
270276 try {
271277 googleCloudStorage =
272278 createGoogleCloudStorage (googleCloudStorageOptions , storageClient , credentials );
@@ -495,6 +501,11 @@ private Long toFileSize(StorageObjectOrIOException storageObjectOrIOException)
495501 }
496502 }
497503
504+ @ VisibleForTesting
505+ GoogleCloudStorage getGoogleCloudStorage () {
506+ return googleCloudStorage ;
507+ }
508+
498509 @ VisibleForTesting
499510 void setCloudStorageImpl (GoogleCloudStorage g ) {
500511 googleCloudStorage = g ;
Original file line number Diff line number Diff line change 6363import com .google .auth .Credentials ;
6464import com .google .cloud .hadoop .gcsio .CreateObjectOptions ;
6565import com .google .cloud .hadoop .gcsio .GoogleCloudStorage ;
66+ import com .google .cloud .hadoop .gcsio .GoogleCloudStorageImpl ;
6667import com .google .cloud .hadoop .gcsio .GoogleCloudStorageOptions ;
6768import com .google .cloud .hadoop .gcsio .GoogleCloudStorageReadOptions ;
6869import com .google .cloud .hadoop .gcsio .StorageResourceId ;
@@ -1866,6 +1867,18 @@ public void testReadMetricsAreNotCollectedWhenNotEnabledOpenWithOptions() throws
18661867 testReadMetrics (false , GoogleCloudStorageReadOptions .DEFAULT );
18671868 }
18681869
1870+ @ Test
1871+ public void testGcsEndpoint () throws IOException {
1872+ GcsOptions pipelineOptions = PipelineOptionsFactory .as (GcsOptions .class );
1873+ pipelineOptions .setGcsEndpoint ("http://localhost:4443/storage/v1/" );
1874+
1875+ GcsUtil gcsUtil = pipelineOptions .getGcsUtil ();
1876+ GoogleCloudStorageImpl gcsImpl =
1877+ (GoogleCloudStorageImpl ) gcsUtil .delegate .getGoogleCloudStorage ();
1878+ assertEquals ("http://localhost:4443/" , gcsImpl .getOptions ().getStorageRootUrl ());
1879+ assertEquals ("storage/v1/" , gcsImpl .getOptions ().getStorageServicePath ());
1880+ }
1881+
18691882 /** A helper to wrap a {@link GenericJson} object in a content stream. */
18701883 private static InputStream toStream (String content ) throws IOException {
18711884 return new ByteArrayInputStream (content .getBytes (StandardCharsets .UTF_8 ));
You can’t perform that action at this time.
0 commit comments