Skip to content

Commit d123a28

Browse files
committed
---
yaml --- r: 897 b: refs/heads/master c: 93b7a0c h: refs/heads/master i: 895: b92f5a2 v: v3
1 parent 13926bb commit d123a28

9 files changed

Lines changed: 35 additions & 453 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
refs/heads/master: 5d8d1237244e0c8b9a76dc66782d6c69cdd916ac
2+
refs/heads/master: 93b7a0c7edc39f794582bce2c01cc81b9b810b75
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
import org.junit.AfterClass;
4242
import org.junit.Before;
4343
import org.junit.BeforeClass;
44-
import org.junit.Rule;
4544
import org.junit.Test;
46-
import org.junit.rules.ExpectedException;
4745
import org.junit.runner.RunWith;
4846
import org.junit.runners.JUnit4;
4947

@@ -104,9 +102,6 @@ public class DatastoreTest {
104102

105103
private static LocalGcdHelper gcdHelper;
106104

107-
@Rule
108-
public ExpectedException thrown = ExpectedException.none();
109-
110105
@BeforeClass
111106
public static void beforeClass() throws IOException, InterruptedException {
112107
if (!LocalGcdHelper.isActive(PROJECT_ID)) {
@@ -640,7 +635,7 @@ public void testKeyFactory() {
640635
}
641636

642637
@Test
643-
public void testRetryableException() throws Exception {
638+
public void testRetires() throws Exception {
644639
DatastoreV1.LookupRequest requestPb =
645640
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
646641
DatastoreV1.LookupResponse responsePb = DatastoreV1.LookupResponse.newBuilder()
@@ -662,51 +657,4 @@ public void testRetryableException() throws Exception {
662657
assertEquals(ENTITY1, entity);
663658
EasyMock.verify(rpcFactoryMock, rpcMock);
664659
}
665-
666-
@Test
667-
public void testNonRetryableException() throws Exception {
668-
DatastoreV1.LookupRequest requestPb =
669-
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
670-
DatastoreRpcFactory rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
671-
DatastoreRpc rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
672-
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
673-
.andReturn(rpcMock);
674-
EasyMock.expect(rpcMock.lookup(requestPb))
675-
.andThrow(new DatastoreRpc.DatastoreRpcException(Reason.PERMISSION_DENIED))
676-
.times(1);
677-
EasyMock.replay(rpcFactoryMock, rpcMock);
678-
RetryParams retryParams = RetryParams.builder().retryMinAttempts(2).build();
679-
DatastoreOptions options = this.options.toBuilder()
680-
.retryParams(retryParams)
681-
.serviceRpcFactory(rpcFactoryMock)
682-
.build();
683-
Datastore datastore = DatastoreFactory.instance().get(options);
684-
thrown.expect(DatastoreException.class);
685-
thrown.expectMessage(Reason.PERMISSION_DENIED.description());
686-
datastore.get(KEY1);
687-
EasyMock.verify(rpcFactoryMock, rpcMock);
688-
}
689-
690-
@Test
691-
public void testRuntimeException() throws Exception {
692-
DatastoreV1.LookupRequest requestPb =
693-
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
694-
DatastoreRpcFactory rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
695-
DatastoreRpc rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
696-
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
697-
.andReturn(rpcMock);
698-
String exceptionMessage = "Artificial runtime exception";
699-
EasyMock.expect(rpcMock.lookup(requestPb))
700-
.andThrow(new RuntimeException(exceptionMessage));
701-
EasyMock.replay(rpcFactoryMock, rpcMock);
702-
DatastoreOptions options = this.options.toBuilder()
703-
.retryParams(RetryParams.getDefaultInstance())
704-
.serviceRpcFactory(rpcFactoryMock)
705-
.build();
706-
Datastore datastore = DatastoreFactory.instance().get(options);
707-
thrown.expect(DatastoreException.class);
708-
thrown.expectMessage(exceptionMessage);
709-
datastore.get(KEY1);
710-
EasyMock.verify(rpcFactoryMock, rpcMock);
711-
}
712660
}

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.google.api.client.http.HttpResponse;
4444
import com.google.api.client.http.HttpResponseException;
4545
import com.google.api.client.http.HttpTransport;
46+
import com.google.api.client.http.InputStreamContent;
4647
import com.google.api.client.http.json.JsonHttpContent;
4748
import com.google.api.client.json.JsonFactory;
4849
import com.google.api.client.json.jackson.JacksonFactory;
@@ -63,6 +64,7 @@
6364

6465
import java.io.ByteArrayOutputStream;
6566
import java.io.IOException;
67+
import java.io.InputStream;
6668
import java.util.ArrayList;
6769
import java.util.List;
6870
import java.util.Map;
@@ -119,13 +121,14 @@ public Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageExcept
119121
}
120122

121123
@Override
122-
public StorageObject create(StorageObject storageObject, final byte[] content,
124+
public StorageObject create(StorageObject storageObject, final InputStream content,
123125
Map<Option, ?> options) throws StorageException {
124126
try {
125-
return storage.objects()
127+
Storage.Objects.Insert insert = storage.objects()
126128
.insert(storageObject.getBucket(), storageObject,
127-
new ByteArrayContent(storageObject.getContentType(), content))
128-
.setProjection(DEFAULT_PROJECTION)
129+
new InputStreamContent(storageObject.getContentType(), content));
130+
insert.getMediaHttpUploader().setDirectUploadEnabled(true);
131+
return insert.setProjection(DEFAULT_PROJECTION)
129132
.setPredefinedAcl(PREDEFINED_ACL.getString(options))
130133
.setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options))
131134
.setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
@@ -521,4 +524,3 @@ public String open(StorageObject object, Map<Option, ?> options)
521524
}
522525
}
523526
}
524-

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.collect.ImmutableMap;
2323
import com.google.gcloud.storage.StorageException;
2424

