Skip to content

Commit 2b44d08

Browse files
droazenmichaelbausor
authored andcommitted
---
yaml --- r: 8279 b: refs/heads/master c: 4055f1f h: refs/heads/master i: 8277: 6be623e 8275: a3cbb9c 8271: 16910a9
1 parent 420d0dd commit 2b44d08

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 10bc8bbfdd78ce68c476bf78c4467529643d355c
2+
refs/heads/master: 4055f1ffeb78680120b4dab6bbda1f621eb5e2fc
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: 983ad13eceefeee06f3300486563b47902cedb77
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageReadChannel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private CloudStorageReadChannel(Storage gcsStorage, BlobId file, long position,
8282
private void innerOpen() throws IOException {
8383
this.channel = gcsStorage.reader(file);
8484
if (position > 0) {
85-
channel.seek((int) position);
85+
channel.seek(position);
8686
}
8787
}
8888

trunk/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageReadChannelTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.junit.rules.ExpectedException;
3838
import org.junit.runner.RunWith;
3939
import org.junit.runners.JUnit4;
40+
import org.mockito.ArgumentCaptor;
4041

4142
import javax.net.ssl.SSLHandshakeException;
4243
import java.io.IOException;
@@ -191,4 +192,25 @@ public void testSetPosition() throws IOException {
191192
verify(gcsChannel).seek(1);
192193
verify(gcsChannel, times(5)).isOpen();
193194
}
195+
196+
/*
197+
* This test case was crafted in response to a bug in CloudStorageReadChannel in which the
198+
* channel position (a long) was getting truncated to an int when seeking on the encapsulated
199+
* ReadChannel in innerOpen(). This test case fails when the bad long -> int cast is present,
200+
* and passes when it's removed.
201+
*/
202+
@Test
203+
public void testChannelPositionDoesNotGetTruncatedToInt() throws IOException {
204+
// This position value will overflow to a negative value if a long -> int cast is attempted
205+
long startPosition = 11918483280L;
206+
ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class);
207+
208+
// Invoke CloudStorageReadChannel.create() to trigger a call to the private
209+
// CloudStorageReadChannel.innerOpen() method, which does a seek on our gcsChannel.
210+
CloudStorageReadChannel.create(gcsStorage, file, startPosition, 1);
211+
212+
// Confirm that our position did not overflow during the seek in CloudStorageReadChannel.innerOpen()
213+
verify(gcsChannel).seek(captor.capture());
214+
assertThat(captor.getValue()).isEqualTo(startPosition);
215+
}
194216
}

0 commit comments

Comments
 (0)