Skip to content

Commit 99b1ec0

Browse files
committed
---
yaml --- r: 6149 b: refs/heads/tswast-patch-1 c: 3cf6af3 h: refs/heads/master i: 6147: 3a6af05
1 parent 6ce8b77 commit 99b1ec0

5 files changed

Lines changed: 59 additions & 13 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: ccc023045b446ac8d5e4b6e921171e09e3eac37e
60+
refs/heads/tswast-patch-1: 3cf6af39a09272ced21ba85b8c9388846581d1e2
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public final class Blob {
3535

3636
private final Storage storage;
37-
private BlobInfo info;
37+
private final BlobInfo info;
3838

3939
public static class BlobSourceOption extends Option {
4040

@@ -137,19 +137,31 @@ public byte[] content(Storage.BlobSourceOption... options) {
137137
return storage.readAllBytes(info.bucket(), info.name(), options);
138138
}
139139

140+
/**
141+
* Fetches current blob's latest information.
142+
*
143+
* @param options blob read options
144+
* @return a {@code Blob} object with latest information
145+
* @throws StorageException upon failure
146+
*/
147+
public Blob reload(BlobSourceOption... options) {
148+
return new Blob(storage, storage.get(info.bucket(), info.name(), convert(info, options)));
149+
}
150+
140151
/**
141152
* Update the blob's information. Bucket or blob's name cannot be changed by this method. If you
142153
* want to rename the blob or move it to a different bucket use the {@link #copyTo} and
143-
* {@link #delete} operations.
154+
* {@link #delete} operations. A new {@code Blob} object is returned.
144155
*
145156
* @param blobInfo new blob's information. Bucket and blob names must match the current ones
146157
* @param options update options
158+
* @return a {@code Blob} object with updated information
147159
* @throws StorageException upon failure
148160
*/
149-
public void update(BlobInfo blobInfo, BlobTargetOption... options) {
161+
public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
150162
checkArgument(Objects.equals(blobInfo.bucket(), info.bucket()), "Bucket name must match");
151163
checkArgument(Objects.equals(blobInfo.name(), info.name()), "Blob name must match");
152-
info = storage.update(blobInfo, options);
164+
return new Blob(storage, storage.update(blobInfo, options));
153165
}
154166

155167
/**

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
21+
import static com.google.gcloud.storage.Blob.BlobSourceOption.convert;
2122

2223
import com.google.gcloud.storage.Storage.BlobSourceOption;
2324
import com.google.gcloud.storage.Storage.BlobTargetOption;
@@ -34,7 +35,7 @@
3435
public final class Bucket {
3536

3637
private final Storage storage;
37-
private BucketInfo info;
38+
private final BucketInfo info;
3839

3940
/**
4041
* Construct a {@code Bucket} object for the provided {@code BucketInfo}. The storage service is
@@ -78,15 +79,28 @@ public boolean exists() {
7879
}
7980

8081
/**
81-
* Update the bucket's information. Bucket's name cannot be changed.
82+
* Fetches current bucket's latest information.
83+
*
84+
* @param options bucket read options
85+
* @return a {@code Bucket} object with latest information
86+
* @throws StorageException upon failure
87+
*/
88+
public Bucket reload(BucketSourceOption... options) {
89+
return new Bucket(storage, storage.get(info.name(), options));
90+
}
91+
92+
/**
93+
* Update the bucket's information. Bucket's name cannot be changed. A new {@code Bucket} object
94+
* is returned.
8295
*
8396
* @param bucketInfo new bucket's information. Name must match the one of the current bucket
8497
* @param options update options
98+
* @return a {@code Bucket} object with updated information
8599
* @throws StorageException upon failure
86100
*/
87-
public void update(BucketInfo bucketInfo, BucketTargetOption... options) {
101+
public Bucket update(BucketInfo bucketInfo, BucketTargetOption... options) {
88102
checkArgument(Objects.equals(bucketInfo.name(), info.name()), "Bucket name must match");
89-
info = storage.update(bucketInfo, options);
103+
return new Bucket(storage, storage.update(bucketInfo, options));
90104
}
91105

92106
/**

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,24 @@ public void testContent() throws Exception {
8181
assertArrayEquals(content, blob.content());
8282
}
8383

84+
@Test
85+
public void testReload() throws Exception {
86+
BlobInfo updatedInfo = BLOB_INFO.toBuilder().cacheControl("c").build();
87+
expect(storage.get(BLOB_INFO.bucket(), BLOB_INFO.name())).andReturn(updatedInfo);
88+
replay(storage);
89+
Blob updatedBlob = blob.reload();
90+
assertSame(storage, blob.storage());
91+
assertEquals(updatedInfo, updatedBlob.info());
92+
}
93+
8494
@Test
8595
public void testUpdate() throws Exception {
8696
BlobInfo updatedInfo = BLOB_INFO.toBuilder().cacheControl("c").build();
8797
expect(storage.update(updatedInfo)).andReturn(updatedInfo);
8898
replay(storage);
89-
blob.update(updatedInfo);
99+
Blob updatedBlob = blob.update(updatedInfo);
90100
assertSame(storage, blob.storage());
91-
assertEquals(updatedInfo, blob.info());
101+
assertEquals(updatedInfo, updatedBlob.info());
92102
}
93103

94104
@Test

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,24 @@ public void testExists_False() throws Exception {
8080
assertFalse(bucket.exists());
8181
}
8282

83+
@Test
84+
public void testReload() throws Exception {
85+
BucketInfo updatedInfo = BUCKET_INFO.toBuilder().notFoundPage("p").build();
86+
expect(storage.get(updatedInfo.name())).andReturn(updatedInfo);
87+
replay(storage);
88+
Bucket updatedBucket = bucket.reload();
89+
assertSame(storage, bucket.storage());
90+
assertEquals(updatedInfo, updatedBucket.info());
91+
}
92+
8393
@Test
8494
public void testUpdate() throws Exception {
8595
BucketInfo updatedInfo = BUCKET_INFO.toBuilder().notFoundPage("p").build();
8696
expect(storage.update(updatedInfo)).andReturn(updatedInfo);
8797
replay(storage);
88-
bucket.update(updatedInfo);
98+
Bucket updatedBucket = bucket.update(updatedInfo);
8999
assertSame(storage, bucket.storage());
90-
assertEquals(updatedInfo, bucket.info());
100+
assertEquals(updatedInfo, updatedBucket.info());
91101
}
92102

93103
@Test

0 commit comments

Comments
 (0)