25+
import java.io.InputStream;
2526
import java.util.List;
2627
import java.util.Map;
2728

@@ -128,7 +129,7 @@ public BatchResponse(Map<StorageObject, Tuple<Boolean, StorageException>> delete
128129

129130
Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageException;
130131

131-
StorageObject create(StorageObject object, byte[] content, Map<Option, ?> options)
132+
StorageObject create(StorageObject object, InputStream content, Map<Option, ?> options)
132133
throws StorageException;
133134

134135
Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) throws StorageException;

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java renamed to trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Default implementation for BlobWriteChannel.
3434
*/
35-
class BlobWriteChannelImpl implements BlobWriteChannel {
35+
class BlobWriterChannelImpl implements BlobWriteChannel {
3636

3737
private static final long serialVersionUID = 8675286882724938737L;
3838
private static final int MIN_CHUNK_SIZE = 256 * 1024;
@@ -50,12 +50,12 @@ class BlobWriteChannelImpl implements BlobWriteChannel {
5050
private transient StorageRpc storageRpc;
5151
private transient StorageObject storageObject;
5252

53-
BlobWriteChannelImpl(StorageOptions options, BlobInfo blobInfo,
53+
BlobWriterChannelImpl(StorageOptions options, BlobInfo blobInfo,
5454
Map<StorageRpc.Option, ?> optionsMap) {
5555
this.options = options;
5656
this.blobInfo = blobInfo;
5757
initTransients();
58-
uploadId = storageRpc.open(storageObject, optionsMap);
58+
uploadId = options.storageRpc().open(storageObject, optionsMap);
5959
}
6060

6161
private void writeObject(ObjectOutputStream out) throws IOException {

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.gcloud.Service;
2626
import com.google.gcloud.spi.StorageRpc;
2727

28+
import java.io.InputStream;
2829
import java.io.Serializable;
2930
import java.net.URL;
3031
import java.util.Arrays;
@@ -500,6 +501,14 @@ public static Builder builder() {
500501
*/
501502
BlobInfo create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options);
502503

504+
/**
505+
* Create a new blob.
506+
*
507+
* @return a complete blob information.
508+
* @throws StorageException upon failure
509+
*/
510+
BlobInfo createFromStream(BlobInfo blobInfo, InputStream content, BlobTargetOption... options);
511+
503512
/**
504513
* Return the requested bucket or {@code null} if not found.
505514
*

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import com.google.gcloud.spi.StorageRpc;
5050
import com.google.gcloud.spi.StorageRpc.Tuple;
5151

52+
import java.io.ByteArrayInputStream;
53+
import java.io.InputStream;
5254
import java.io.Serializable;
5355
import java.io.UnsupportedEncodingException;
5456
import java.net.MalformedURLException;
@@ -114,12 +116,20 @@ public com.google.api.services.storage.model.Bucket call() {
114116

115117
@Override
116118
public BlobInfo create(BlobInfo blobInfo, final byte[] content, BlobTargetOption... options) {
119+
return createFromStream(blobInfo,
120+
new ByteArrayInputStream(firstNonNull(content, EMPTY_BYTE_ARRAY)), options);
121+
}
122+
123+
@Override
124+
public BlobInfo createFromStream(BlobInfo blobInfo, final InputStream content,
125+
BlobTargetOption... options) {
117126
final StorageObject blobPb = blobInfo.toPb();
118127
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
119128
return BlobInfo.fromPb(runWithRetries(new Callable<StorageObject>() {
120129
@Override
121130
public StorageObject call() {
122-
return storageRpc.create(blobPb, firstNonNull(content, EMPTY_BYTE_ARRAY), optionsMap);
131+
return storageRpc.create(blobPb,
132+
firstNonNull(content, new ByteArrayInputStream(EMPTY_BYTE_ARRAY)), optionsMap);
123133
}
124134
}, options().retryParams(), EXCEPTION_HANDLER));
125135
}
@@ -443,7 +453,7 @@ public BlobReadChannel reader(String bucket, String blob, BlobSourceOption... op
443453
@Override
444454
public BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) {
445455
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
446-
return new BlobWriteChannelImpl(options(), blobInfo, optionsMap);
456+
return new BlobWriterChannelImpl(options(), blobInfo, optionsMap);
447457
}
448458

449459
@Override

0 commit comments

Comments
 (0)