Skip to content

Commit f4e67a7

Browse files
committed
---
yaml --- r: 6331 b: refs/heads/tswast-patch-1 c: 638bd92 h: refs/heads/master i: 6329: 145048b 6327: ba182e4
1 parent d8fce36 commit f4e67a7

3 files changed

Lines changed: 31 additions & 3 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: 2060526a1469fbbf6a492594ac3dc66d06aaa51c
60+
refs/heads/tswast-patch-1: 638bd92113a30b4e1b330f941db1b02fda41039f
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ static Builder builder(StorageOptions options, BlobInfo blobInfo, String uploadI
227227
@Override
228228
public BlobWriteChannel restore() {
229229
BlobWriteChannelImpl channel = new BlobWriteChannelImpl(serviceOptions, blobInfo, uploadId);
230+
if (buffer != null) {
231+
channel.buffer = buffer.clone();
232+
channel.limit = buffer.length;
233+
}
230234
channel.position = position;
231-
channel.buffer = buffer.clone();
232-
channel.limit = buffer.length;
233235
channel.isOpen = isOpen;
234236
channel.chunkSize = chunkSize;
235237
return channel;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,32 @@ public void testSaveAndRestore() throws IOException {
220220
assertEquals(new Long(DEFAULT_CHUNK_SIZE), capturedPosition.getValues().get(1));
221221
}
222222

223+
@Test
224+
public void testSaveAndRestoreClosed() throws IOException {
225+
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock).times(2);
226+
EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
227+
EasyMock.replay(optionsMock);
228+
EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
229+
Capture<byte[]> capturedBuffer = Capture.newInstance();
230+
storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
231+
EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(0), EasyMock.eq(true));
232+
EasyMock.expectLastCall();
233+
EasyMock.replay(storageRpcMock);
234+
writer = new BlobWriteChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
235+
writer.close();
236+
RestorableState<BlobWriteChannel> writerState = writer.save();
237+
RestorableState<BlobWriteChannel> expectedWriterState =
238+
BlobWriteChannelImpl.StateImpl.builder(optionsMock, BLOB_INFO, UPLOAD_ID)
239+
.buffer(null)
240+
.chunkSize(DEFAULT_CHUNK_SIZE)
241+
.isOpen(false)
242+
.position(0)
243+
.build();
244+
BlobWriteChannel restoredWriter = writerState.restore();
245+
assertArrayEquals(new byte[0], capturedBuffer.getValue());
246+
assertEquals(expectedWriterState, restoredWriter.save());
247+
}
248+
223249
@Test
224250
public void testStateEquals() {
225251
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock).times(2);

0 commit comments

Comments
 (0)