Skip to content

Commit 985daa9

Browse files
committed
---
yaml --- r: 6165 b: refs/heads/tswast-patch-1 c: 967c429 h: refs/heads/master i: 6163: 84ece0a
1 parent 1d2f8fc commit 985daa9

3 files changed

Lines changed: 46 additions & 18 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 575fa1f50ee34aa68d277cd4b09a054982b871cc
60+
refs/heads/tswast-patch-1: 967c4292b8320ed5d85700b080d7795a6b0370cd
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobReadChannelTest.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.Arrays;
3535
import java.util.Map;
3636
import java.util.Random;
37+
import static org.easymock.EasyMock.verify;
38+
import org.junit.After;
3739

3840
public class BlobReadChannelTest {
3941

@@ -55,28 +57,19 @@ public void setUp() throws IOException, InterruptedException {
5557
storageRpcMock = EasyMock.createMock(StorageRpc.class);
5658
}
5759

58-
@Test
59-
public void testCreate() {
60-
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
61-
EasyMock.replay(optionsMock);
62-
reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
63-
assertTrue(reader.isOpen());
60+
@After
61+
public void tearDown() throws Exception {
62+
verify(optionsMock);
63+
verify(storageRpcMock);
6464
}
6565

6666
@Test
67-
public void testReadSmall() throws IOException {
67+
public void testCreate() {
6868
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
69-
EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
7069
EasyMock.replay(optionsMock);
71-
reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
72-
byte[] result = randomByteArray(DEFAULT_CHUNK_SIZE);
73-
ByteBuffer readBuffer = ByteBuffer.allocate(42);
74-
EasyMock
75-
.expect(storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE))
76-
.andReturn(result);
7770
EasyMock.replay(storageRpcMock);
78-
reader.read(readBuffer);
79-
assertArrayEquals(Arrays.copyOf(result, readBuffer.capacity()), readBuffer.array());
71+
reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
72+
assertTrue(reader.isOpen());
8073
}
8174

8275
@Test
@@ -120,7 +113,6 @@ public void testReadBig() throws IOException {
120113
storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, DEFAULT_CHUNK_SIZE,
121114
CUSTOM_CHUNK_SIZE))
122115
.andReturn(secondResult);
123-
EasyMock.expectLastCall();
124116
EasyMock.replay(storageRpcMock);
125117
reader.read(firstReadBuffer);
126118
reader.read(secondReadBuffer);
@@ -165,6 +157,7 @@ public void testSeek() throws IOException {
165157
public void testClose() throws IOException {
166158
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
167159
EasyMock.replay(optionsMock);
160+
EasyMock.replay(storageRpcMock);
168161
reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
169162
assertTrue(reader.isOpen());
170163
reader.close();
@@ -175,6 +168,7 @@ public void testClose() throws IOException {
175168
public void testReadClosed() {
176169
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
177170
EasyMock.replay(optionsMock);
171+
EasyMock.replay(storageRpcMock);
178172
reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
179173
reader.close();
180174
try {

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriterChannelTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.Arrays;
3636
import java.util.Map;
3737
import java.util.Random;
38+
import static org.easymock.EasyMock.verify;
39+
import org.junit.After;
3840

3941
public class BlobWriterChannelTest {
4042

@@ -58,6 +60,12 @@ public void setUp() throws IOException, InterruptedException {
5860
storageRpcMock = EasyMock.createMock(StorageRpc.class);
5961
}
6062

63+
@After
64+
public void tearDown() throws Exception {
65+
verify(optionsMock);
66+
verify(storageRpcMock);
67+
}
68+
6169
@Test
6270
public void testCreate() {
6371
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
@@ -97,6 +105,32 @@ public void testWriteWithFlush() throws IOException {
97105
assertArrayEquals(buffer.array(), capturedBuffer.getValue());
98106
}
99107

108+
@Test
109+
public void testWritesAndFlush() throws IOException {
110+
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
111+
EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
112+
EasyMock.replay(optionsMock);
113+
EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
114+
Capture<byte[]> capturedBuffer = Capture.newInstance();
115+
storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
116+
EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(DEFAULT_CHUNK_SIZE),
117+
EasyMock.eq(false));
118+
EasyMock.expectLastCall();
119+
EasyMock.replay(storageRpcMock);
120+
writer = new BlobWriterChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS);
121+
ByteBuffer[] buffers = new ByteBuffer[DEFAULT_CHUNK_SIZE / MIN_CHUNK_SIZE];
122+
for (int i = 0; i < buffers.length; i++) {
123+
buffers[i] = randomBuffer(MIN_CHUNK_SIZE);
124+
assertEquals(MIN_CHUNK_SIZE, writer.write(buffers[i]));
125+
}
126+
for (int i = 0; i < buffers.length; i++) {
127+
assertArrayEquals(
128+
buffers[i].array(),
129+
Arrays.copyOfRange(
130+
capturedBuffer.getValue(), MIN_CHUNK_SIZE * i, MIN_CHUNK_SIZE * (i + 1)));
131+
}
132+
}
133+
100134
@Test
101135
public void testCloseWithoutFlush() throws IOException {
102136
EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);

0 commit comments

Comments
 (0)