|
19 | 19 | import static java.nio.charset.StandardCharsets.UTF_8; |
20 | 20 | import static org.junit.Assert.assertArrayEquals; |
21 | 21 | import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertFalse; |
22 | 23 | import static org.junit.Assert.assertNotNull; |
23 | 24 | import static org.junit.Assert.assertNull; |
24 | 25 | import static org.junit.Assert.assertTrue; |
@@ -130,7 +131,8 @@ public void testCreateBlob() { |
130 | 131 | BlobInfo remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT); |
131 | 132 | assertNotNull(remoteBlob); |
132 | 133 | assertEquals(blob.bucket(), remoteBlob.bucket()); |
133 | | - assertEquals(blob.name(), remoteBlob.name()); byte[] readBytes = storage.readAllBytes(BUCKET, blobName); |
| 134 | + assertEquals(blob.name(), remoteBlob.name()); |
| 135 | + byte[] readBytes = storage.readAllBytes(BUCKET, blobName); |
134 | 136 | assertArrayEquals(BLOB_BYTE_CONTENT, readBytes); |
135 | 137 | assertTrue(storage.delete(BUCKET, blobName)); |
136 | 138 | } |
@@ -245,16 +247,26 @@ public void testGetBlobFail() { |
245 | 247 | String blobName = "test-get-blob-fail"; |
246 | 248 | BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build(); |
247 | 249 | assertNotNull(storage.create(blob)); |
248 | | - BlobId wrongGenerationBlob = BlobId.of(BUCKET, blobName, -1L); |
| 250 | + BlobId wrongGenerationBlob = BlobId.of(BUCKET, blobName); |
249 | 251 | try { |
250 | | - storage.get(wrongGenerationBlob, Storage.BlobGetOption.generationMatch()); |
| 252 | + storage.get(wrongGenerationBlob, Storage.BlobGetOption.generationMatch(-1)); |
251 | 253 | fail("StorageException was expected"); |
252 | 254 | } catch (StorageException ex) { |
253 | 255 | // expected |
254 | 256 | } |
255 | 257 | assertTrue(storage.delete(BUCKET, blobName)); |
256 | 258 | } |
257 | 259 |
|
| 260 | + @Test |
| 261 | + public void testGetBlobFailNonExistingGeneration() { |
| 262 | + String blobName = "test-get-blob-fail-non-existing-generation"; |
| 263 | + BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build(); |
| 264 | + assertNotNull(storage.create(blob)); |
| 265 | + BlobId wrongGenerationBlob = BlobId.of(BUCKET, blobName, -1L); |
| 266 | + assertNull(storage.get(wrongGenerationBlob)); |
| 267 | + assertTrue(storage.delete(BUCKET, blobName)); |
| 268 | + } |
| 269 | + |
258 | 270 | @Test |
259 | 271 | public void testListBlobsSelectedFields() { |
260 | 272 | String[] blobNames = {"test-list-blobs-selected-fields-blob1", |
@@ -405,6 +417,14 @@ public void testDeleteNonExistingBlob() { |
405 | 417 | assertTrue(!storage.delete(BUCKET, blobName)); |
406 | 418 | } |
407 | 419 |
|
| 420 | + @Test |
| 421 | + public void testDeleteBlobNonExistingGeneration() { |
| 422 | + String blobName = "test-delete-blob-non-existing-generation"; |
| 423 | + BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build(); |
| 424 | + assertNotNull(storage.create(blob)); |
| 425 | + assertTrue(!storage.delete(BlobId.of(BUCKET, blobName, -1L))); |
| 426 | + } |
| 427 | + |
408 | 428 | @Test |
409 | 429 | public void testDeleteBlobFail() { |
410 | 430 | String blobName = "test-delete-blob-fail"; |
@@ -611,19 +631,20 @@ public void testBatchRequestFail() { |
611 | 631 | BatchRequest batchRequest = BatchRequest.builder() |
612 | 632 | .update(updatedBlob, Storage.BlobTargetOption.generationMatch()) |
613 | 633 | .delete(BUCKET, blobName, Storage.BlobSourceOption.generationMatch(-1L)) |
614 | | - .delete(BlobId.of(BUCKET, blobName, -1L), Storage.BlobSourceOption.generationMatch()) |
| 634 | + .delete(BlobId.of(BUCKET, blobName, -1L)) |
615 | 635 | .get(BUCKET, blobName, Storage.BlobGetOption.generationMatch(-1L)) |
616 | | - .get(BlobId.of(BUCKET, blobName, -1L), Storage.BlobGetOption.generationMatch()) |
| 636 | + .get(BlobId.of(BUCKET, blobName, -1L)) |
617 | 637 | .build(); |
618 | | - BatchResponse updateResponse = storage.apply(batchRequest); |
619 | | - assertEquals(1, updateResponse.updates().size()); |
620 | | - assertEquals(2, updateResponse.deletes().size()); |
621 | | - assertEquals(2, updateResponse.gets().size()); |
622 | | - assertTrue(updateResponse.updates().get(0).failed()); |
623 | | - assertTrue(updateResponse.gets().get(0).failed()); |
624 | | - assertTrue(updateResponse.gets().get(1).failed()); |
625 | | - assertTrue(updateResponse.deletes().get(0).failed()); |
626 | | - assertTrue(updateResponse.deletes().get(1).failed()); |
| 638 | + BatchResponse batchResponse = storage.apply(batchRequest); |
| 639 | + assertEquals(1, batchResponse.updates().size()); |
| 640 | + assertEquals(2, batchResponse.deletes().size()); |
| 641 | + assertEquals(2, batchResponse.gets().size()); |
| 642 | + assertTrue(batchResponse.updates().get(0).failed()); |
| 643 | + assertTrue(batchResponse.gets().get(0).failed()); |
| 644 | + assertFalse(batchResponse.gets().get(1).failed()); |
| 645 | + assertNull(batchResponse.gets().get(1).get()); |
| 646 | + assertTrue(batchResponse.deletes().get(0).failed()); |
| 647 | + assertTrue(batchResponse.deletes().get(1).failed()); |
627 | 648 | assertTrue(storage.delete(BUCKET, blobName)); |
628 | 649 | } |
629 | 650 |
|
|
0 commit comments