diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java index 6959388f34ef..6e815648497a 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchRequest.java @@ -33,15 +33,15 @@ public final class BatchRequest implements Serializable { private static final long serialVersionUID = -1527992265939800345L; - private final Map> toDelete; + private final Map> toDelete; private final Map> toUpdate; - private final Map> toGet; + private final Map> toGet; public static class Builder { - private Map> toDelete = new LinkedHashMap<>(); + private Map> toDelete = new LinkedHashMap<>(); private Map> toUpdate = new LinkedHashMap<>(); - private Map> toGet = new LinkedHashMap<>(); + private Map> toGet = new LinkedHashMap<>(); private Builder() {} @@ -49,7 +49,15 @@ private Builder() {} * Delete the given blob. */ public Builder delete(String bucket, String blob, BlobSourceOption... options) { - toDelete.put(BlobInfo.of(bucket, blob), Lists.newArrayList(options)); + toDelete.put(BlobId.of(bucket, blob), Lists.newArrayList(options)); + return this; + } + + /** + * Delete the given blob. + */ + public Builder delete(BlobId blob, BlobSourceOption... options) { + toDelete.put(blob, Lists.newArrayList(options)); return this; } @@ -65,7 +73,15 @@ public Builder update(BlobInfo blobInfo, BlobTargetOption... options) { * Retrieve metadata for the given blob. */ public Builder get(String bucket, String blob, BlobSourceOption... options) { - toGet.put(BlobInfo.of(bucket, blob), Lists.newArrayList(options)); + toGet.put(BlobId.of(bucket, blob), Lists.newArrayList(options)); + return this; + } + + /** + * Retrieve metadata for the given blob. + */ + public Builder get(BlobId blob, BlobSourceOption... options) { + toGet.put(blob, Lists.newArrayList(options)); return this; } @@ -96,7 +112,7 @@ public boolean equals(Object obj) { && Objects.equals(toGet, other.toGet); } - public Map> toDelete() { + public Map> toDelete() { return toDelete; } @@ -104,7 +120,7 @@ public Map> toUpdate() { return toUpdate; } - public Map> toGet() { + public Map> toGet() { return toGet; } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java index 189ae2ad3065..321c3becaca4 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java @@ -28,7 +28,6 @@ import com.google.gcloud.storage.Storage.SignUrlOption; import java.net.URL; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -118,7 +117,19 @@ public Blob(Storage storage, BlobInfo info) { */ public Blob(Storage storage, String bucket, String blob) { this.storage = checkNotNull(storage); - this.info = BlobInfo.of(checkNotNull(bucket), checkNotNull(blob)); + this.info = BlobInfo.builder(BlobId.of(bucket, blob)).build(); + } + + /** + * Constructs a {@code Blob} object for the provided {@code BlobId}. The storage service is used + * to issue requests. + * + * @param storage the storage service used for issuing requests + * @param blobId blob's identifier + */ + public Blob(Storage storage, BlobId blobId) { + this.storage = checkNotNull(storage); + this.info = BlobInfo.builder(blobId).build(); } /** @@ -128,6 +139,13 @@ public BlobInfo info() { return info; } + /** + * Returns the blob's id. + */ + public BlobId id() { + return info.blobId(); + } + /** * Checks if this blob exists. * @@ -213,7 +231,7 @@ public Blob copyTo(String targetBucket, BlobSourceOption... options) { * @throws StorageException upon failure */ public Blob copyTo(String targetBucket, String targetBlob, BlobSourceOption... options) { - BlobInfo updatedInfo = info.toBuilder().bucket(targetBucket).name(targetBlob).build(); + BlobInfo updatedInfo = info.toBuilder().blobId(BlobId.of(targetBucket, targetBlob)).build(); CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name()) .sourceOptions(convert(info, options)).target(updatedInfo).build(); @@ -267,18 +285,18 @@ public Storage storage() { * {@code infos.length > 1} a batch request is used to fetch blobs. * * @param storage the storage service used to issue the request - * @param infos the blobs to get + * @param blobs the blobs to get * @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has - * been denied the corresponding item in the list is {@code null}. + * been denied the corresponding item in the list is {@code null}. * @throws StorageException upon failure */ - public static List get(final Storage storage, BlobInfo... infos) { + public static List get(final Storage storage, BlobId... blobs) { checkNotNull(storage); - checkNotNull(infos); - if (infos.length == 0) { + checkNotNull(blobs); + if (blobs.length == 0) { return Collections.emptyList(); } - return Collections.unmodifiableList(Lists.transform(storage.get(infos), + return Collections.unmodifiableList(Lists.transform(storage.get(blobs), new Function() { @Override public Blob apply(BlobInfo f) { @@ -294,7 +312,7 @@ public Blob apply(BlobInfo f) { * @param storage the storage service used to issue the request * @param infos the blobs to update * @return an immutable list of {@code Blob} objects. If a blob does not exist or access to it has - * been denied the corresponding item in the list is {@code null}. + * been denied the corresponding item in the list is {@code null}. * @throws StorageException upon failure */ public static List update(final Storage storage, BlobInfo... infos) { @@ -317,18 +335,18 @@ public Blob apply(BlobInfo f) { * {@code infos.length > 1} a batch request is used to delete blobs. * * @param storage the storage service used to issue the request - * @param infos the blobs to delete + * @param blobs the blobs to delete * @return an immutable list of booleans. If a blob has been deleted the corresponding item in the - * list is {@code true}. If deletion failed or access to the resource was denied the item is + * list is {@code true}. If deletion failed or access to the resource was denied the item is * {@code false}. * @throws StorageException upon failure */ - public static List delete(Storage storage, BlobInfo... infos) { + public static List delete(Storage storage, BlobId... blobs) { checkNotNull(storage); - checkNotNull(infos); - if (infos.length == 0) { + checkNotNull(blobs); + if (blobs.length == 0) { return Collections.emptyList(); } - return storage.delete(infos); + return storage.delete(blobs); } } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java new file mode 100644 index 000000000000..ea98e65d244d --- /dev/null +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java @@ -0,0 +1,82 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud.storage; + +import com.google.api.services.storage.model.StorageObject; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.MoreObjects; + +import java.io.Serializable; +import java.util.Objects; + +/** + * Google Storage object identifier. + */ +public final class BlobId implements Serializable { + + private static final long serialVersionUID = -6156002883225601925L; + private final String bucket; + private final String name; + + private BlobId(String bucket, String name) { + this.bucket = bucket; + this.name = name; + } + + public String bucket() { + return bucket; + } + + public String name() { + return name; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("bucket", bucket()) + .add("name", name()) + .toString(); + } + + @Override + public int hashCode() { + return Objects.hash(bucket, name); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof BlobId && Objects.equals(bucket, ((BlobId) obj).bucket) + && Objects.equals(name, ((BlobId) obj).name); + } + + StorageObject toPb() { + StorageObject storageObject = new StorageObject(); + storageObject.setBucket(bucket); + storageObject.setName(name); + return storageObject; + } + + public static BlobId of(String bucket, String name) { + return new BlobId(checkNotNull(bucket), checkNotNull(name)); + } + + static BlobId fromPb(StorageObject storageObject) { + return BlobId.of(storageObject.getBucket(), storageObject.getName()); + } +} diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java index 6c05c427ef6b..8e6921bbc20d 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java @@ -59,9 +59,8 @@ public StorageObject apply(BlobInfo blobInfo) { } }; private static final long serialVersionUID = 2228487739943277159L; - private final String bucket; + private final BlobId blobId; private final String id; - private final String name; private final String selfLink; private final String cacheControl; private final List acl; @@ -84,9 +83,8 @@ public StorageObject apply(BlobInfo blobInfo) { public static final class Builder { - private String bucket; + private BlobId blobId; private String id; - private String name; private String contentType; private String contentEncoding; private String contentDisposition; @@ -109,8 +107,8 @@ public static final class Builder { private Builder() {} - public Builder bucket(String bucket) { - this.bucket = checkNotNull(bucket); + public Builder blobId(BlobId blobId) { + this.blobId = checkNotNull(blobId); return this; } @@ -119,11 +117,6 @@ Builder id(String id) { return this; } - public Builder name(String name) { - this.name = checkNotNull(name); - return this; - } - public Builder contentType(String contentType) { this.contentType = firstNonNull(contentType, Data.nullOf(String.class)); return this; @@ -220,15 +213,13 @@ Builder updateTime(Long updateTime) { } public BlobInfo build() { - checkNotNull(bucket); - checkNotNull(name); + checkNotNull(blobId); return new BlobInfo(this); } } private BlobInfo(Builder builder) { - bucket = builder.bucket; - name = builder.name; + blobId = builder.blobId; id = builder.id; cacheControl = builder.cacheControl; contentEncoding = builder.contentEncoding; @@ -251,8 +242,12 @@ private BlobInfo(Builder builder) { updateTime = builder.updateTime; } + public BlobId blobId() { + return blobId; + } + public String bucket() { - return bucket; + return blobId().bucket(); } public String id() { @@ -260,7 +255,7 @@ public String id() { } public String name() { - return name; + return blobId().name(); } public String cacheControl() { @@ -341,8 +336,7 @@ public Long updateTime() { public Builder toBuilder() { return new Builder() - .bucket(bucket) - .name(name) + .blobId(blobId) .id(id) .generation(generation) .cacheControl(cacheControl) @@ -378,7 +372,7 @@ public String toString() { @Override public int hashCode() { - return Objects.hash(bucket, name); + return Objects.hash(blobId); } @Override @@ -387,7 +381,7 @@ public boolean equals(Object obj) { } StorageObject toPb() { - StorageObject storageObject = new StorageObject(); + StorageObject storageObject = blobId.toPb(); if (acl != null) { storageObject.setAcl(Lists.transform(acl, new Function() { @Override @@ -408,7 +402,6 @@ public ObjectAccessControl apply(Acl acl) { if (owner != null) { storageObject.setOwner(new Owner().setEntity(owner.toPb())); } - storageObject.setBucket(bucket); storageObject.setCacheControl(cacheControl); storageObject.setContentEncoding(contentEncoding); storageObject.setCrc32c(crc32c); @@ -418,7 +411,6 @@ public ObjectAccessControl apply(Acl acl) { storageObject.setMediaLink(mediaLink); storageObject.setMetadata(metadata); storageObject.setMetageneration(metageneration); - storageObject.setName(name); storageObject.setContentDisposition(contentDisposition); storageObject.setComponentCount(componentCount); storageObject.setContentLanguage(contentLanguage); @@ -428,20 +420,20 @@ public ObjectAccessControl apply(Acl acl) { return storageObject; } - public static BlobInfo of(String bucket, String name) { - return builder(bucket, name).build(); - } - public static Builder builder(BucketInfo bucketInfo, String name) { return builder(bucketInfo.name(), name); } public static Builder builder(String bucket, String name) { - return new Builder().bucket(bucket).name(name); + return new Builder().blobId(BlobId.of(bucket, name)); + } + + public static Builder builder(BlobId blobId) { + return new Builder().blobId(blobId); } static BlobInfo fromPb(StorageObject storageObject) { - Builder builder = new Builder().bucket(storageObject.getBucket()).name(storageObject.getName()); + Builder builder = builder(BlobId.fromPb(storageObject)); if (storageObject.getCacheControl() != null) { builder.cacheControl(storageObject.getCacheControl()); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java index 7561775c81b9..79fe2fd1e531 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannelImpl.java @@ -38,7 +38,7 @@ class BlobReadChannelImpl implements BlobReadChannel { private static final long serialVersionUID = 4821762590742862669L; private final StorageOptions serviceOptions; - private final BlobInfo blobInfo; + private final BlobId blob; private final Map requestOptions; private int position; private boolean isOpen; @@ -50,10 +50,10 @@ class BlobReadChannelImpl implements BlobReadChannel { private transient int bufferPos; private transient byte[] buffer; - BlobReadChannelImpl(StorageOptions serviceOptions, BlobInfo blobInfo, + BlobReadChannelImpl(StorageOptions serviceOptions, BlobId blob, Map requestOptions) { this.serviceOptions = serviceOptions; - this.blobInfo = blobInfo; + this.blob = blob; this.requestOptions = requestOptions; isOpen = true; initTransients(); @@ -76,7 +76,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE private void initTransients() { storageRpc = serviceOptions.storageRpc(); - storageObject = blobInfo.toPb(); + storageObject = blob.toPb(); } @Override diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java index 95cc5f262e03..8da06ec12fea 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java @@ -141,7 +141,7 @@ public ListResult list(Storage.BlobListOption... options) { * @throws StorageException upon failure */ public Blob get(String blob, BlobSourceOption... options) { - return new Blob(storage, storage.get(info.name(), blob, options)); + return new Blob(storage, storage.get(BlobId.of(info.name(), blob), options)); } /** @@ -179,8 +179,8 @@ public List get(String blobName1, String blobName2, String... blobNames) { * @throws StorageException upon failure */ Blob create(String blob, byte[] content, BlobTargetOption... options) { - BlobInfo blobInfo = BlobInfo.of(info.name(), blob); - return new Blob(storage, storage.create(blobInfo, content, options)); + BlobId blobId = BlobId.of(info.name(), blob); + return new Blob(storage, storage.create(BlobInfo.builder(blobId).build(), content, options)); } /** diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java index a475f22309c6..7f36352b9bf3 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java @@ -379,7 +379,7 @@ public static ComposeRequest of(Iterable sources, BlobInfo target) { } public static ComposeRequest of(String bucket, Iterable sources, String target) { - return of(sources, BlobInfo.of(bucket, target)); + return of(sources, BlobInfo.builder(BlobId.of(bucket, target)).build()); } public static Builder builder() { @@ -391,8 +391,7 @@ class CopyRequest implements Serializable { private static final long serialVersionUID = -2606508373751748775L; - private final String sourceBucket; - private final String sourceBlob; + private final BlobId source; private final List sourceOptions; private final BlobInfo target; private final List targetOptions; @@ -401,13 +400,16 @@ public static class Builder { private final Set sourceOptions = new LinkedHashSet<>(); private final Set targetOptions = new LinkedHashSet<>(); - private String sourceBucket; - private String sourceBlob; + private BlobId source; private BlobInfo target; public Builder source(String bucket, String blob) { - this.sourceBucket = bucket; - this.sourceBlob = blob; + this.source = BlobId.of(bucket, blob); + return this; + } + + public Builder source(BlobId source) { + this.source = source; return this; } @@ -437,27 +439,21 @@ public Builder targetOptions(Iterable options) { } public CopyRequest build() { - checkNotNull(sourceBucket); - checkNotNull(sourceBlob); + checkNotNull(source); checkNotNull(target); return new CopyRequest(this); } } private CopyRequest(Builder builder) { - sourceBucket = checkNotNull(builder.sourceBucket); - sourceBlob = checkNotNull(builder.sourceBlob); + source = checkNotNull(builder.source); sourceOptions = ImmutableList.copyOf(builder.sourceOptions); target = checkNotNull(builder.target); targetOptions = ImmutableList.copyOf(builder.targetOptions); } - public String sourceBucket() { - return sourceBucket; - } - - public String sourceBlob() { - return sourceBlob; + public BlobId source() { + return source; } public List sourceOptions() { @@ -476,8 +472,18 @@ public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo ta return builder().source(sourceBucket, sourceBlob).target(target).build(); } + public static CopyRequest of(BlobId sourceBlobId, BlobInfo target) { + return builder().source(sourceBlobId).target(target).build(); + } + public static CopyRequest of(String sourceBucket, String sourceBlob, String targetBlob) { - return of(sourceBucket, sourceBlob, BlobInfo.of(sourceBucket, targetBlob)); + return of(sourceBucket, sourceBlob, + BlobInfo.builder(BlobId.of(sourceBucket, targetBlob)).build()); + } + + public static CopyRequest of(BlobId sourceBlobId, String targetBlob) { + return of(sourceBlobId, + BlobInfo.builder(BlobId.of(sourceBlobId.bucket(), targetBlob)).build()); } public static Builder builder() { @@ -533,6 +539,20 @@ public static Builder builder() { */ BlobInfo get(String bucket, String blob, BlobSourceOption... options); + /** + * Return the requested blob or {@code null} if not found. + * + * @throws StorageException upon failure + */ + BlobInfo get(BlobId blob, BlobSourceOption... options); + + /** + * Return the requested blob or {@code null} if not found. + * + * @throws StorageException upon failure + */ + BlobInfo get(BlobId blob); + /** * List the project's buckets. * @@ -587,6 +607,14 @@ public static Builder builder() { */ boolean delete(String bucket, String blob, BlobSourceOption... options); + /** + * Delete the requested blob. + * + * @return true if blob was deleted + * @throws StorageException upon failure + */ + boolean delete(BlobId blob, BlobSourceOption... options); + /** * Send a compose request. * @@ -611,6 +639,14 @@ public static Builder builder() { */ byte[] readAllBytes(String bucket, String blob, BlobSourceOption... options); + /** + * Reads all the bytes from a blob. + * + * @return the blob's content. + * @throws StorageException upon failure + */ + byte[] readAllBytes(BlobId blob, BlobSourceOption... options); + /** * Send a batch request. * @@ -626,6 +662,13 @@ public static Builder builder() { */ BlobReadChannel reader(String bucket, String blob, BlobSourceOption... options); + /** + * Return a channel for reading the blob's content. + * + * @throws StorageException upon failure + */ + BlobReadChannel reader(BlobId blob, BlobSourceOption... options); + /** * Create a blob and return a channel for writing its content. * @@ -656,12 +699,12 @@ public static Builder builder() { /** * Gets the requested blobs. A batch request is used to perform this call. * - * @param blobInfos blobs to get + * @param blobIds blobs to get * @return an immutable list of {@code BlobInfo} objects. If a blob does not exist or access to it * has been denied the corresponding item in the list is {@code null}. * @throws StorageException upon failure */ - List get(BlobInfo... blobInfos); + List get(BlobId... blobIds); /** * Updates the requested blobs. A batch request is used to perform this call. @@ -676,11 +719,11 @@ public static Builder builder() { /** * Deletes the requested blobs. A batch request is used to perform this call. * - * @param blobInfos blobs to delete + * @param blobIds blobs to delete * @return an immutable list of booleans. If a blob has been deleted the corresponding item in the * list is {@code true}. If deletion failed or access to the resource was denied the item is * {@code false}. * @throws StorageException upon failure */ - List delete(BlobInfo... blobInfos); + List delete(BlobId... blobIds); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java index 6e32220746ca..2e926be27fae 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java @@ -176,7 +176,12 @@ public com.google.api.services.storage.model.Bucket call() { @Override public BlobInfo get(String bucket, String blob, BlobSourceOption... options) { - final StorageObject storedObject = BlobInfo.of(bucket, blob).toPb(); + return get(BlobId.of(bucket, blob), options); + } + + @Override + public BlobInfo get(BlobId blob, BlobSourceOption... options) { + final StorageObject storedObject = blob.toPb(); final Map optionsMap = optionMap(options); try { StorageObject storageObject = runWithRetries(new Callable() { @@ -198,6 +203,11 @@ public StorageObject call() { } } + @Override + public BlobInfo get(BlobId blob) { + return get(blob, new BlobSourceOption[0]); + } + private static abstract class BasePageFetcher implements BaseListResult.NextPageFetcher { @@ -372,7 +382,12 @@ public Boolean call() { @Override public boolean delete(String bucket, String blob, BlobSourceOption... options) { - final StorageObject storageObject = BlobInfo.of(bucket, blob).toPb(); + return delete(BlobId.of(bucket, blob), options); + } + + @Override + public boolean delete(BlobId blob, BlobSourceOption... options) { + final StorageObject storageObject = blob.toPb(); final Map optionsMap = optionMap(options); try { return runWithRetries(new Callable() { @@ -411,8 +426,7 @@ public StorageObject call() { @Override public BlobInfo copy(CopyRequest copyRequest) { - final StorageObject source = - BlobInfo.of(copyRequest.sourceBucket(), copyRequest.sourceBlob()).toPb(); + final StorageObject source = copyRequest.source().toPb(); copyRequest.sourceOptions(); final Map sourceOptions = optionMap(null, null, copyRequest.sourceOptions(), true); @@ -433,7 +447,12 @@ public StorageObject call() { @Override public byte[] readAllBytes(String bucket, String blob, BlobSourceOption... options) { - final StorageObject storageObject = BlobInfo.of(bucket, blob).toPb(); + return readAllBytes(BlobId.of(bucket, blob), options); + } + + @Override + public byte[] readAllBytes(BlobId blob, BlobSourceOption... options) { + final StorageObject storageObject = blob.toPb(); final Map optionsMap = optionMap(options); try { return runWithRetries(new Callable() { @@ -451,11 +470,10 @@ public byte[] call() { public BatchResponse apply(BatchRequest batchRequest) { List>> toDelete = Lists.newArrayListWithCapacity(batchRequest.toDelete().size()); - for (Map.Entry> entry : batchRequest.toDelete().entrySet()) { - BlobInfo blobInfo = entry.getKey(); - Map optionsMap = - optionMap(blobInfo.generation(), blobInfo.metageneration(), entry.getValue()); - StorageObject storageObject = blobInfo.toPb(); + for (Map.Entry> entry : batchRequest.toDelete().entrySet()) { + BlobId blob = entry.getKey(); + Map optionsMap = optionMap(null, null, entry.getValue()); + StorageObject storageObject = blob.toPb(); toDelete.add(Tuple.>of(storageObject, optionsMap)); } List>> toUpdate = @@ -468,11 +486,10 @@ public BatchResponse apply(BatchRequest batchRequest) { } List>> toGet = Lists.newArrayListWithCapacity(batchRequest.toGet().size()); - for (Map.Entry> entry : batchRequest.toGet().entrySet()) { - BlobInfo blobInfo = entry.getKey(); - Map optionsMap = - optionMap(blobInfo.generation(), blobInfo.metageneration(), entry.getValue()); - toGet.add(Tuple.>of(blobInfo.toPb(), optionsMap)); + for (Map.Entry> entry : batchRequest.toGet().entrySet()) { + BlobId blob = entry.getKey(); + Map optionsMap = optionMap(null, null, entry.getValue()); + toGet.add(Tuple.>of(blob.toPb(), optionsMap)); } StorageRpc.BatchResponse response = storageRpc.batch(new StorageRpc.BatchRequest(toDelete, toUpdate, toGet)); @@ -511,7 +528,13 @@ private List> transformBatch @Override public BlobReadChannel reader(String bucket, String blob, BlobSourceOption... options) { Map optionsMap = optionMap(options); - return new BlobReadChannelImpl(options(), BlobInfo.of(bucket, blob), optionsMap); + return new BlobReadChannelImpl(options(), BlobId.of(bucket, blob), optionsMap); + } + + @Override + public BlobReadChannel reader(BlobId blob, BlobSourceOption... options) { + Map optionsMap = optionMap(options); + return new BlobReadChannelImpl(options(), blob, optionsMap); } @Override @@ -584,10 +607,10 @@ public URL signUrl(BlobInfo blobInfo, long expiration, SignUrlOption... options) } @Override - public List get(BlobInfo... blobInfos) { + public List get(BlobId... blobIds) { BatchRequest.Builder requestBuilder = BatchRequest.builder(); - for (BlobInfo blobInfo : blobInfos) { - requestBuilder.get(blobInfo.bucket(), blobInfo.name()); + for (BlobId blob : blobIds) { + requestBuilder.get(blob); } BatchResponse response = apply(requestBuilder.build()); return Collections.unmodifiableList(transformResultList(response.gets(), null)); @@ -604,10 +627,10 @@ public List update(BlobInfo... blobInfos) { } @Override - public List delete(BlobInfo... blobInfos) { + public List delete(BlobId... blobIds) { BatchRequest.Builder requestBuilder = BatchRequest.builder(); - for (BlobInfo blobInfo : blobInfos) { - requestBuilder.delete(blobInfo.bucket(), blobInfo.name()); + for (BlobId blob : blobIds) { + requestBuilder.delete(blob); } BatchResponse response = apply(requestBuilder.build()); return Collections.unmodifiableList(transformResultList(response.deletes(), Boolean.FALSE)); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java index 9cafd64afaa8..96b73c871468 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java @@ -38,47 +38,47 @@ public void testBatchRequest() { .delete("b1", "o1") .delete("b1", "o2", BlobSourceOption.generationMatch(1), BlobSourceOption.metagenerationMatch(2)) - .update(BlobInfo.of("b2", "o1"), BlobTargetOption.predefinedAcl(PUBLIC_READ)) - .update(BlobInfo.of("b2", "o2")) + .update(BlobInfo.builder("b2", "o1").build(), BlobTargetOption.predefinedAcl(PUBLIC_READ)) + .update(BlobInfo.builder("b2", "o2").build()) .get("b3", "o1") .get("b3", "o2", BlobSourceOption.generationMatch(1)) .get("b3", "o3") .build(); - Iterator>> deletes = request + Iterator>> deletes = request .toDelete().entrySet().iterator(); - Entry> delete = deletes.next(); - assertEquals(BlobInfo.of("b1", "o1"), delete.getKey()); + Entry> delete = deletes.next(); + assertEquals(BlobId.of("b1", "o1"), delete.getKey()); assertTrue(Iterables.isEmpty(delete.getValue())); delete = deletes.next(); - assertEquals(BlobInfo.of("b1", "o2"), delete.getKey()); + assertEquals(BlobId.of("b1", "o2"), delete.getKey()); assertEquals(2, Iterables.size(delete.getValue())); assertFalse(deletes.hasNext()); Iterator>> updates = request .toUpdate().entrySet().iterator(); Entry> update = updates.next(); - assertEquals(BlobInfo.of("b2", "o1"), update.getKey()); + assertEquals(BlobInfo.builder("b2", "o1").build(), update.getKey()); assertEquals(1, Iterables.size(update.getValue())); assertEquals(BlobTargetOption.predefinedAcl(PUBLIC_READ), Iterables.getFirst(update.getValue(), null)); update = updates.next(); - assertEquals(BlobInfo.of("b2", "o2"), update.getKey()); + assertEquals(BlobInfo.builder("b2", "o2").build(), update.getKey()); assertTrue(Iterables.isEmpty(update.getValue())); assertFalse(updates.hasNext()); - Iterator>> gets = request + Iterator>> gets = request .toGet().entrySet().iterator(); - Entry> get = gets.next(); - assertEquals(BlobInfo.of("b3", "o1"), get.getKey()); + Entry> get = gets.next(); + assertEquals(BlobId.of("b3", "o1"), get.getKey()); assertTrue(Iterables.isEmpty(get.getValue())); get = gets.next(); - assertEquals(BlobInfo.of("b3", "o2"), get.getKey()); + assertEquals(BlobId.of("b3", "o2"), get.getKey()); assertEquals(1, Iterables.size(get.getValue())); assertEquals(BlobSourceOption.generationMatch(1), Iterables.getFirst(get.getValue(), null)); get = gets.next(); - assertEquals(BlobInfo.of("b3", "o3"), get.getKey()); + assertEquals(BlobId.of("b3", "o3"), get.getKey()); assertTrue(Iterables.isEmpty(get.getValue())); assertFalse(gets.hasNext()); } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java index 7e774a77c739..59c1da91b3fd 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java @@ -27,9 +27,9 @@ public class BatchResponseTest { - private static final BlobInfo BLOB_INFO_1 = BlobInfo.of("b", "o1"); - private static final BlobInfo BLOB_INFO_2 = BlobInfo.of("b", "o2"); - private static final BlobInfo BLOB_INFO_3 = BlobInfo.of("b", "o3"); + private static final BlobInfo BLOB_INFO_1 = BlobInfo.builder("b", "o1").build(); + private static final BlobInfo BLOB_INFO_2 = BlobInfo.builder("b", "o2").build(); + private static final BlobInfo BLOB_INFO_3 = BlobInfo.builder("b", "o3").build(); @Test public void testBatchResponse() { diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobIdTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobIdTest.java new file mode 100644 index 000000000000..acc1885b9194 --- /dev/null +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobIdTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud.storage; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class BlobIdTest { + + private static final BlobId BLOB = BlobId.of("b", "n"); + + @Test + public void testOf() { + BlobId blobId = BlobId.of("b", "n"); + assertEquals("b", blobId.bucket()); + assertEquals("n", blobId.name()); + } + + @Test + public void testEquals() { + compareBlobIds(BLOB, BlobId.of("b", "n")); + } + + private void compareBlobIds(BlobId expected, BlobId value) { + assertEquals(expected, value); + assertEquals(expected.bucket(), value.bucket()); + assertEquals(expected.name(), value.name()); + assertEquals(expected.hashCode(), value.hashCode()); + } + + @Test + public void testToPbAndFromPb() { + compareBlobIds(BLOB, BlobId.fromPb(BLOB.toPb())); + } +} diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java index bd5ac476c318..70560b0c9a9e 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java @@ -81,21 +81,14 @@ public class BlobInfoTest { @Test public void testToBuilder() { compareBlobs(BLOB_INFO, BLOB_INFO.toBuilder().build()); - BlobInfo blobInfo = BLOB_INFO.toBuilder().name("n2").bucket("b2").size(200L).build(); + BlobInfo blobInfo = BLOB_INFO.toBuilder().blobId(BlobId.of("b2", "n2")).size(200L).build(); assertEquals("n2", blobInfo.name()); assertEquals("b2", blobInfo.bucket()); assertEquals(Long.valueOf(200), blobInfo.size()); - blobInfo = blobInfo.toBuilder().name("n").bucket("b").size(SIZE).build(); + blobInfo = blobInfo.toBuilder().blobId(BlobId.of("b", "n")).size(SIZE).build(); compareBlobs(BLOB_INFO, blobInfo); } - @Test - public void testOf() { - BlobInfo blobInfo = BlobInfo.of("b", "n"); - assertEquals("b", blobInfo.bucket()); - assertEquals("n", blobInfo.name()); - } - @Test public void testBuilder() { assertEquals("b", BLOB_INFO.bucket()); @@ -103,7 +96,7 @@ public void testBuilder() { assertEquals(ACL, BLOB_INFO.acl()); assertEquals(COMPONENT_COUNT, BLOB_INFO.componentCount()); assertEquals(CONTENT_TYPE, BLOB_INFO.contentType()); - assertEquals(CACHE_CONTROL, BLOB_INFO.cacheControl() ); + assertEquals(CACHE_CONTROL, BLOB_INFO.cacheControl()); assertEquals(CONTENT_DISPOSITION, BLOB_INFO.contentDisposition()); assertEquals(CONTENT_ENCODING, BLOB_INFO.contentEncoding()); assertEquals(CONTENT_LANGUAGE, BLOB_INFO.contentLanguage()); @@ -129,7 +122,7 @@ private void compareBlobs(BlobInfo expected, BlobInfo value) { assertEquals(expected.acl(), value.acl()); assertEquals(expected.componentCount(), value.componentCount()); assertEquals(expected.contentType(), value.contentType()); - assertEquals(expected.cacheControl(), value.cacheControl() ); + assertEquals(expected.cacheControl(), value.cacheControl()); assertEquals(expected.contentDisposition(), value.contentDisposition()); assertEquals(expected.contentEncoding(), value.contentEncoding()); assertEquals(expected.contentLanguage(), value.contentLanguage()); @@ -151,7 +144,12 @@ private void compareBlobs(BlobInfo expected, BlobInfo value) { @Test public void testToPbAndFromPb() { compareBlobs(BLOB_INFO, BlobInfo.fromPb(BLOB_INFO.toPb())); - BlobInfo blobInfo = BlobInfo.of("b", "n"); + BlobInfo blobInfo = BlobInfo.builder(BlobId.of("b", "n")).build(); compareBlobs(blobInfo, BlobInfo.fromPb(blobInfo.toPb())); } + + @Test + public void testBlobId() { + assertEquals(BlobId.of("b", "n"), BLOB_INFO.blobId()); + } } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java index 9cbe5b3fea5a..117e2b692c6b 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java @@ -32,12 +32,12 @@ public class BlobListResultTest { private static final Iterable FIRST_PAGE_RESULTS = ImmutableList.of( - BlobInfo.of("b1", "n1"), - BlobInfo.of("b2", "n2")); + BlobInfo.builder("b1", "n1").build(), + BlobInfo.builder("b2", "n2").build()); private static final Iterable SECOND_PAGE_RESULTS = ImmutableList.of( - BlobInfo.of("b1", "n1"), - BlobInfo.of("b2", "n2")); + BlobInfo.builder("b1", "n1").build(), + BlobInfo.builder("b2", "n2").build()); private BaseListResult firstPage; private BaseListResult secondPage; diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobReadChannelImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobReadChannelImplTest.java index 2a43753e6178..c5c9a0e48612 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobReadChannelImplTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobReadChannelImplTest.java @@ -41,7 +41,7 @@ public class BlobReadChannelImplTest { private static final String BUCKET_NAME = "b"; private static final String BLOB_NAME = "n"; - private static final BlobInfo BLOB_INFO = BlobInfo.of(BUCKET_NAME, BLOB_NAME); + private static final BlobId BLOB_ID = BlobId.of(BUCKET_NAME, BLOB_NAME); private static final Map EMPTY_RPC_OPTIONS = ImmutableMap.of(); private static final int DEFAULT_CHUNK_SIZE = 2 * 1024 * 1024; private static final int CUSTOM_CHUNK_SIZE = 2 * 1024 * 1024; @@ -68,7 +68,7 @@ public void testCreate() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.replay(optionsMock); EasyMock.replay(storageRpcMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); assertTrue(reader.isOpen()); } @@ -77,12 +77,12 @@ public void testReadBuffered() throws IOException { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.replay(optionsMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); byte[] result = randomByteArray(DEFAULT_CHUNK_SIZE); ByteBuffer firstReadBuffer = ByteBuffer.allocate(42); ByteBuffer secondReadBuffer = ByteBuffer.allocate(42); EasyMock - .expect(storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) + .expect(storageRpcMock.read(BLOB_ID.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) .andReturn(result); EasyMock.replay(storageRpcMock); reader.read(firstReadBuffer); @@ -99,18 +99,18 @@ public void testReadBig() throws IOException { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()).times(2); EasyMock.replay(optionsMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); reader.chunkSize(CUSTOM_CHUNK_SIZE); byte[] firstResult = randomByteArray(DEFAULT_CHUNK_SIZE); byte[] secondResult = randomByteArray(DEFAULT_CHUNK_SIZE); ByteBuffer firstReadBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE); ByteBuffer secondReadBuffer = ByteBuffer.allocate(42); EasyMock - .expect(storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) + .expect(storageRpcMock.read(BLOB_ID.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) .andReturn(firstResult); EasyMock .expect( - storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, DEFAULT_CHUNK_SIZE, + storageRpcMock.read(BLOB_ID.toPb(), EMPTY_RPC_OPTIONS, DEFAULT_CHUNK_SIZE, CUSTOM_CHUNK_SIZE)) .andReturn(secondResult); EasyMock.replay(storageRpcMock); @@ -126,11 +126,11 @@ public void testReadFinish() throws IOException { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.replay(optionsMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); byte[] result = {}; ByteBuffer readBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE); EasyMock - .expect(storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) + .expect(storageRpcMock.read(BLOB_ID.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) .andReturn(result); EasyMock.replay(storageRpcMock); assertEquals(-1, reader.read(readBuffer)); @@ -141,12 +141,12 @@ public void testSeek() throws IOException { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.replay(optionsMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); reader.seek(42); byte[] result = randomByteArray(DEFAULT_CHUNK_SIZE); ByteBuffer readBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE); EasyMock - .expect(storageRpcMock.read(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS, 42, DEFAULT_CHUNK_SIZE)) + .expect(storageRpcMock.read(BLOB_ID.toPb(), EMPTY_RPC_OPTIONS, 42, DEFAULT_CHUNK_SIZE)) .andReturn(result); EasyMock.replay(storageRpcMock); reader.read(readBuffer); @@ -158,7 +158,7 @@ public void testClose() throws IOException { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.replay(optionsMock); EasyMock.replay(storageRpcMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); assertTrue(reader.isOpen()); reader.close(); assertTrue(!reader.isOpen()); @@ -169,7 +169,7 @@ public void testReadClosed() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.replay(optionsMock); EasyMock.replay(storageRpcMock); - reader = new BlobReadChannelImpl(optionsMock, BLOB_INFO, EMPTY_RPC_OPTIONS); + reader = new BlobReadChannelImpl(optionsMock, BLOB_ID, EMPTY_RPC_OPTIONS); reader.close(); try { ByteBuffer readBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java index ece24eeacd1e..4288ae1a71be 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java @@ -41,9 +41,11 @@ public class BlobTest { - private static final BlobInfo BLOB_INFO = BlobInfo.of("b", "n"); - private static final BlobInfo[] BLOB_INFO_ARRAY = {BlobInfo.of("b1", "n1"), - BlobInfo.of("b2", "n2"), BlobInfo.of("b3", "n3")}; + private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n").build(); + private static final BlobId[] BLOB_ID_ARRAY = {BlobId.of("b1", "n1"), + BlobId.of("b2", "n2"), BlobId.of("b3", "n3")}; + private static final BlobInfo[] BLOB_INFO_ARRAY = {BlobInfo.builder("b1", "n1").build(), + BlobInfo.builder("b2", "n2").build(), BlobInfo.builder("b3", "n3").build()}; private Storage storage; private Blob blob; @@ -116,28 +118,26 @@ public void testDelete() throws Exception { @Test public void testCopyToBucket() throws Exception { - BlobInfo target = BLOB_INFO.toBuilder().bucket("bt").build(); + BlobInfo target = BLOB_INFO.toBuilder().blobId(BlobId.of("bt", "n")).build(); Capture capturedCopyRequest = Capture.newInstance(); expect(storage.copy(capture(capturedCopyRequest))).andReturn(target); replay(storage); Blob targetBlob = blob.copyTo("bt"); assertEquals(target, targetBlob.info()); - assertEquals(capturedCopyRequest.getValue().sourceBlob(), blob.info().name()); - assertEquals(capturedCopyRequest.getValue().sourceBucket(), blob.info().bucket()); + assertEquals(capturedCopyRequest.getValue().source(), blob.id()); assertEquals(capturedCopyRequest.getValue().target(), target); assertSame(storage, targetBlob.storage()); } @Test public void testCopyTo() throws Exception { - BlobInfo target = BLOB_INFO.toBuilder().bucket("bt").name("nt").build(); + BlobInfo target = BLOB_INFO.toBuilder().blobId(BlobId.of("bt", "nt")).build(); Capture capturedCopyRequest = Capture.newInstance(); expect(storage.copy(capture(capturedCopyRequest))).andReturn(target); replay(storage); Blob targetBlob = blob.copyTo("bt", "nt"); assertEquals(target, targetBlob.info()); - assertEquals(capturedCopyRequest.getValue().sourceBlob(), blob.info().name()); - assertEquals(capturedCopyRequest.getValue().sourceBucket(), blob.info().bucket()); + assertEquals(capturedCopyRequest.getValue().source(), blob.id()); assertEquals(capturedCopyRequest.getValue().target(), target); assertSame(storage, targetBlob.storage()); } @@ -175,9 +175,9 @@ public void testGetNone() throws Exception { @Test public void testGetSome() throws Exception { List blobInfoList = Arrays.asList(BLOB_INFO_ARRAY); - expect(storage.get(BLOB_INFO_ARRAY)).andReturn(blobInfoList); + expect(storage.get(BLOB_ID_ARRAY)).andReturn(blobInfoList); replay(storage); - List result = Blob.get(storage, BLOB_INFO_ARRAY); + List result = Blob.get(storage, BLOB_ID_ARRAY); assertEquals(blobInfoList.size(), result.size()); for (int i = 0; i < blobInfoList.size(); i++) { assertEquals(blobInfoList.get(i), result.get(i).info()); @@ -187,9 +187,9 @@ public void testGetSome() throws Exception { @Test public void testGetSomeNull() throws Exception { List blobInfoList = Arrays.asList(BLOB_INFO_ARRAY[0], null, BLOB_INFO_ARRAY[2]); - expect(storage.get(BLOB_INFO_ARRAY)).andReturn(blobInfoList); + expect(storage.get(BLOB_ID_ARRAY)).andReturn(blobInfoList); replay(storage); - List result = Blob.get(storage, BLOB_INFO_ARRAY); + List result = Blob.get(storage, BLOB_ID_ARRAY); assertEquals(blobInfoList.size(), result.size()); for (int i = 0; i < blobInfoList.size(); i++) { if (blobInfoList.get(i) != null) { @@ -208,7 +208,7 @@ public void testUpdateNone() throws Exception { @Test public void testUpdateSome() throws Exception { - List blobInfoList = Lists.newArrayListWithCapacity(BLOB_INFO_ARRAY.length); + List blobInfoList = Lists.newArrayListWithCapacity(BLOB_ID_ARRAY.length); for (BlobInfo info : BLOB_INFO_ARRAY) { blobInfoList.add(info.toBuilder().contentType("content").build()); } @@ -248,9 +248,9 @@ public void testDeleteNone() throws Exception { @Test public void testDeleteSome() throws Exception { List deleleResultList = Arrays.asList(true, true, true); - expect(storage.delete(BLOB_INFO_ARRAY)).andReturn(deleleResultList); + expect(storage.delete(BLOB_ID_ARRAY)).andReturn(deleleResultList); replay(storage); - List result = Blob.delete(storage, BLOB_INFO_ARRAY); + List result = Blob.delete(storage, BLOB_ID_ARRAY); assertEquals(deleleResultList.size(), result.size()); for (int i = 0; i < deleleResultList.size(); i++) { assertEquals(deleleResultList.get(i), result.get(i)); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java index cc43f8f6e1f7..54135cc9990d 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java @@ -43,7 +43,7 @@ public class BlobWriteChannelImplTest { private static final String BUCKET_NAME = "b"; private static final String BLOB_NAME = "n"; private static final String UPLOAD_ID = "uploadid"; - private static final BlobInfo BLOB_INFO = BlobInfo.of(BUCKET_NAME, BLOB_NAME); + private static final BlobInfo BLOB_INFO = BlobInfo.builder(BUCKET_NAME, BLOB_NAME).build(); private static final Map EMPTY_RPC_OPTIONS = ImmutableMap.of(); private static final int MIN_CHUNK_SIZE = 256 * 1024; private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE; diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java index 5fddc23691d6..d0b5d502a8da 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java @@ -42,9 +42,9 @@ public class BucketTest { private static final BucketInfo BUCKET_INFO = BucketInfo.of("b"); private static final Iterable BLOB_INFO_RESULTS = ImmutableList.of( - BlobInfo.of("b", "n1"), - BlobInfo.of("b", "n2"), - BlobInfo.of("b", "n3")); + BlobInfo.builder("b", "n1").build(), + BlobInfo.builder("b", "n2").build(), + BlobInfo.builder("b", "n3").build()); private Storage storage; private Bucket bucket; @@ -125,8 +125,9 @@ public void testList() throws Exception { @Test public void testGet() throws Exception { - BlobInfo info = BlobInfo.of("b", "n"); - expect(storage.get(BUCKET_INFO.name(), "n")).andReturn(info); + BlobInfo info = BlobInfo.builder("b", "n").build(); + expect(storage.get(BlobId.of(bucket.info().name(), "n"), new Storage.BlobSourceOption[0])) + .andReturn(info); replay(storage); Blob blob = bucket.get("n"); assertEquals(info, blob.info()); @@ -144,10 +145,10 @@ public void testGetAll() throws Exception { expect(storage.apply(capture(capturedBatchRequest))).andReturn(response); replay(storage); List blobs = bucket.get("n1", "n2", "n3"); - Set blobInfoSet = capturedBatchRequest.getValue().toGet().keySet(); + Set blobInfoSet = capturedBatchRequest.getValue().toGet().keySet(); assertEquals(batchResultList.size(), blobInfoSet.size()); for (BlobInfo info : BLOB_INFO_RESULTS) { - assertTrue(blobInfoSet.contains(info)); + assertTrue(blobInfoSet.contains(info.blobId())); } Iterator blobIterator = blobs.iterator(); Iterator> batchResultIterator = response.gets().iterator(); @@ -160,7 +161,7 @@ public void testGetAll() throws Exception { @Test public void testCreate() throws Exception { - BlobInfo info = BlobInfo.of("b", "n"); + BlobInfo info = BlobInfo.builder("b", "n").build(); byte[] content = {0xD, 0xE, 0xA, 0xD}; expect(storage.create(info, content)).andReturn(info); replay(storage); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java index 2ca36c8ec1e3..3846ef9ada42 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java @@ -92,7 +92,7 @@ public void testListBuckets() throws InterruptedException { @Test public void testCreateBlob() { String blobName = "test-create-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); BlobInfo remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT); assertNotNull(remoteBlob); assertEquals(blob.bucket(), remoteBlob.bucket()); @@ -105,7 +105,7 @@ public void testCreateBlob() { @Test public void testCreateEmptyBlob() { String blobName = "test-create-empty-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); BlobInfo remoteBlob = storage.create(blob); assertNotNull(remoteBlob); assertEquals(blob.bucket(), remoteBlob.bucket()); @@ -133,7 +133,7 @@ public void testCreateBlobStream() throws UnsupportedEncodingException { @Test public void testCreateBlobFail() { String blobName = "test-create-blob-fail"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); assertNotNull(storage.create(blob)); try { storage.create(blob.toBuilder().generation(-1L).build(), BLOB_BYTE_CONTENT, @@ -148,7 +148,7 @@ public void testCreateBlobFail() { @Test public void testUpdateBlob() { String blobName = "test-update-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); assertNotNull(storage.create(blob)); BlobInfo updatedBlob = storage.update(blob.toBuilder().contentType(CONTENT_TYPE).build()); assertNotNull(updatedBlob); @@ -161,7 +161,7 @@ public void testUpdateBlob() { @Test public void testUpdateBlobFail() { String blobName = "test-update-blob-fail"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); assertNotNull(storage.create(blob)); try { storage.update(blob.toBuilder().contentType(CONTENT_TYPE).generation(-1L).build(), @@ -176,14 +176,13 @@ public void testUpdateBlobFail() { @Test public void testDeleteNonExistingBlob() { String blobName = "test-delete-non-existing-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); - assertTrue(!storage.delete(bucket, blob.name())); + assertTrue(!storage.delete(bucket, blobName)); } @Test public void testDeleteBlobFail() { String blobName = "test-delete-blob-fail"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); assertNotNull(storage.create(blob)); try { storage.delete(bucket, blob.name(), Storage.BlobSourceOption.generationMatch(-1L)); @@ -198,12 +197,12 @@ public void testDeleteBlobFail() { public void testComposeBlob() { String sourceBlobName1 = "test-compose-blob-source-1"; String sourceBlobName2 = "test-compose-blob-source-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1, BLOB_BYTE_CONTENT)); assertNotNull(storage.create(sourceBlob2, BLOB_BYTE_CONTENT)); String targetBlobName = "test-compose-blob-target"; - BlobInfo targetBlob = BlobInfo.of(bucket, targetBlobName); + BlobInfo targetBlob = BlobInfo.builder(bucket, targetBlobName).build(); Storage.ComposeRequest req = Storage.ComposeRequest.of(ImmutableList.of(sourceBlobName1, sourceBlobName2), targetBlob); BlobInfo remoteBlob = storage.compose(req); @@ -224,12 +223,12 @@ public void testComposeBlob() { public void testComposeBlobFail() { String sourceBlobName1 = "test-compose-blob-fail-source-1"; String sourceBlobName2 = "test-compose-blob-fail-source-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1)); assertNotNull(storage.create(sourceBlob2)); String targetBlobName = "test-compose-blob-fail-target"; - BlobInfo targetBlob = BlobInfo.of(bucket, targetBlobName); + BlobInfo targetBlob = BlobInfo.builder(bucket, targetBlobName).build(); Storage.ComposeRequest req = Storage.ComposeRequest.builder() .addSource(sourceBlobName1, -1L) .addSource(sourceBlobName2, -1L) @@ -248,10 +247,10 @@ public void testComposeBlobFail() { @Test public void testCopyBlob() { String sourceBlobName = "test-copy-blob-source"; - BlobInfo blob = BlobInfo.of(bucket, sourceBlobName); + BlobInfo blob = BlobInfo.builder(bucket, sourceBlobName).build(); assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT)); String targetBlobName = "test-copy-blob-target"; - Storage.CopyRequest req = Storage.CopyRequest.of(bucket, sourceBlobName, targetBlobName); + Storage.CopyRequest req = Storage.CopyRequest.of(blob.blobId(), targetBlobName); BlobInfo remoteBlob = storage.copy(req); assertNotNull(remoteBlob); assertEquals(bucket, remoteBlob.bucket()); @@ -265,7 +264,7 @@ public void testCopyBlob() { @Test public void testCopyBlobUpdateMetadata() { String sourceBlobName = "test-copy-blob-update-metadata-source"; - BlobInfo sourceBlob = BlobInfo.of(bucket, sourceBlobName); + BlobInfo sourceBlob = BlobInfo.builder(bucket, sourceBlobName).build(); assertNotNull(storage.create(sourceBlob)); String targetBlobName = "test-copy-blob-update-metadata-target"; BlobInfo targetBlob = @@ -283,7 +282,7 @@ public void testCopyBlobUpdateMetadata() { @Test public void testCopyBlobFail() { String sourceBlobName = "test-copy-blob-fail-source"; - BlobInfo blob = BlobInfo.of(bucket, sourceBlobName); + BlobInfo blob = BlobInfo.builder(bucket, sourceBlobName).build(); assertNotNull(storage.create(blob)); String targetBlobName = "test-copy-blob-fail-target"; Storage.CopyRequest req = new Storage.CopyRequest.Builder() @@ -304,8 +303,8 @@ public void testCopyBlobFail() { public void testBatchRequest() { String sourceBlobName1 = "test-batch-request-blob-1"; String sourceBlobName2 = "test-batch-request-blob-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1)); assertNotNull(storage.create(sourceBlob2)); @@ -359,7 +358,7 @@ public void testBatchRequest() { @Test public void testBatchRequestFail() { String blobName = "test-batch-request-blob-fail"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); assertNotNull(storage.create(blob)); BlobInfo updatedBlob = blob.toBuilder().generation(-1L).build(); BatchRequest batchRequest = BatchRequest.builder() @@ -380,7 +379,7 @@ public void testBatchRequestFail() { @Test public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOException { String blobName = "test-read-and-write-channels-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); byte[] stringBytes; try (BlobWriteChannel writer = storage.writer(blob)) { stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8); @@ -389,7 +388,7 @@ public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOEx } ByteBuffer readBytes; ByteBuffer readStringBytes; - try (BlobReadChannel reader = storage.reader(bucket, blobName)) { + try (BlobReadChannel reader = storage.reader(blob.blobId())) { readBytes = ByteBuffer.allocate(BLOB_BYTE_CONTENT.length); readStringBytes = ByteBuffer.allocate(stringBytes.length); reader.read(readBytes); @@ -403,10 +402,10 @@ public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOEx @Test public void testReadChannelFail() throws UnsupportedEncodingException, IOException { String blobName = "test-read-channel-blob-fail"; - BlobInfo blob = BlobInfo.of(bucket, blobName); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); assertNotNull(storage.create(blob)); try (BlobReadChannel reader = - storage.reader(bucket, blobName, Storage.BlobSourceOption.metagenerationMatch(-1L))) { + storage.reader(blob.blobId(), Storage.BlobSourceOption.metagenerationMatch(-1L))) { reader.read(ByteBuffer.allocate(42)); fail("StorageException was expected"); } catch (StorageException ex) { @@ -433,8 +432,8 @@ public void testWriteChannelFail() throws UnsupportedEncodingException, IOExcept @Test public void testGetSignedUrl() throws IOException { String blobName = "test-get-signed-url-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); - assertNotNull(storage.create(BlobInfo.of(bucket, blobName), BLOB_BYTE_CONTENT)); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); + assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT)); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, 1); long expiration = calendar.getTimeInMillis() / 1000; @@ -451,8 +450,8 @@ public void testGetSignedUrl() throws IOException { @Test public void testPostSignedUrl() throws IOException { String blobName = "test-post-signed-url-blob"; - BlobInfo blob = BlobInfo.of(bucket, blobName); - assertNotNull(storage.create(BlobInfo.of(bucket, blobName))); + BlobInfo blob = BlobInfo.builder(bucket, blobName).build(); + assertNotNull(storage.create(blob)); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, 1); long expiration = calendar.getTimeInMillis() / 1000; @@ -471,11 +470,11 @@ public void testPostSignedUrl() throws IOException { public void testGetBlobs() { String sourceBlobName1 = "test-get-blobs-1"; String sourceBlobName2 = "test-get-blobs-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1)); assertNotNull(storage.create(sourceBlob2)); - List remoteInfos = storage.get(sourceBlob1, sourceBlob2); + List remoteInfos = storage.get(sourceBlob1.blobId(), sourceBlob2.blobId()); assertEquals(sourceBlob1.bucket(), remoteInfos.get(0).bucket()); assertEquals(sourceBlob1.name(), remoteInfos.get(0).name()); assertEquals(sourceBlob2.bucket(), remoteInfos.get(1).bucket()); @@ -488,10 +487,10 @@ public void testGetBlobs() { public void testGetBlobsFail() { String sourceBlobName1 = "test-get-blobs-fail-1"; String sourceBlobName2 = "test-get-blobs-fail-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1)); - List remoteBlobs = storage.get(sourceBlob1, sourceBlob2); + List remoteBlobs = storage.get(sourceBlob1.blobId(), sourceBlob2.blobId()); assertEquals(sourceBlob1.bucket(), remoteBlobs.get(0).bucket()); assertEquals(sourceBlob1.name(), remoteBlobs.get(0).name()); assertNull(remoteBlobs.get(1)); @@ -502,11 +501,11 @@ public void testGetBlobsFail() { public void testDeleteBlobs() { String sourceBlobName1 = "test-delete-blobs-1"; String sourceBlobName2 = "test-delete-blobs-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1)); assertNotNull(storage.create(sourceBlob2)); - List deleteStatus = storage.delete(sourceBlob1, sourceBlob2); + List deleteStatus = storage.delete(sourceBlob1.blobId(), sourceBlob2.blobId()); assertTrue(deleteStatus.get(0)); assertTrue(deleteStatus.get(1)); } @@ -515,10 +514,10 @@ public void testDeleteBlobs() { public void testDeleteBlobsFail() { String sourceBlobName1 = "test-delete-blobs-fail-1"; String sourceBlobName2 = "test-delete-blobs-fail-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); assertNotNull(storage.create(sourceBlob1)); - List deleteStatus = storage.delete(sourceBlob1, sourceBlob2); + List deleteStatus = storage.delete(sourceBlob1.blobId(), sourceBlob2.blobId()); assertTrue(deleteStatus.get(0)); assertTrue(!deleteStatus.get(1)); } @@ -527,8 +526,8 @@ public void testDeleteBlobsFail() { public void testUpdateBlobs() { String sourceBlobName1 = "test-update-blobs-1"; String sourceBlobName2 = "test-update-blobs-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); BlobInfo remoteBlob1 = storage.create(sourceBlob1); BlobInfo remoteBlob2 = storage.create(sourceBlob2); assertNotNull(remoteBlob1); @@ -550,8 +549,8 @@ public void testUpdateBlobs() { public void testUpdateBlobsFail() { String sourceBlobName1 = "test-update-blobs-fail-1"; String sourceBlobName2 = "test-update-blobs-fail-2"; - BlobInfo sourceBlob1 = BlobInfo.of(bucket, sourceBlobName1); - BlobInfo sourceBlob2 = BlobInfo.of(bucket, sourceBlobName2); + BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build(); + BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build(); BlobInfo remoteBlob1 = storage.create(sourceBlob1); assertNotNull(remoteBlob1); List updatedBlobs = storage.update( diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java index cd02cfbd801d..2dd1b8cbf895 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java @@ -40,7 +40,7 @@ public class SerializationTest { private static final Acl.Project ACL_PROJECT_ = new Acl.Project(ProjectRole.VIEWERS, "pid"); private static final Acl.User ACL_USER = new Acl.User("user"); private static final Acl.RawEntity ACL_RAW = new Acl.RawEntity("raw"); - private static final BlobInfo BLOB_INFO = BlobInfo.of("b", "n"); + private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n").build(); private static final BucketInfo BUCKET_INFO = BucketInfo.of("b"); private static final Cors.Origin ORIGIN = Cors.Origin.any(); private static final Cors CORS = @@ -51,7 +51,7 @@ public class SerializationTest { Collections.>emptyList(), Collections.>emptyList()); private static final BaseListResult LIST_RESULT = - new BaseListResult<>(null, "c", Collections.singletonList(BlobInfo.of("b", "n"))); + new BaseListResult<>(null, "c", Collections.singletonList(BlobInfo.builder("b", "n").build())); private static final Storage.BlobListOption BLOB_LIST_OPTIONS = Storage.BlobListOption.maxResults(100); private static final Storage.BlobSourceOption BLOB_SOURCE_OPTIONS = @@ -88,7 +88,7 @@ public void testServiceOptions() throws Exception { public void testModelAndRequests() throws Exception { Serializable[] objects = {ACL_DOMAIN, ACL_GROUP, ACL_PROJECT_, ACL_USER, ACL_RAW, BLOB_INFO, BUCKET_INFO, - ORIGIN, CORS, BATCH_REQUEST,BATCH_RESPONSE, LIST_RESULT, BLOB_LIST_OPTIONS, + ORIGIN, CORS, BATCH_REQUEST, BATCH_RESPONSE, LIST_RESULT, BLOB_LIST_OPTIONS, BLOB_SOURCE_OPTIONS, BLOB_TARGET_OPTIONS, BUCKET_LIST_OPTIONS, BUCKET_SOURCE_OPTIONS, BUCKET_TARGET_OPTIONS}; for (Serializable obj : objects) { diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java index fa0daa976eb0..9e041fe9f846 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java @@ -342,7 +342,7 @@ public void testGetBlob() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.expect( - storageRpcMock.get(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb(), EMPTY_RPC_OPTIONS)) + storageRpcMock.get(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb(), EMPTY_RPC_OPTIONS)) .andReturn(BLOB_INFO1.toPb()); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); @@ -355,7 +355,7 @@ public void testGetBlobWithOptions() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.expect( - storageRpcMock.get(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb(), BLOB_SOURCE_OPTIONS)) + storageRpcMock.get(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb(), BLOB_SOURCE_OPTIONS)) .andReturn(BLOB_INFO1.toPb()); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); @@ -541,7 +541,7 @@ public void testDeleteBlob() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.expect( - storageRpcMock.delete(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb(), EMPTY_RPC_OPTIONS)) + storageRpcMock.delete(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb(), EMPTY_RPC_OPTIONS)) .andReturn(true); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); @@ -553,7 +553,7 @@ public void testDeleteBlobWithOptions() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.expect( - storageRpcMock.delete(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb(), BLOB_SOURCE_OPTIONS)) + storageRpcMock.delete(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb(), BLOB_SOURCE_OPTIONS)) .andReturn(true); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); @@ -634,7 +634,7 @@ public void testReadAllBytes() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.expect( - storageRpcMock.load(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb(), EMPTY_RPC_OPTIONS)) + storageRpcMock.load(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb(), EMPTY_RPC_OPTIONS)) .andReturn(BLOB_CONTENT); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); @@ -647,7 +647,7 @@ public void testReadAllBytesWithOptions() { EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()); EasyMock.expect( - storageRpcMock.load(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb(), BLOB_SOURCE_OPTIONS)) + storageRpcMock.load(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb(), BLOB_SOURCE_OPTIONS)) .andReturn(BLOB_CONTENT); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); @@ -663,9 +663,9 @@ public void testApply() { .update(BLOB_INFO2) .get(BUCKET_NAME1, BLOB_NAME3) .build(); - List toDelete = ImmutableList.of(BlobInfo.of(BUCKET_NAME1, BLOB_NAME1).toPb()); - List toUpdate = ImmutableList.of(BlobInfo.of(BUCKET_NAME1, BLOB_NAME2).toPb()); - List toGet = ImmutableList.of(BlobInfo.of(BUCKET_NAME1, BLOB_NAME3).toPb()); + List toDelete = ImmutableList.of(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb()); + List toUpdate = ImmutableList.of(BlobId.of(BUCKET_NAME1, BLOB_NAME2).toPb()); + List toGet = ImmutableList.of(BlobId.of(BUCKET_NAME1, BLOB_NAME3).toPb()); List> deleteOptions = ImmutableList.>of(EMPTY_RPC_OPTIONS); List> updateOptions = @@ -859,10 +859,10 @@ public void testSignUrlWithOptions() throws NoSuchAlgorithmException, InvalidKey @Test public void testGetAll() { - BlobInfo blobInfo1 = BlobInfo.of(BUCKET_NAME1, BLOB_NAME1); - BlobInfo blobInfo2 = BlobInfo.of(BUCKET_NAME1, BLOB_NAME2); - StorageObject storageObject1 = blobInfo1.toPb(); - StorageObject storageObject2 = blobInfo2.toPb(); + BlobId blobId1 = BlobId.of(BUCKET_NAME1, BLOB_NAME1); + BlobId blobId2 = BlobId.of(BUCKET_NAME1, BLOB_NAME2); + StorageObject storageObject1 = blobId1.toPb(); + StorageObject storageObject2 = blobId2.toPb(); List toGet = ImmutableList.of(storageObject1, storageObject2); Map> deleteResult = ImmutableMap.of(); @@ -882,7 +882,7 @@ public Tuple apply(StorageObject f) { EasyMock.expect(storageRpcMock.batch(EasyMock.capture(capturedBatchRequest))).andReturn(res); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); - List resultBlobs = storage.get(blobInfo1, blobInfo2); + List resultBlobs = storage.get(blobId1, blobId2); // Verify captured StorageRpc.BatchRequest List>> capturedToGet = @@ -968,7 +968,7 @@ public Tuple apply(StorageObject f) { EasyMock.expect(storageRpcMock.batch(EasyMock.capture(capturedBatchRequest))).andReturn(res); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); - List deleteResults = storage.delete(blobInfo1, blobInfo2); + List deleteResults = storage.delete(blobInfo1.blobId(), blobInfo2.blobId()); // Verify captured StorageRpc.BatchRequest List>> capturedToDelete = @@ -988,7 +988,7 @@ public Tuple apply(StorageObject f) { @Test public void testRetryableException() { - BlobInfo blob = BlobInfo.of(BUCKET_NAME1, BLOB_NAME1); + BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.getDefaultInstance()); EasyMock.expect(storageRpcMock.get(blob.toPb(), EMPTY_RPC_OPTIONS)) @@ -996,13 +996,13 @@ public void testRetryableException() { .andReturn(BLOB_INFO1.toPb()); EasyMock.replay(optionsMock, storageRpcMock); storage = StorageFactory.instance().get(optionsMock); - BlobInfo readBlob = storage.get(blob.bucket(), blob.name()); + BlobInfo readBlob = storage.get(blob); assertEquals(BLOB_INFO1, readBlob); } @Test public void testNonRetryableException() { - BlobInfo blob = BlobInfo.of(BUCKET_NAME1, BLOB_NAME1); + BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); String exceptionMessage = "Not Implemented"; EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.getDefaultInstance()); @@ -1012,12 +1012,12 @@ public void testNonRetryableException() { storage = StorageFactory.instance().get(optionsMock); thrown.expect(StorageException.class); thrown.expectMessage(exceptionMessage); - storage.get(blob.bucket(), blob.name()); + storage.get(blob); } @Test public void testRuntimeException() { - BlobInfo blob = BlobInfo.of(BUCKET_NAME1, BLOB_NAME1); + BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); String exceptionMessage = "Artificial runtime exception"; EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock); EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.getDefaultInstance()); @@ -1027,6 +1027,6 @@ public void testRuntimeException() { storage = StorageFactory.instance().get(optionsMock); thrown.expect(StorageException.class); thrown.expectMessage(exceptionMessage); - storage.get(blob.bucket(), blob.name()); + storage.get(blob); } }