Skip to content

Commit 630ad71

Browse files
authored
---
yaml --- r: 9005 b: refs/heads/lesv-patch-1 c: 21e7f4c h: refs/heads/master i: 9003: ae3a0a1
1 parent 12eb3f5 commit 630ad71

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ refs/tags/v0.22.0: 18b298fe4bfe8ec2f20b0e0bf7ffdcce5cc3c5fe
6666
refs/heads/vam-google-patch-1: d0c8fee3a4074d0bf7360ce8c4f7f7223d0ee7b9
6767
refs/heads/vam-google-patch-CODEOWNERS: 2ac1616e25229e51d08a984708ef1918f91a35ee
6868
refs/heads/danoscarmike-patch-1: 7342a9916bce4ed00002c7202e2a16c5d46afaea
69-
refs/heads/lesv-patch-1: f2a238733cf05a82df39d4331d2f3d41b0adc89e
69+
refs/heads/lesv-patch-1: 21e7f4ccaf7016e81130915f83bf0e4ad88580ac
7070
refs/heads/ml-update-branch: 079dd6610017f5c51b9d1938c12d6d55b61513cf
7171
refs/heads/vkedia-patch-2: 7d8241388a9769a5c069334761b06c7012c878e7
7272
refs/heads/vkedia-patch-3: 4d128043acaa7db9160faf439d2ca6104e8a88cb

branches/lesv-patch-1/google-cloud-core/src/main/java/com/google/cloud/BaseWriteChannel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ protected int getChunkSize() {
104104

105105
@Override
106106
public final void setChunkSize(int chunkSize) {
107-
chunkSize = (chunkSize / getMinChunkSize()) * getMinChunkSize();
108-
this.chunkSize = Math.max(getMinChunkSize(), chunkSize);
107+
int minSize = getMinChunkSize();
108+
109+
this.chunkSize = Math.max(minSize, (chunkSize + minSize - 1) / minSize * minSize);
109110
}
110111

111112
@InternalApi("This class should only be extended within google-cloud-java")
@@ -173,7 +174,6 @@ public final void close() throws IOException {
173174
public RestorableState<WriteChannel> capture() {
174175
byte[] bufferToSave = null;
175176
if (isOpen) {
176-
flush();
177177
bufferToSave = Arrays.copyOf(buffer, limit);
178178
}
179179
return stateBuilder()

branches/lesv-patch-1/google-cloud-core/src/main/java/com/google/cloud/WriteChannel.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
* A channel for writing data to Google Cloud services.
2424
*
2525
* <p>Implementations of this class may further buffer data internally to reduce remote calls.
26-
* Written data will only be visible after calling {@link #close()}. This interface implements
26+
* Written data might not be visible until calling {@link #close()}. This interface implements
2727
* {@link Restorable} to allow saving the writer's state to continue writing afterwards.
28-
* </p>
2928
*/
3029
public interface WriteChannel extends WritableByteChannel, Closeable, Restorable<WriteChannel> {
3130

32-
3331
/**
3432
* Sets the minimum size that will be written by a single RPC.
3533
* Written data will be buffered and only flushed upon reaching this size or closing the channel.

branches/lesv-patch-1/google-cloud-core/src/test/java/com/google/cloud/BaseWriteChannelTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@
1616

1717
package com.google.cloud;
1818

19+
import static com.google.common.truth.Truth.assertThat;
1920
import static junit.framework.TestCase.assertFalse;
2021
import static junit.framework.TestCase.assertTrue;
2122
import static org.junit.Assert.assertArrayEquals;
2223
import static org.junit.Assert.assertEquals;
2324
import static org.junit.Assert.assertNull;
2425

2526
import com.google.cloud.spi.ServiceRpcFactory;
26-
27-
import org.junit.Before;
28-
import org.junit.Rule;
29-
import org.junit.Test;
30-
import org.junit.rules.ExpectedException;
31-
3227
import java.io.IOException;
3328
import java.io.Serializable;
3429
import java.nio.ByteBuffer;
3530
import java.nio.channels.ClosedChannelException;
3631
import java.util.Arrays;
3732
import java.util.Random;
33+
import org.junit.Before;
34+
import org.junit.Rule;
35+
import org.junit.Test;
36+
import org.junit.rules.ExpectedException;
3837

3938
public class BaseWriteChannelTest {
4039

@@ -111,11 +110,16 @@ public void testValidateOpen() throws IOException {
111110
@Test
112111
public void testChunkSize() {
113112
channel.setChunkSize(42);
114-
assertEquals(MIN_CHUNK_SIZE, channel.getChunkSize());
113+
assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue();
114+
assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0);
115+
115116
channel.setChunkSize(2 * MIN_CHUNK_SIZE);
116-
assertEquals(2 * MIN_CHUNK_SIZE, channel.getChunkSize());
117-
channel.setChunkSize(512 * 1025);
118-
assertEquals(2 * MIN_CHUNK_SIZE, channel.getChunkSize());
117+
assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue();
118+
assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0);
119+
120+
channel.setChunkSize(2 * MIN_CHUNK_SIZE + 1);
121+
assertThat(channel.getChunkSize() >= MIN_CHUNK_SIZE).isTrue();
122+
assertThat(channel.getChunkSize() % MIN_CHUNK_SIZE).isEqualTo(0);
119123
}
120124

121125
@Test

0 commit comments

Comments
 (0)