Skip to content

Commit ec7da21

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 6353 b: refs/heads/tswast-patch-1 c: de1ce7f h: refs/heads/master i: 6351: 4b2352a
1 parent 6a95a16 commit ec7da21

8 files changed

Lines changed: 74 additions & 158 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: e4da160ab9dd70aee39fdca5582024e967de5490
60+
refs/heads/tswast-patch-1: de1ce7fe771306435c5cc9c63376fbbdad538ee7
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
3636
import com.google.gcloud.datastore.testing.LocalGcdHelper;
3737
import com.google.gcloud.spi.DatastoreRpc;
38+
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
3839
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
3940
import com.google.gcloud.spi.DatastoreRpcFactory;
4041

@@ -49,9 +50,12 @@
4950
import org.junit.runners.JUnit4;
5051

5152
import java.io.IOException;
53+
import java.util.ArrayList;
5254
import java.util.Collections;
55+
import java.util.HashSet;
5356
import java.util.Iterator;
5457
import java.util.List;
58+
import java.util.Set;
5559

5660
@RunWith(JUnit4.class)
5761
public class DatastoreTest {
@@ -520,7 +524,7 @@ public void testGet() {
520524
}
521525

522526
@Test
523-
public void testGetArray() {
527+
public void testGetArrayNoDeferredResults() {
524528
datastore.put(ENTITY3);
525529
Iterator<Entity> result =
526530
datastore.fetch(KEY1, Key.builder(KEY1).name("bla").build(), KEY2, KEY3).iterator();
@@ -546,7 +550,65 @@ public void testGetArray() {
546550
// expected - no such property
547551
}
548552
assertFalse(result.hasNext());
549-
// TODO(ozarov): construct a test to verify more results
553+
}
554+
555+
public void testGetArrayDeferredResults() throws DatastoreRpcException {
556+
List<DatastoreV1.Key> keysPb = new ArrayList<>();
557+
keysPb.add(KEY1.toPb());
558+
keysPb.add(KEY2.toPb());
559+
keysPb.add(KEY3.toPb());
560+
keysPb.add(KEY4.toPb());
561+
keysPb.add(KEY5.toPb());
562+
List<DatastoreV1.LookupRequest> lookupRequests = new ArrayList<>();
563+
lookupRequests.add(DatastoreV1.LookupRequest.newBuilder().addAllKey(keysPb).build());
564+
lookupRequests.add(
565+
DatastoreV1.LookupRequest.newBuilder()
566+
.addKey(keysPb.get(2))
567+
.addKey(keysPb.get(3))
568+
.addKey(keysPb.get(5))
569+
.build());
570+
lookupRequests.add(DatastoreV1.LookupRequest.newBuilder().addKey(keysPb.get(5)).build());
571+
Entity entity4 = Entity.builder(KEY4).set("value", StringValue.of("value")).build();
572+
Entity entity5 = Entity.builder(KEY5).set("value", "value").build();
573+
List<DatastoreV1.LookupResponse> lookupResponses = new ArrayList<>();
574+
lookupResponses.add(
575+
DatastoreV1.LookupResponse.newBuilder()
576+
.addFound(EntityResult.newBuilder().setEntity(ENTITY1.toPb()))
577+
.addFound(EntityResult.newBuilder().setEntity(entity4.toPb()))
578+
.addDeferred(KEY2.toPb())
579+
.addDeferred(KEY3.toPb())
580+
.addDeferred(KEY5.toPb())
581+
.build());
582+
lookupResponses.add(
583+
DatastoreV1.LookupResponse.newBuilder()
584+
.addFound(EntityResult.newBuilder().setEntity(ENTITY3.toPb()))
585+
.addFound(EntityResult.newBuilder().setEntity(entity4.toPb()))
586+
.addDeferred(KEY5.toPb())
587+
.build());
588+
lookupResponses.add(
589+
DatastoreV1.LookupResponse.newBuilder()
590+
.addFound(EntityResult.newBuilder().setEntity(entity5.toPb()))
591+
.build());
592+
DatastoreRpcFactory rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
593+
DatastoreRpc rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
594+
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
595+
.andReturn(rpcMock);
596+
for (int i = 0; i < lookupRequests.size(); i++) {
597+
EasyMock.expect(rpcMock.lookup(lookupRequests.get(i))).andReturn(lookupResponses.get(i));
598+
}
599+
EasyMock.replay(rpcFactoryMock, rpcMock);
600+
DatastoreOptions options =
601+
this.options.toBuilder()
602+
.retryParams(RetryParams.getDefaultInstance())
603+
.serviceRpcFactory(rpcFactoryMock)
604+
.build();
605+
Datastore datastore = DatastoreFactory.instance().get(options);
606+
Iterator<Entity> iter = datastore.get(KEY1, KEY2, KEY3, KEY4, KEY5);
607+
Set<Entity> foundEntities = new HashSet<>();
608+
while (iter.hasNext()) {
609+
foundEntities.add(iter.next());
610+
}
611+
assertEquals(foundEntities.size(), 5);
550612
}
551613

552614
@Test

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public boolean equals(Object obj) {
133133
BatchResponse other = (BatchResponse) obj;
134134
return Objects.equals(deleteResult, other.deleteResult)
135135
&& Objects.equals(updateResult, other.updateResult)
136-
&& Objects.equals(getResult, other.getResult);
136+
&& Objects.equals(updateResult, other.updateResult);
137137
}
138138

139139
/**

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
2121

22-
import com.google.common.base.MoreObjects;
2322
import com.google.gcloud.storage.Storage.BlobSourceOption;
2423
import com.google.gcloud.storage.Storage.BlobTargetOption;
25-
import com.google.gcloud.storage.Storage.BlobWriteOption;
2624
import com.google.gcloud.storage.Storage.BucketSourceOption;
2725
import com.google.gcloud.storage.Storage.BucketTargetOption;
28-
import java.io.InputStream;
2926

3027
import java.util.ArrayList;
3128
import java.util.Collections;
@@ -175,43 +172,17 @@ public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
175172
}
176173

177174
/**
178-
* Creates a new blob in this bucket. Direct upload is used to upload {@code content}.
179-
* For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)}
180-
* is recommended as it uses resumable upload. MD5 and CRC32C hashes of {@code content} are
181-
* computed and used for validating transferred data.
175+
* Creates a new blob in this bucket.
182176
*
183177
* @param blob a blob name
184178
* @param content the blob content
185-
* @param contentType the blob content type. If {@code null} then
186-
* {@value com.google.gcloud.storage.Storage#DEFAULT_CONTENT_TYPE} is used.
187179
* @param options options for blob creation
188180
* @return a complete blob information.
189181
* @throws StorageException upon failure
190182
*/
191-
public Blob create(String blob, byte[] content, String contentType, BlobTargetOption... options) {
192-
BlobInfo blobInfo = BlobInfo.builder(BlobId.of(info.name(), blob))
193-
.contentType(MoreObjects.firstNonNull(contentType, Storage.DEFAULT_CONTENT_TYPE)).build();
194-
return new Blob(storage, storage.create(blobInfo, content, options));
195-
}
196-
197-
/**
198-
* Creates a new blob in this bucket. Direct upload is used to upload {@code content}.
199-
* For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)}
200-
* is recommended as it uses resumable upload.
201-
*
202-
* @param blob a blob name
203-
* @param content the blob content as a stream
204-
* @param contentType the blob content type. If {@code null} then
205-
* {@value com.google.gcloud.storage.Storage#DEFAULT_CONTENT_TYPE} is used.
206-
* @param options options for blob creation
207-
* @return a complete blob information.
208-
* @throws StorageException upon failure
209-
*/
210-
public Blob create(String blob, InputStream content, String contentType,
211-
BlobWriteOption... options) {
212-
BlobInfo blobInfo = BlobInfo.builder(BlobId.of(info.name(), blob))
213-
.contentType(MoreObjects.firstNonNull(contentType, Storage.DEFAULT_CONTENT_TYPE)).build();
214-
return new Blob(storage, storage.create(blobInfo, content, options));
183+
Blob create(String blob, byte[] content, BlobTargetOption... options) {
184+
BlobId blobId = BlobId.of(info.name(), blob);
185+
return new Blob(storage, storage.create(BlobInfo.builder(blobId).build(), content, options));
215186
}
216187

217188
/**

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
*/
4747
public interface Storage extends Service<StorageOptions> {
4848

49-
public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
50-
5149
enum PredefinedAcl {
5250
AUTHENTICATED_READ("authenticatedRead"),
5351
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers"),

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static com.google.gcloud.storage.Storage.PredefinedAcl.PUBLIC_READ;
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertNotEquals;
2322
import static org.junit.Assert.assertTrue;
2423

2524
import com.google.common.collect.Iterables;
@@ -83,56 +82,4 @@ public void testBatchRequest() {
8382
assertTrue(Iterables.isEmpty(get.getValue()));
8483
assertFalse(gets.hasNext());
8584
}
86-
87-
@Test
88-
public void testEquals() {
89-
BatchRequest request = BatchRequest.builder()
90-
.delete("b1", "o1")
91-
.delete("b1", "o2")
92-
.update(BlobInfo.builder("b2", "o1").build())
93-
.update(BlobInfo.builder("b2", "o2").build())
94-
.get("b3", "o1")
95-
.get("b3", "o2")
96-
.build();
97-
BatchRequest requestEquals = BatchRequest.builder()
98-
.delete("b1", "o1")
99-
.delete("b1", "o2")
100-
.update(BlobInfo.builder("b2", "o1").build())
101-
.update(BlobInfo.builder("b2", "o2").build())
102-
.get("b3", "o1")
103-
.get("b3", "o2")
104-
.build();
105-
BatchRequest requestNotEquals1 = BatchRequest.builder()
106-
.delete("b1", "o1")
107-
.delete("b1", "o3")
108-
.update(BlobInfo.builder("b2", "o1").build())
109-
.update(BlobInfo.builder("b2", "o2").build())
110-
.get("b3", "o1")
111-
.get("b3", "o2")
112-
.build();
113-
BatchRequest requestNotEquals2 = BatchRequest.builder()
114-
.delete("b1", "o1")
115-
.delete("b1", "o2")
116-
.update(BlobInfo.builder("b2", "o1").build())
117-
.update(BlobInfo.builder("b2", "o3").build())
118-
.get("b3", "o1")
119-
.get("b3", "o2")
120-
.build();
121-
BatchRequest requestNotEquals3 = BatchRequest.builder()
122-
.delete("b1", "o1")
123-
.delete("b1", "o2")
124-
.update(BlobInfo.builder("b2", "o1").build())
125-
.update(BlobInfo.builder("b2", "o2").build())
126-
.get("b3", "o1")
127-
.get("b3", "o3")
128-
.build();
129-
assertEquals(request, requestEquals);
130-
assertEquals(request.hashCode(), requestEquals.hashCode());
131-
assertNotEquals(request, requestNotEquals1);
132-
assertNotEquals(request.hashCode(), requestNotEquals1.hashCode());
133-
assertNotEquals(request, requestNotEquals2);
134-
assertNotEquals(request.hashCode(), requestNotEquals2.hashCode());
135-
assertNotEquals(request, requestNotEquals3);
136-
assertNotEquals(request.hashCode(), requestNotEquals3.hashCode());
137-
}
13885
}

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

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.gcloud.storage;
1818

1919
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotEquals;
2120

2221
import com.google.common.collect.ImmutableList;
2322
import com.google.gcloud.storage.BatchResponse.Result;
@@ -35,38 +34,12 @@ public class BatchResponseTest {
3534
@Test
3635
public void testBatchResponse() {
3736
List<Result<Boolean>> deletes = ImmutableList.of(Result.of(true), Result.of(false));
38-
List<Result<BlobInfo>> updates =
39-
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
37+
List<Result<BlobInfo>> updates = ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
4038
List<Result<BlobInfo>> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
4139
BatchResponse response = new BatchResponse(deletes, updates, gets);
40+
4241
assertEquals(deletes, response.deletes());
4342
assertEquals(updates, response.updates());
4443
assertEquals(gets, response.gets());
4544
}
46-
47-
@Test
48-
public void testEquals() {
49-
List<Result<Boolean>> deletes = ImmutableList.of(Result.of(true), Result.of(false));
50-
List<Result<BlobInfo>> updates =
51-
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
52-
List<Result<BlobInfo>> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
53-
List<Result<Boolean>> otherDeletes = ImmutableList.of(Result.of(false), Result.of(true));
54-
List<Result<BlobInfo>> otherUpdates =
55-
ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
56-
List<Result<BlobInfo>> otherGets =
57-
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
58-
BatchResponse response = new BatchResponse(deletes, updates, gets);
59-
BatchResponse responseEquals = new BatchResponse(deletes, updates, gets);
60-
BatchResponse responseNotEquals1 = new BatchResponse(otherDeletes, updates, gets);
61-
BatchResponse responseNotEquals2 = new BatchResponse(deletes, otherUpdates, gets);
62-
BatchResponse responseNotEquals3 = new BatchResponse(deletes, updates, otherGets);
63-
assertEquals(response, responseEquals);
64-
assertEquals(response.hashCode(), responseEquals.hashCode());
65-
assertNotEquals(response, responseNotEquals1);
66-
assertNotEquals(response.hashCode(), responseNotEquals1.hashCode());
67-
assertNotEquals(response, responseNotEquals2);
68-
assertNotEquals(response.hashCode(), responseNotEquals2.hashCode());
69-
assertNotEquals(response, responseNotEquals3);
70-
assertNotEquals(response.hashCode(), responseNotEquals3.hashCode());
71-
}
7245
}

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

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
import com.google.common.collect.ImmutableList;
3030
import com.google.gcloud.storage.BatchResponse.Result;
31-
import java.io.ByteArrayInputStream;
32-
import java.io.InputStream;
3331
import java.util.Collections;
3432
import java.util.Iterator;
3533
import java.util.LinkedList;
@@ -47,7 +45,6 @@ public class BucketTest {
4745
BlobInfo.builder("b", "n1").build(),
4846
BlobInfo.builder("b", "n2").build(),
4947
BlobInfo.builder("b", "n3").build());
50-
private static final String CONTENT_TYPE = "text/plain";
5148

5249
private Storage storage;
5350
private Bucket bucket;
@@ -164,43 +161,11 @@ public void testGetAll() throws Exception {
164161

165162
@Test
166163
public void testCreate() throws Exception {
167-
BlobInfo info = BlobInfo.builder("b", "n").contentType(CONTENT_TYPE).build();
168-
byte[] content = {0xD, 0xE, 0xA, 0xD};
169-
expect(storage.create(info, content)).andReturn(info);
170-
replay(storage);
171-
Blob blob = bucket.create("n", content, CONTENT_TYPE);
172-
assertEquals(info, blob.info());
173-
}
174-
175-
@Test
176-
public void testCreateNullContentType() throws Exception {
177-
BlobInfo info = BlobInfo.builder("b", "n").contentType(Storage.DEFAULT_CONTENT_TYPE).build();
164+
BlobInfo info = BlobInfo.builder("b", "n").build();
178165
byte[] content = {0xD, 0xE, 0xA, 0xD};
179166
expect(storage.create(info, content)).andReturn(info);
180167
replay(storage);
181-
Blob blob = bucket.create("n", content, null);
182-
assertEquals(info, blob.info());
183-
}
184-
185-
@Test
186-
public void testCreateFromStream() throws Exception {
187-
BlobInfo info = BlobInfo.builder("b", "n").contentType(CONTENT_TYPE).build();
188-
byte[] content = {0xD, 0xE, 0xA, 0xD};
189-
InputStream streamContent = new ByteArrayInputStream(content);
190-
expect(storage.create(info, streamContent)).andReturn(info);
191-
replay(storage);
192-
Blob blob = bucket.create("n", streamContent, CONTENT_TYPE);
193-
assertEquals(info, blob.info());
194-
}
195-
196-
@Test
197-
public void testCreateFromStreamNullContentType() throws Exception {
198-
BlobInfo info = BlobInfo.builder("b", "n").contentType(Storage.DEFAULT_CONTENT_TYPE).build();
199-
byte[] content = {0xD, 0xE, 0xA, 0xD};
200-
InputStream streamContent = new ByteArrayInputStream(content);
201-
expect(storage.create(info, streamContent)).andReturn(info);
202-
replay(storage);
203-
Blob blob = bucket.create("n", streamContent, null);
168+
Blob blob = bucket.create("n", content);
204169
assertEquals(info, blob.info());
205170
}
206171

0 commit comments

Comments
 (0)