|
46 | 46 | import com.google.cloud.storage.it.runner.registry.Generator; |
47 | 47 | import com.google.cloud.storage.it.runner.registry.ObjectsFixture; |
48 | 48 | import com.google.cloud.storage.it.runner.registry.ObjectsFixture.ObjectAndContent; |
| 49 | +import com.google.common.collect.ImmutableMap; |
49 | 50 | import com.google.common.io.BaseEncoding; |
50 | 51 | import com.google.common.io.ByteStreams; |
51 | 52 | import java.io.ByteArrayInputStream; |
@@ -528,6 +529,36 @@ public void responseWith416ReturnsZeroAndLeavesTheChannelOpen() throws IOExcepti |
528 | 529 | } |
529 | 530 | } |
530 | 531 |
|
| 532 | + @Test |
| 533 | + public void responseWith416AttemptingToReadStartingPastTheEndOfTheObjectIsTerminallyEOF() |
| 534 | + throws IOException { |
| 535 | + int length = 10; |
| 536 | + byte[] bytes = DataGenerator.base64Characters().genBytes(length); |
| 537 | + |
| 538 | + BlobInfo info1 = |
| 539 | + BlobInfo.newBuilder(bucket, generator.randomObjectName()) |
| 540 | + .setMetadata(ImmutableMap.of("gen", "1")) |
| 541 | + .build(); |
| 542 | + Blob gen1 = storage.create(info1, bytes, BlobTargetOption.doesNotExist()); |
| 543 | + |
| 544 | + try (ReadChannel reader = storage.reader(gen1.getBlobId())) { |
| 545 | + reader.seek(length + 1); |
| 546 | + ByteBuffer buf = ByteBuffer.allocate(1); |
| 547 | + assertThat(reader.read(buf)).isEqualTo(-1); |
| 548 | + assertThat(reader.read(buf)).isEqualTo(-1); |
| 549 | + |
| 550 | + BlobInfo update = gen1.toBuilder().setMetadata(ImmutableMap.of("gen", "2")).build(); |
| 551 | + BlobInfo gen2 = |
| 552 | + storage.create( |
| 553 | + update, |
| 554 | + DataGenerator.base64Characters().genBytes(length + 2), |
| 555 | + BlobTargetOption.generationMatch()); |
| 556 | + |
| 557 | + assertThat(reader.read(buf)).isEqualTo(-1); |
| 558 | + assertThat(reader.read(buf)).isEqualTo(-1); |
| 559 | + } |
| 560 | + } |
| 561 | + |
531 | 562 | /** Read channel does not consider itself closed once it returns {@code -1} from read. */ |
532 | 563 | @Test |
533 | 564 | public void readChannelIsAlwaysOpen_willReturnNegative1UntilExplicitlyClosed() throws Exception { |
|
0 commit comments