22
22
import com .google .cloud .storage .BucketInfo ;
23
23
import com .google .cloud .storage .DataGenerator ;
24
24
import com .google .cloud .storage .Storage ;
25
+ import com .google .cloud .storage .Storage .BlobGetOption ;
25
26
import com .google .cloud .storage .Storage .BlobTargetOption ;
26
27
import com .google .cloud .storage .Storage .ComposeRequest ;
27
28
import com .google .cloud .storage .it .ChecksummedTestContent ;
@@ -34,6 +35,9 @@ public final class ObjectsFixture implements ManagedLifecycle {
34
35
private final Storage s ;
35
36
private final BucketInfo bucket ;
36
37
38
+ private final BlobTargetOption [] blobTargetOptions ;
39
+ private final BlobGetOption [] blobGetOptions ;
40
+
37
41
private BlobInfo info1 ;
38
42
private BlobInfo info2 ;
39
43
private BlobInfo info3 ;
@@ -43,6 +47,21 @@ public final class ObjectsFixture implements ManagedLifecycle {
43
47
ObjectsFixture (Storage s , BucketInfo bucket ) {
44
48
this .s = s ;
45
49
this .bucket = bucket ;
50
+ boolean isRequesterPays = Boolean .TRUE .equals (bucket .requesterPays ());
51
+ String projectId = s .getOptions ().getProjectId ();
52
+ if (isRequesterPays ) {
53
+ blobTargetOptions =
54
+ new BlobTargetOption [] {
55
+ BlobTargetOption .doesNotExist (), BlobTargetOption .userProject (projectId )
56
+ };
57
+ } else {
58
+ blobTargetOptions = new BlobTargetOption [] {BlobTargetOption .doesNotExist ()};
59
+ }
60
+ if (isRequesterPays ) {
61
+ blobGetOptions = new BlobGetOption [] {BlobGetOption .userProject (projectId )};
62
+ } else {
63
+ blobGetOptions = new BlobGetOption [] {};
64
+ }
46
65
}
47
66
48
67
@ Override
@@ -83,41 +102,38 @@ public void start() {
83
102
BlobInfo info2 = BlobInfo .newBuilder (blobId2 ).setMetadata (ImmutableMap .of ("pow" , "2" )).build ();
84
103
BlobInfo info3 = BlobInfo .newBuilder (blobId3 ).setMetadata (ImmutableMap .of ("pow" , "3" )).build ();
85
104
BlobInfo info4 = BlobInfo .newBuilder (blobId4 ).setMetadata (ImmutableMap .of ("pow" , "4" )).build ();
86
- s .create (info1 , "A" .getBytes (StandardCharsets .UTF_8 ), BlobTargetOption . doesNotExist () );
105
+ s .create (info1 , "A" .getBytes (StandardCharsets .UTF_8 ), blobTargetOptions );
87
106
88
107
ComposeRequest c2 =
89
108
ComposeRequest .newBuilder ()
90
109
.addSource (blobId1 .getName (), blobId1 .getName ())
91
110
.setTarget (info2 )
92
- .setTargetOptions (BlobTargetOption . doesNotExist () )
111
+ .setTargetOptions (blobTargetOptions )
93
112
.build ();
94
113
ComposeRequest c3 =
95
114
ComposeRequest .newBuilder ()
96
115
.addSource (blobId2 .getName (), blobId2 .getName ())
97
116
.setTarget (info3 )
98
- .setTargetOptions (BlobTargetOption . doesNotExist () )
117
+ .setTargetOptions (blobTargetOptions )
99
118
.build ();
100
119
ComposeRequest c4 =
101
120
ComposeRequest .newBuilder ()
102
121
.addSource (blobId3 .getName (), blobId3 .getName ())
103
122
.setTarget (info4 )
104
- .setTargetOptions (BlobTargetOption . doesNotExist () )
123
+ .setTargetOptions (blobTargetOptions )
105
124
.build ();
106
125
s .compose (c2 );
107
126
s .compose (c3 );
108
127
s .compose (c4 );
109
128
110
- this .info1 = s .get (blobId1 ).asBlobInfo ();
111
- this .info2 = s .get (blobId2 ).asBlobInfo ();
112
- this .info3 = s .get (blobId3 ).asBlobInfo ();
113
- this .info4 = s .get (blobId4 ).asBlobInfo ();
129
+ this .info1 = s .get (blobId1 , blobGetOptions ).asBlobInfo ();
130
+ this .info2 = s .get (blobId2 , blobGetOptions ).asBlobInfo ();
131
+ this .info3 = s .get (blobId3 , blobGetOptions ).asBlobInfo ();
132
+ this .info4 = s .get (blobId4 , blobGetOptions ).asBlobInfo ();
114
133
115
134
byte [] bytes = DataGenerator .base64Characters ().genBytes (512 * 1024 );
116
135
Blob obj512KiB =
117
- s .create (
118
- BlobInfo .newBuilder (bucket , "obj512KiB" ).build (),
119
- bytes ,
120
- BlobTargetOption .doesNotExist ());
136
+ s .create (BlobInfo .newBuilder (bucket , "obj512KiB" ).build (), bytes , blobTargetOptions );
121
137
this .obj512KiB = new ObjectAndContent (obj512KiB .asBlobInfo (), ChecksummedTestContent .of (bytes ));
122
138
}
123
139
0 commit comments