3434import com .google .cloud .storage .BlobId ;
3535import com .google .cloud .storage .BlobInfo ;
3636import com .google .cloud .storage .BucketInfo ;
37- import com .google .cloud .storage .DataGeneration ;
37+ import com .google .cloud .storage .DataGenerator ;
3838import com .google .cloud .storage .HttpStorageOptions ;
3939import com .google .cloud .storage .PackagePrivateMethodWorkarounds ;
4040import com .google .cloud .storage .Storage ;
5858import java .io .IOException ;
5959import java .nio .ByteBuffer ;
6060import java .util .Optional ;
61- import java .util .Random ;
6261import java .util .concurrent .atomic .AtomicBoolean ;
6362import java .util .logging .Logger ;
64- import org .junit .Rule ;
6563import org .junit .Test ;
6664import org .junit .runner .RunWith ;
6765import org .threeten .bp .Clock ;
@@ -89,8 +87,6 @@ public final class ITBlobWriteChannelTest {
8987
9088 @ Inject public Generator generator ;
9189
92- @ Rule public final DataGeneration dataGeneration = new DataGeneration (new Random (1234567890 ));
93-
9490 /**
9591 * Test for unexpected EOF at the beginning of trying to read the json response.
9692 *
@@ -146,9 +142,9 @@ public void testWriteChannelExistingBlob() throws IOException {
146142 DateTimeFormatter formatter =
147143 DateTimeFormatter .ISO_LOCAL_DATE_TIME .withZone (ZoneId .from (ZoneOffset .UTC ));
148144 String nowString = formatter .format (now );
149- BucketInfo bucketInfo = BucketInfo .of (dataGeneration . getBucketName ());
145+ BucketInfo bucketInfo = BucketInfo .of (generator . randomBucketName ());
150146 String blobPath = String .format ("%s/%s/blob" , generator .randomObjectName (), nowString );
151- BlobId blobId = BlobId .of (dataGeneration . getBucketName (), blobPath );
147+ BlobId blobId = BlobId .of (bucketInfo . getName (), blobPath );
152148 BlobInfo blobInfo = BlobInfo .newBuilder (blobId ).build ();
153149 storage .create (bucketInfo );
154150 storage .create (blobInfo );
@@ -164,7 +160,7 @@ public void testWriteChannelExistingBlob() throws IOException {
164160 private void doJsonUnexpectedEOFTest (int contentSize , int cappedByteCount ) throws IOException {
165161 String blobPath = String .format ("%s/%s/blob" , generator .randomObjectName (), NOW_STRING );
166162
167- BucketInfo bucketInfo = BucketInfo .of (dataGeneration . getBucketName ());
163+ BucketInfo bucketInfo = BucketInfo .of (generator . randomBucketName ());
168164 BlobInfo blobInfoGen0 = BlobInfo .newBuilder (bucketInfo , blobPath , 0L ).build ();
169165
170166 RetryTestResource retryTestResource =
@@ -225,7 +221,7 @@ private void doJsonUnexpectedEOFTest(int contentSize, int cappedByteCount) throw
225221
226222 testStorage .create (bucketInfo );
227223
228- ByteBuffer content = dataGeneration . randByteBuffer (contentSize );
224+ ByteBuffer content = DataGenerator . base64Characters (). genByteBuffer (contentSize );
229225 // create a duplicate to preserve the initial offset and limit for assertion later
230226 ByteBuffer expected = content .duplicate ();
231227
@@ -260,13 +256,13 @@ private void blobWriteChannel_handlesRecoveryOnLastChunkWhenGenerationIsPresent(
260256 DateTimeFormatter formatter =
261257 DateTimeFormatter .ISO_LOCAL_DATE_TIME .withZone (ZoneId .from (ZoneOffset .UTC ));
262258 String nowString = formatter .format (now );
263- BucketInfo bucketInfo = BucketInfo .of (dataGeneration . getBucketName ());
259+ BucketInfo bucketInfo = BucketInfo .of (generator . randomBucketName ());
264260 String blobPath = String .format ("%s/%s/blob" , generator .randomObjectName (), nowString );
265- BlobId blobId = BlobId .of (dataGeneration . getBucketName (), blobPath );
261+ BlobId blobId = BlobId .of (bucketInfo . getName (), blobPath );
266262 BlobInfo blobInfo = BlobInfo .newBuilder (blobId ).build ();
267263
268- ByteBuffer contentGen1 = dataGeneration . randByteBuffer (contentSize );
269- ByteBuffer contentGen2 = dataGeneration . randByteBuffer (contentSize );
264+ ByteBuffer contentGen1 = DataGenerator . base64Characters (). genByteBuffer (contentSize );
265+ ByteBuffer contentGen2 = DataGenerator . base64Characters (). genByteBuffer (contentSize );
270266 ByteBuffer contentGen2Expected = contentGen2 .duplicate ();
271267 HttpStorageOptions baseStorageOptions =
272268 StorageOptions .http ()
@@ -302,7 +298,6 @@ private void blobWriteChannel_handlesRecoveryOnLastChunkWhenGenerationIsPresent(
302298 * get on an object can result in a 404 because the object that is created while
303299 * the BlobWriteChannel is executing will be a new generation.
304300 */
305- @ SuppressWarnings ("UnstableApiUsage" )
306301 @ Override
307302 public StorageRpc create (final StorageOptions options ) {
308303 return Reflection .newProxy (
0 commit comments