/** * Example of getting the blob's latest information, if its generation does not match the {@link * Blob#getGeneration()} value, otherwise a {@link StorageException} is thrown. */ // [TARGET reload(BlobSourceOption...)] public Blob reload() { // [START reload] Blob latestBlob = blob.reload(BlobSourceOption.generationNotMatch()); if (latestBlob == null) { // the blob was not found } // [END reload] return latestBlob; }
@Test public void testReloadNull() throws Exception { initializeExpectedBlob(1); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.get(BLOB_INFO.getBlobId(), new Storage.BlobGetOption[0])).andReturn(null); replay(storage); initializeBlob(); Blob reloadedBlob = blob.reload(); assertNull(reloadedBlob); }
@Test public void testReload() throws Exception { initializeExpectedBlob(2); Blob expectedReloadedBlob = expectedBlob.toBuilder().setCacheControl("c").build(); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.get(BLOB_INFO.getBlobId(), new Storage.BlobGetOption[0])) .andReturn(expectedReloadedBlob); replay(storage); initializeBlob(); Blob updatedBlob = blob.reload(); assertEquals(expectedReloadedBlob, updatedBlob); }
@Test public void testReloadWithOptions() throws Exception { initializeExpectedBlob(2); Blob expectedReloadedBlob = expectedBlob.toBuilder().setCacheControl("c").build(); Storage.BlobGetOption[] options = {Storage.BlobGetOption.metagenerationMatch(42L)}; expect(storage.getOptions()).andReturn(mockOptions); expect(storage.get(BLOB_INFO.getBlobId(), options)).andReturn(expectedReloadedBlob); replay(storage); initializeBlob(); Blob updatedBlob = blob.reload(BlobSourceOption.metagenerationMatch()); assertEquals(expectedReloadedBlob, updatedBlob); }