Skip to content

Commit ba182e4

Browse files
committed
---
yaml --- r: 6327 b: refs/heads/tswast-patch-1 c: ab56573 h: refs/heads/master i: 6325: d285381 6323: 3ee9231 6319: de1ece8
1 parent f51e674 commit ba182e4

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 33400dac0c853e281f5dbb9bac2a6aeecd6f5f0d
60+
refs/heads/tswast-patch-1: ab56573274b17060376043d5768e179a80f5cd15
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.Assert.fail;
2626

2727
import com.google.common.collect.ImmutableList;
28+
import com.google.gcloud.RestorableState;
2829
import com.google.gcloud.storage.testing.RemoteGcsHelper;
2930

3031
import java.io.ByteArrayInputStream;
@@ -35,7 +36,6 @@
3536
import java.net.URLConnection;
3637
import java.nio.ByteBuffer;
3738
import java.util.Arrays;
38-
import java.util.Calendar;
3939
import java.util.Iterator;
4040
import java.util.List;
4141
import java.util.concurrent.ExecutionException;
@@ -399,6 +399,35 @@ public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOEx
399399
assertTrue(storage.delete(bucket, blobName));
400400
}
401401

402+
@Test
403+
public void testReadAndWriteSaveChannels() throws UnsupportedEncodingException, IOException {
404+
String blobName = "test-read-and-write-save-channels-blob";
405+
BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
406+
byte[] stringBytes;
407+
BlobWriteChannel writer = storage.writer(blob);
408+
stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
409+
writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT));
410+
RestorableState<BlobWriteChannel> writerState = writer.save();
411+
BlobWriteChannel secondWriter = writerState.restore();
412+
secondWriter.write(ByteBuffer.wrap(stringBytes));
413+
secondWriter.close();
414+
ByteBuffer readBytes;
415+
ByteBuffer readStringBytes;
416+
BlobReadChannel reader = storage.reader(blob.blobId());
417+
reader.chunkSize(BLOB_BYTE_CONTENT.length);
418+
readBytes = ByteBuffer.allocate(BLOB_BYTE_CONTENT.length);
419+
reader.read(readBytes);
420+
RestorableState<BlobReadChannel> readerState = reader.save();
421+
BlobReadChannel secondReader = readerState.restore();
422+
readStringBytes = ByteBuffer.allocate(stringBytes.length);
423+
secondReader.read(readStringBytes);
424+
reader.close();
425+
secondReader.close();
426+
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes.array());
427+
assertEquals(BLOB_STRING_CONTENT, new String(readStringBytes.array(), UTF_8));
428+
assertTrue(storage.delete(bucket, blobName));
429+
}
430+
402431
@Test
403432
public void testReadChannelFail() throws UnsupportedEncodingException, IOException {
404433
String blobName = "test-read-channel-blob-fail";

0 commit comments

Comments
 (0)