@@ -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