Skip to content

Commit 4bd3f66

Browse files
committed
---
yaml --- r: 5989 b: refs/heads/tswast-patch-1 c: 294cfb4 h: refs/heads/master i: 5987: b8c5e74
1 parent 18d2df6 commit 4bd3f66

3 files changed

Lines changed: 29 additions & 6 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: 502365303e2a961b61bf851f94a2ac40bf30513b
60+
refs/heads/tswast-patch-1: 294cfb4e76c7df4de5fe0c52c0ff999dfbca33ea
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public class BatchResponse implements Serializable {
3636
public static class Result<T extends Serializable> implements Serializable {
3737

3838
private static final long serialVersionUID = -1946539570170529094L;
39+
private static final Result EMPTY = new BatchResponse.Result(null);
3940

4041
private final T value;
4142
private final StorageServiceException exception;
4243

44+
4345
Result(T value) {
4446
this.value = value;
4547
this.exception = null;
@@ -50,13 +52,15 @@ public static class Result<T extends Serializable> implements Serializable {
5052
this.value = null;
5153
}
5254

53-
5455
/**
5556
* Returns the result.
5657
*
5758
* @throws StorageServiceException if failed
5859
*/
5960
public T result() throws StorageServiceException {
61+
if (failed()) {
62+
throw failure();
63+
}
6064
return value;
6165
}
6266

@@ -76,7 +80,15 @@ public boolean failed() {
7680

7781
@Override
7882
public String toString() {
79-
return MoreObjects.firstNonNull(value, exception).toString();
83+
return MoreObjects.toStringHelper(this)
84+
.add("value", value)
85+
.add("exception", exception)
86+
.toString();
87+
}
88+
89+
@SuppressWarnings("unchecked")
90+
static <T extends Serializable> Result<T> empty() {
91+
return EMPTY;
8092
}
8193
}
8294

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import com.google.common.collect.Iterables;
3838
import com.google.common.collect.Lists;
3939
import com.google.common.collect.Maps;
40+
import com.google.common.collect.Sets;
41+
import com.google.common.primitives.Ints;
4042
import com.google.gcloud.BaseService;
4143
import com.google.gcloud.ExceptionHandler;
4244
import com.google.gcloud.ExceptionHandler.Interceptor;
@@ -52,6 +54,7 @@
5254
import java.util.Arrays;
5355
import java.util.List;
5456
import java.util.Map;
57+
import java.util.Set;
5558
import java.util.concurrent.Callable;
5659

5760
final class StorageServiceImpl extends BaseService<StorageServiceOptions> implements StorageService {
@@ -325,20 +328,28 @@ public BatchResponse apply(BatchRequest batchRequest) {
325328
List<BatchResponse.Result<Blob>> updates = transformBatchResult(
326329
toUpdate, response.updates, Blob.FROM_PB_FUNCTION);
327330
List<BatchResponse.Result<Blob>> gets = transformBatchResult(
328-
toGet, response.gets, Blob.FROM_PB_FUNCTION);
331+
toGet, response.gets, Blob.FROM_PB_FUNCTION, 404);
329332
return new BatchResponse(deletes, updates, gets);
330333
}
331334

332335
private <I, O extends Serializable> List<BatchResponse.Result<O>> transformBatchResult(
333336
Iterable<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> request,
334-
Map<StorageObject, Tuple<I, StorageServiceException>> results, Function<I, O> transform) {
337+
Map<StorageObject, Tuple<I, StorageServiceException>> results, Function<I, O> transform,
338+
int... nullOnErrorCodes) {
339+
Set nullOnErrorCodesSet = Sets.newHashSet(Ints.asList(nullOnErrorCodes));
335340
List<BatchResponse.Result<O>> response = Lists.newArrayListWithCapacity(results.size());
336341
for (Tuple<StorageObject, ?> tuple : request) {
337342
Tuple<I, StorageServiceException> result = results.get(tuple.x());
338343
if (result.x() != null) {
339344
response.add(new BatchResponse.Result<>(transform.apply(result.x())));
340345
} else {
341-
response.add(new BatchResponse.Result<O>(result.y()));
346+
StorageServiceException exception = result.y();
347+
if (nullOnErrorCodesSet.contains(exception.code())) {
348+
//noinspection unchecked
349+
response.add(BatchResponse.Result.<O>empty());
350+
} else {
351+
response.add(new BatchResponse.Result<O>(result.y()));
352+
}
342353
}
343354
}
344355
return response;

0 commit comments

Comments
 (0)