Repository: googleapis/java-storage
Pull request #463 (2020-08-12 20:36:35)

deps: update dependency com.google.api.grpc:grpc-google-cloud-kms-v1 to v0.86.1
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [com.google.api.grpc:grpc-google-cloud-kms-v1](https://togithub.com/googleapis/java-kms) | patch | `0.86.0` -> `0.86.1` |

---

### Renovate configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-storage).

codecov[bot]: # [Codecov](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=h1) Report
> Merging [#463](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=desc) into [master](https://codecov.io/gh/googleapis/java-storage/commit/f1c9331e396810fddbaedc6cc292506ee93a1abb&el=desc) will **decrease** coverage by `0.13%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/googleapis/java-storage/pull/463/graphs/tree.svg?width=650&height=150&src=pr&token=ssm139YOdp)](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=tree)

```diff
@@             Coverage Diff              @@
##             master     #463      +/-   ##
============================================
- Coverage     63.29%   63.16%   -0.14%     
+ Complexity      622      612      -10     
============================================
  Files            32       32              
  Lines          5144     5128      -16     
  Branches        491      460      -31     
============================================
- Hits           3256     3239      -17     
+ Misses         1724     1722       -2     
- Partials        164      167       +3     
```


| [Impacted Files](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...in/java/com/google/cloud/storage/StorageBatch.java](https://codecov.io/gh/googleapis/java-storage/pull/463/diff?src=pr&el=tree#diff-Z29vZ2xlLWNsb3VkLXN0b3JhZ2Uvc3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3N0b3JhZ2UvU3RvcmFnZUJhdGNoLmphdmE=) | `88.00% <0.00%> (-4.00%)` | `13.00% <0.00%> (ø%)` | |
| [...gle/cloud/storage/testing/RemoteStorageHelper.java](https://codecov.io/gh/googleapis/java-storage/pull/463/diff?src=pr&el=tree#diff-Z29vZ2xlLWNsb3VkLXN0b3JhZ2Uvc3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3N0b3JhZ2UvdGVzdGluZy9SZW1vdGVTdG9yYWdlSGVscGVyLmphdmE=) | `63.93% <0.00%> (-0.59%)` | `9.00% <0.00%> (ø%)` | |
| [...main/java/com/google/cloud/storage/BucketInfo.java](https://codecov.io/gh/googleapis/java-storage/pull/463/diff?src=pr&el=tree#diff-Z29vZ2xlLWNsb3VkLXN0b3JhZ2Uvc3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3N0b3JhZ2UvQnVja2V0SW5mby5qYXZh) | `81.81% <0.00%> (-0.20%)` | `86.00% <0.00%> (ø%)` | |
| [...ain/java/com/google/cloud/storage/StorageImpl.java](https://codecov.io/gh/googleapis/java-storage/pull/463/diff?src=pr&el=tree#diff-Z29vZ2xlLWNsb3VkLXN0b3JhZ2Uvc3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3N0b3JhZ2UvU3RvcmFnZUltcGwuamF2YQ==) | `81.11% <0.00%> (-0.14%)` | `138.00% <0.00%> (-9.00%)` | |
| [...e/src/main/java/com/google/cloud/storage/Blob.java](https://codecov.io/gh/googleapis/java-storage/pull/463/diff?src=pr&el=tree#diff-Z29vZ2xlLWNsb3VkLXN0b3JhZ2Uvc3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3N0b3JhZ2UvQmxvYi5qYXZh) | `82.08% <0.00%> (-0.11%)` | `29.00% <0.00%> (-1.00%)` | |
| [...om/google/cloud/storage/spi/v1/HttpStorageRpc.java](https://codecov.io/gh/googleapis/java-storage/pull/463/diff?src=pr&el=tree#diff-Z29vZ2xlLWNsb3VkLXN0b3JhZ2Uvc3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3N0b3JhZ2Uvc3BpL3YxL0h0dHBTdG9yYWdlUnBjLmphdmE=) | `1.60% <0.00%> (+<0.01%)` | `2.00% <0.00%> (ø%)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=footer). Last update [f1c9331...af1db2f](https://codecov.io/gh/googleapis/java-storage/pull/463?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/google-cloud-storage/pom.xml b/google-cloud-storage/pom.xml
index 58782265..6db71ffd 100644
--- a/google-cloud-storage/pom.xml
+++ b/google-cloud-storage/pom.xml
@@ -117,7 +117,7 @@
     <dependency>
       <groupId>com.google.api.grpc</groupId>
       <artifactId>grpc-google-cloud-kms-v1</artifactId>
-      <version>0.86.0</version>
+      <version>0.86.1</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
index b3e96113..038df91d 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
@@ -351,7 +351,9 @@ public class BucketInfo implements Serializable {
           && condition.getAge() == null
           && condition.getCreatedBefore() == null
           && condition.getMatchesStorageClass() == null
-          && condition.getNumberOfNewerVersions() == null) {
+          && condition.getNumberOfNewerVersions() == null
+          && condition.getDaysSinceNoncurrentTime() == null
+          && condition.getNoncurrentTimeBefore() == null) {
         throw new IllegalArgumentException(
             "You must specify at least one condition to use object lifecycle "
                 + "management. Please see https://cloud.google.com/storage/docs/lifecycle for details.");
@@ -419,7 +421,13 @@ public class BucketInfo implements Serializable {
                       ? null
                       : transform(
                           lifecycleCondition.getMatchesStorageClass(),
-                          Functions.toStringFunction()));
+                          Functions.toStringFunction()))
+              .setDaysSinceNoncurrentTime(lifecycleCondition.getDaysSinceNoncurrentTime())
+              .setNoncurrentTimeBefore(
+                  lifecycleCondition.getNoncurrentTimeBefore() == null
+                      ? null
+                      : new DateTime(
+                          true, lifecycleCondition.getNoncurrentTimeBefore().getValue(), 0));
 
       rule.setCondition(condition);
 
@@ -462,7 +470,9 @@ public class BucketInfo implements Serializable {
                             public StorageClass apply(String storageClass) {
                               return StorageClass.valueOf(storageClass);
                             }
-                          }));
+                          }))
+              .setDaysSinceNoncurrentTime(condition.getDaysSinceNoncurrentTime())
+              .setNoncurrentTimeBefore(condition.getNoncurrentTimeBefore());
 
       return new LifecycleRule(lifecycleAction, conditionBuilder.build());
     }
@@ -480,6 +490,8 @@ public class BucketInfo implements Serializable {
       private final Integer numberOfNewerVersions;
       private final Boolean isLive;
       private final List<StorageClass> matchesStorageClass;
+      private final Integer daysSinceNoncurrentTime;
+      private final DateTime noncurrentTimeBefore;
 
       private LifecycleCondition(Builder builder) {
         this.age = builder.age;
@@ -487,6 +499,8 @@ public class BucketInfo implements Serializable {
         this.numberOfNewerVersions = builder.numberOfNewerVersions;
         this.isLive = builder.isLive;
         this.matchesStorageClass = builder.matchesStorageClass;
+        this.daysSinceNoncurrentTime = builder.daysSinceNoncurrentTime;
+        this.noncurrentTimeBefore = builder.noncurrentTimeBefore;
       }
 
       public Builder toBuilder() {
@@ -495,7 +509,9 @@ public class BucketInfo implements Serializable {
             .setCreatedBefore(this.createdBefore)
             .setNumberOfNewerVersions(this.numberOfNewerVersions)
             .setIsLive(this.isLive)
-            .setMatchesStorageClass(this.matchesStorageClass);
+            .setMatchesStorageClass(this.matchesStorageClass)
+            .setDaysSinceNoncurrentTime(this.daysSinceNoncurrentTime)
+            .setNoncurrentTimeBefore(this.noncurrentTimeBefore);
       }
 
       public static Builder newBuilder() {
@@ -510,6 +526,8 @@ public class BucketInfo implements Serializable {
             .add("numberofNewerVersions", numberOfNewerVersions)
             .add("isLive", isLive)
             .add("matchesStorageClass", matchesStorageClass)
+            .add("daysSinceNoncurrentTime", daysSinceNoncurrentTime)
+            .add("noncurrentTimeBefore", noncurrentTimeBefore)
             .toString();
       }
 
@@ -533,6 +551,18 @@ public class BucketInfo implements Serializable {
         return matchesStorageClass;
       }
 
+      /** Returns the number of days elapsed since the noncurrent timestamp of an object. */
+      public Integer getDaysSinceNoncurrentTime() {
+        return daysSinceNoncurrentTime;
+      }
+
+      /**
+       * Returns the date in RFC 3339 format with only the date part (for instance, "2013-01-15").
+       */
+      public DateTime getNoncurrentTimeBefore() {
+        return noncurrentTimeBefore;
+      }
+
       /** Builder for {@code LifecycleCondition}. */
       public static class Builder {
         private Integer age;
@@ -540,6 +570,8 @@ public class BucketInfo implements Serializable {
         private Integer numberOfNewerVersions;
         private Boolean isLive;
         private List<StorageClass> matchesStorageClass;
+        private Integer daysSinceNoncurrentTime;
+        private DateTime noncurrentTimeBefore;
 
         private Builder() {}
 
@@ -594,6 +626,29 @@ public class BucketInfo implements Serializable {
           return this;
         }
 
+        /**
+         * Sets the number of days elapsed since the noncurrent timestamp of an object. The
+         * condition is satisfied if the days elapsed is at least this number. This condition is
+         * relevant only for versioned objects. The value of the field must be a nonnegative
+         * integer. If it's zero, the object version will become eligible for Lifecycle action as
+         * soon as it becomes noncurrent.
+         */
+        public Builder setDaysSinceNoncurrentTime(Integer daysSinceNoncurrentTime) {
+          this.daysSinceNoncurrentTime = daysSinceNoncurrentTime;
+          return this;
+        }
+
+        /**
+         * Sets the date in RFC 3339 format with only the date part (for instance, "2013-01-15").
+         * Note that only date part will be considered, if the time is specified it will be
+         * truncated. This condition is satisfied when the noncurrent time on an object is before
+         * this date. This condition is relevant only for versioned objects.
+         */
+        public Builder setNoncurrentTimeBefore(DateTime noncurrentTimeBefore) {
+          this.noncurrentTimeBefore = noncurrentTimeBefore;
+          return this;
+        }
+
         /** Builds a {@code LifecycleCondition} object. * */
         public LifecycleCondition build() {
           return new LifecycleCondition(this);


Test patch:
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java
index 425cfb70..c7b3aa19 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import com.google.api.client.util.DateTime;
 import com.google.api.services.storage.model.Bucket;
 import com.google.api.services.storage.model.Bucket.Lifecycle.Rule;
 import com.google.cloud.storage.Acl.Project;
@@ -328,6 +329,22 @@ public class BucketInfoTest {
         setStorageClassLifecycleRule.getAction().getStorageClass());
     assertTrue(setStorageClassLifecycleRule.getCondition().getIsLive());
     assertEquals(10, setStorageClassLifecycleRule.getCondition().getNumNewerVersions().intValue());
+
+    Rule lifecycleRule =
+        new LifecycleRule(
+                LifecycleAction.newSetStorageClassAction(StorageClass.COLDLINE),
+                LifecycleCondition.newBuilder()
+                    .setIsLive(true)
+                    .setNumberOfNewerVersions(10)
+                    .setDaysSinceNoncurrentTime(30)
+                    .setNoncurrentTimeBefore(new DateTime(System.currentTimeMillis()))
+                    .build())
+            .toPb();
+    assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass());
+    assertTrue(lifecycleRule.getCondition().getIsLive());
+    assertEquals(10, lifecycleRule.getCondition().getNumNewerVersions().intValue());
+    assertEquals(30, lifecycleRule.getCondition().getDaysSinceNoncurrentTime().intValue());
+    assertNotNull(lifecycleRule.getCondition().getNoncurrentTimeBefore());
   }
 
   @Test
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java
index 24f5ed9e..35c4e253 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
 import com.google.api.client.googleapis.json.GoogleJsonError;
+import com.google.api.client.util.DateTime;
 import com.google.api.core.ApiClock;
 import com.google.api.services.storage.model.Policy.Bindings;
 import com.google.api.services.storage.model.StorageObject;
@@ -2232,4 +2233,40 @@ public class StorageImplTest {
     assertEquals(outputFields.get("key"), "my-object");
     assertEquals("https://storage.googleapis.com/my-bucket/", policy.getUrl());
   }
+
+  @Test
+  public void testBucketLifecycleRules() {
+    BucketInfo bucketInfo =
+        BucketInfo.newBuilder("b")
+            .setLocation("us")
+            .setLifecycleRules(
+                ImmutableList.of(
+                    new BucketInfo.LifecycleRule(
+                        BucketInfo.LifecycleRule.LifecycleAction.newSetStorageClassAction(
+                            StorageClass.COLDLINE),
+                        BucketInfo.LifecycleRule.LifecycleCondition.newBuilder()
+                            .setAge(1)
+                            .setNumberOfNewerVersions(3)
+                            .setIsLive(false)
+                            .setCreatedBefore(new DateTime(System.currentTimeMillis()))
+                            .setMatchesStorageClass(ImmutableList.of(StorageClass.COLDLINE))
+                            .setDaysSinceNoncurrentTime(30)
+                            .setNoncurrentTimeBefore(new DateTime(System.currentTimeMillis()))
+                            .build())))
+            .build();
+    EasyMock.expect(
+            storageRpcMock.create(bucketInfo.toPb(), new HashMap<StorageRpc.Option, Object>()))
+        .andReturn(bucketInfo.toPb());
+    EasyMock.replay(storageRpcMock);
+    initializeService();
+    Bucket bucket = storage.create(bucketInfo);
+    BucketInfo.LifecycleRule lifecycleRule = bucket.getLifecycleRules().get(0);
+    assertEquals(3, lifecycleRule.getCondition().getNumberOfNewerVersions().intValue());
+    assertNotNull(lifecycleRule.getCondition().getCreatedBefore());
+    assertFalse(lifecycleRule.getCondition().getIsLive());
+    assertEquals(1, lifecycleRule.getCondition().getAge().intValue());
+    assertEquals(1, lifecycleRule.getCondition().getMatchesStorageClass().size());
+    assertEquals(30, lifecycleRule.getCondition().getDaysSinceNoncurrentTime().intValue());
+    assertNotNull(lifecycleRule.getCondition().getNoncurrentTimeBefore());
+  }
 }
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
index a741f3eb..d92ca592 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
@@ -456,6 +456,8 @@ public class ITStorageTest {
                             .setIsLive(false)
                             .setCreatedBefore(new DateTime(System.currentTimeMillis()))
                             .setMatchesStorageClass(ImmutableList.of(StorageClass.COLDLINE))
+                            .setDaysSinceNoncurrentTime(30)
+                            .setNoncurrentTimeBefore(new DateTime(System.currentTimeMillis()))
                             .build())))
             .build());
     Bucket remoteBucket =
@@ -472,6 +474,8 @@ public class ITStorageTest {
       assertFalse(lifecycleRule.getCondition().getIsLive());
       assertEquals(1, lifecycleRule.getCondition().getAge().intValue());
       assertEquals(1, lifecycleRule.getCondition().getMatchesStorageClass().size());
+      assertEquals(30, lifecycleRule.getCondition().getDaysSinceNoncurrentTime().intValue());
+      assertNotNull(lifecycleRule.getCondition().getNoncurrentTimeBefore());
     } finally {
       storage.delete(lifecycleTestBucketName);
     }