Skip to content

Commit 14f300a

Browse files
authored
---
yaml --- r: 8719 b: refs/heads/master c: 21e7f4c h: refs/heads/master i: 8717: 15b868f 8715: de822bf 8711: db970b5 8703: 95fc0ab
1 parent 9f7522f commit 14f300a

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f2a238733cf05a82df39d4331d2f3d41b0adc89e
2+
refs/heads/master: 21e7f4ccaf7016e81130915f83bf0e4ad88580ac
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: 6daca92127d91b7c2c99490080ecf8a13fa94cde
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/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()

trunk/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.

trunk/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)