Skip to content

Commit ab56573

Browse files
committed
Add channel write and restore integration tests
1 parent 33400da commit ab56573

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

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)