|
25 | 25 | import static org.junit.Assert.fail; |
26 | 26 |
|
27 | 27 | import com.google.common.collect.ImmutableList; |
| 28 | +import com.google.gcloud.RestorableState; |
28 | 29 | import com.google.gcloud.storage.testing.RemoteGcsHelper; |
29 | 30 |
|
30 | 31 | import java.io.ByteArrayInputStream; |
|
35 | 36 | import java.net.URLConnection; |
36 | 37 | import java.nio.ByteBuffer; |
37 | 38 | import java.util.Arrays; |
38 | | -import java.util.Calendar; |
39 | 39 | import java.util.Iterator; |
40 | 40 | import java.util.List; |
41 | 41 | import java.util.concurrent.ExecutionException; |
@@ -399,6 +399,35 @@ public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOEx |
399 | 399 | assertTrue(storage.delete(bucket, blobName)); |
400 | 400 | } |
401 | 401 |
|
| 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 | + |
402 | 431 | @Test |
403 | 432 | public void testReadChannelFail() throws UnsupportedEncodingException, IOException { |
404 | 433 | String blobName = "test-read-channel-blob-fail"; |
|
0 commit comments