Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose updateTime field of the bucket #449

Merged
merged 6 commits into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions google-cloud-storage/clirr-ignored-differences.xml
Expand Up @@ -21,4 +21,9 @@
<method>com.google.cloud.storage.BucketInfo$Builder deleteLifecycleRules()</method>
<differenceType>7013</differenceType>
</difference>
<difference>
<className>com/google/cloud/storage/BucketInfo$Builder</className>
<method>com.google.cloud.storage.BucketInfo$Builder setUpdateTime(java.lang.Long)</method>
<differenceType>7013</differenceType>
</difference>
</differences>
Expand Up @@ -601,6 +601,12 @@ Builder setCreateTime(Long createTime) {
return this;
}

@Override
Builder setUpdateTime(Long updateTime) {
infoBuilder.setUpdateTime(updateTime);
return this;
}

@Override
Builder setMetageneration(Long metageneration) {
infoBuilder.setMetageneration(metageneration);
Expand Down
Expand Up @@ -84,6 +84,7 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo)
private final List<LifecycleRule> lifecycleRules;
private final String etag;
private final Long createTime;
private final Long updateTime;
private final Long metageneration;
private final List<Cors> cors;
private final List<Acl> acl;
Expand Down Expand Up @@ -1005,6 +1006,8 @@ public abstract static class Builder {

abstract Builder setCreateTime(Long createTime);

abstract Builder setUpdateTime(Long updateTime);

abstract Builder setMetageneration(Long metageneration);

abstract Builder setLocationType(String locationType);
Expand Down Expand Up @@ -1090,6 +1093,7 @@ static final class BuilderImpl extends Builder {
private String location;
private String etag;
private Long createTime;
private Long updateTime;
private Long metageneration;
private List<Cors> cors;
private List<Acl> acl;
Expand All @@ -1113,6 +1117,7 @@ static final class BuilderImpl extends Builder {
name = bucketInfo.name;
etag = bucketInfo.etag;
createTime = bucketInfo.createTime;
updateTime = bucketInfo.updateTime;
metageneration = bucketInfo.metageneration;
location = bucketInfo.location;
storageClass = bucketInfo.storageClass;
Expand Down Expand Up @@ -1232,6 +1237,12 @@ Builder setCreateTime(Long createTime) {
return this;
}

@Override
Builder setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
return this;
}

@Override
Builder setMetageneration(Long metageneration) {
this.metageneration = metageneration;
Expand Down Expand Up @@ -1337,6 +1348,7 @@ public BucketInfo build() {
name = builder.name;
etag = builder.etag;
createTime = builder.createTime;
updateTime = builder.updateTime;
metageneration = builder.metageneration;
location = builder.location;
storageClass = builder.storageClass;
Expand Down Expand Up @@ -1468,6 +1480,14 @@ public Long getCreateTime() {
return createTime;
}

/**
* Returns the last modification time of the bucket's metadata expressed as the number of
* milliseconds since the Unix epoch.
*/
public Long getUpdateTime() {
return updateTime;
}

/** Returns the metadata generation of this bucket. */
public Long getMetageneration() {
return metageneration;
Expand Down Expand Up @@ -1650,6 +1670,9 @@ com.google.api.services.storage.model.Bucket toPb() {
if (createTime != null) {
bucketPb.setTimeCreated(new DateTime(createTime));
}
if (updateTime != null) {
bucketPb.setUpdated(new DateTime(updateTime));
}
if (metageneration != null) {
bucketPb.setMetageneration(metageneration);
}
Expand Down Expand Up @@ -1797,6 +1820,9 @@ static BucketInfo fromPb(com.google.api.services.storage.model.Bucket bucketPb)
if (bucketPb.getTimeCreated() != null) {
builder.setCreateTime(bucketPb.getTimeCreated().getValue());
}
if (bucketPb.getUpdated() != null) {
builder.setUpdateTime(bucketPb.getUpdated().getValue());
}
if (bucketPb.getLocation() != null) {
builder.setLocation(bucketPb.getLocation());
}
Expand Down
Expand Up @@ -56,6 +56,7 @@ public class BucketInfoTest {
private static final User OWNER = new User("user@gmail.com");
private static final String SELF_LINK = "http://storage/b/n";
private static final Long CREATE_TIME = System.currentTimeMillis();
private static final Long UPDATE_TIME = CREATE_TIME;
private static final List<Cors> CORS = Collections.singletonList(Cors.newBuilder().build());
private static final List<Acl> DEFAULT_ACL =
Collections.singletonList(Acl.of(User.ofAllAuthenticatedUsers(), Role.WRITER));
Expand Down Expand Up @@ -117,6 +118,7 @@ public class BucketInfoTest {
.setSelfLink(SELF_LINK)
.setCors(CORS)
.setCreateTime(CREATE_TIME)
.setUpdateTime(UPDATE_TIME)
.setDefaultAcl(DEFAULT_ACL)
.setDeleteRules(DELETE_RULES)
.setLifecycleRules(LIFECYCLE_RULES)
Expand Down Expand Up @@ -148,6 +150,7 @@ public class BucketInfoTest {
.setSelfLink(SELF_LINK)
.setCors(CORS)
.setCreateTime(CREATE_TIME)
.setUpdateTime(UPDATE_TIME)
.setDefaultAcl(DEFAULT_ACL)
.setDeleteRules(DELETE_RULES)
.setLifecycleRules(LIFECYCLE_RULES)
Expand Down Expand Up @@ -202,6 +205,7 @@ public void testBuilder() {
assertEquals(OWNER, BUCKET_INFO.getOwner());
assertEquals(SELF_LINK, BUCKET_INFO.getSelfLink());
assertEquals(CREATE_TIME, BUCKET_INFO.getCreateTime());
assertEquals(UPDATE_TIME, BUCKET_INFO.getUpdateTime());
assertEquals(CORS, BUCKET_INFO.getCors());
assertEquals(DEFAULT_ACL, BUCKET_INFO.getDefaultAcl());
assertEquals(DELETE_RULES, BUCKET_INFO.getDeleteRules());
Expand All @@ -223,6 +227,7 @@ public void testBuilder() {
}

@Test
@SuppressWarnings({"unchecked", "deprecation"})
public void testToPbAndFromPb() {
compareBuckets(BUCKET_INFO, BucketInfo.fromPb(BUCKET_INFO.toPb()));
BucketInfo bucketInfo =
Expand All @@ -245,6 +250,7 @@ private void compareBuckets(BucketInfo expected, BucketInfo value) {
assertEquals(expected.getOwner(), value.getOwner());
assertEquals(expected.getSelfLink(), value.getSelfLink());
assertEquals(expected.getCreateTime(), value.getCreateTime());
assertEquals(expected.getUpdateTime(), value.getUpdateTime());
assertEquals(expected.getCors(), value.getCors());
assertEquals(expected.getDefaultAcl(), value.getDefaultAcl());
assertEquals(expected.getDeleteRules(), value.getDeleteRules());
Expand Down
Expand Up @@ -69,6 +69,7 @@ public class BucketTest {
private static final User OWNER = new User("user@gmail.com");
private static final String SELF_LINK = "http://storage/b/n";
private static final Long CREATE_TIME = System.currentTimeMillis();
private static final Long UPDATE_TIME = CREATE_TIME - 1L;
private static final List<Cors> CORS = Collections.singletonList(Cors.newBuilder().build());
private static final List<Acl> DEFAULT_ACL =
Collections.singletonList(Acl.of(User.ofAllAuthenticatedUsers(), WRITER));
Expand Down Expand Up @@ -111,6 +112,7 @@ public class BucketTest {
.setSelfLink(SELF_LINK)
.setCors(CORS)
.setCreateTime(CREATE_TIME)
.setUpdateTime(UPDATE_TIME)
.setDefaultAcl(DEFAULT_ACL)
.setDeleteRules(DELETE_RULES)
.setLifecycleRules(LIFECYCLE_RULES)
Expand Down Expand Up @@ -803,6 +805,7 @@ public void testBuilder() {
.setSelfLink(SELF_LINK)
.setCors(CORS)
.setCreateTime(CREATE_TIME)
.setUpdateTime(UPDATE_TIME)
.setDefaultAcl(DEFAULT_ACL)
.setDeleteRules(DELETE_RULES)
.setLifecycleRules(LIFECYCLE_RULES)
Expand All @@ -828,6 +831,7 @@ public void testBuilder() {
assertEquals(OWNER, bucket.getOwner());
assertEquals(SELF_LINK, bucket.getSelfLink());
assertEquals(CREATE_TIME, bucket.getCreateTime());
assertEquals(UPDATE_TIME, bucket.getUpdateTime());
assertEquals(CORS, bucket.getCors());
assertEquals(DEFAULT_ACL, bucket.getDefaultAcl());
assertEquals(DELETE_RULES, bucket.getDeleteRules());
Expand Down
Expand Up @@ -3535,4 +3535,26 @@ public void testRemoveBucketCORS() throws ExecutionException, InterruptedExcepti
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}

@Test
public void testBucketUpdateTime() throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
BucketInfo bucketInfo =
BucketInfo.newBuilder(bucketName).setLocation("us").setVersioningEnabled(true).build();
try {
Bucket bucket = storage.create(bucketInfo);
assertThat(bucket).isNotNull();
assertThat(bucket.versioningEnabled()).isTrue();
assertThat(bucket.getCreateTime()).isNotNull();
assertThat(bucket.getUpdateTime()).isEqualTo(bucket.getCreateTime());

Bucket updatedBucket = bucket.toBuilder().setVersioningEnabled(false).build().update();
assertThat(updatedBucket.versioningEnabled()).isFalse();
assertThat(updatedBucket.getUpdateTime()).isNotNull();
assertThat(updatedBucket.getCreateTime()).isEqualTo(bucket.getCreateTime());
assertThat(updatedBucket.getUpdateTime()).isGreaterThan(bucket.getCreateTime());
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
athakor marked this conversation as resolved.
Show resolved Hide resolved
}