Fix for replenishing schedule

This fixes the unusual replenish per rate schedule, where the replenish
was scheduled as: 1 minute – (n - 1) * timeLapse. It was unintended to
be firstly replenished in 1 minute. Meaning, it should have been
scheduled as (n) * timeLapse.

It is ambiguous why scheduleAtFixedRate method is not executed after an
initial delay, and considers the initial delay variable as a first
period. However, by walking through the previous versions, since it is
evident that scheduleAtFixedRate method indeed considers the initial
delay as the first period, this fixes accordingly.

Change-Id: I36273b8f70acab470a2322e7b091f1031acf23f7
diff --git a/src/main/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiter.java b/src/main/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiter.java
index 203645d..cb86336 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiter.java
@@ -43,7 +43,8 @@
     this.maxPermits = permits;
     this.usedPermits = new AtomicInteger();
     this.replenishTask =
-        executor.scheduleAtFixedRate(this::replenishPermits, 1, timeLapse, TimeUnit.MINUTES);
+        executor.scheduleAtFixedRate(
+            this::replenishPermits, timeLapse, timeLapse, TimeUnit.MINUTES);
   }
 
   @Override
diff --git a/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiterTest.java b/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiterTest.java
index 0343d6b..1cb3764 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/PeriodicRateLimiterTest.java
@@ -68,7 +68,10 @@
   public void testReplenishPermitsIsScheduled() {
     verify(scheduledExecutorMock)
         .scheduleAtFixedRate(
-            any(), eq(1L), eq(DEFAULT_TIME_LAPSE_IN_MINUTES), eq(TimeUnit.MINUTES));
+            any(),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
+            eq(TimeUnit.MINUTES));
   }
 
   @Test
@@ -77,7 +80,7 @@
     verify(scheduledExecutorMock)
         .scheduleAtFixedRate(
             runnableCaptor.capture(),
-            eq(1L),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
             eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
             eq(TimeUnit.MINUTES));
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningRateLimiterTest.java b/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningRateLimiterTest.java
index 4a0162f..0353a92 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningRateLimiterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningRateLimiterTest.java
@@ -99,7 +99,10 @@
   public void testReplenishPermitsIsScheduled() {
     verify(scheduledExecutorMock1)
         .scheduleAtFixedRate(
-            any(), eq(1L), eq(DEFAULT_TIME_LAPSE_IN_MINUTES), eq(TimeUnit.MINUTES));
+            any(),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
+            eq(TimeUnit.MINUTES));
   }
 
   @Test
@@ -108,7 +111,7 @@
     verify(scheduledExecutorMock1)
         .scheduleAtFixedRate(
             runnableCaptor.capture(),
-            eq(1L),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
             eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
             eq(TimeUnit.MINUTES));
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningUnlimitedRateLimiterTest.java b/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningUnlimitedRateLimiterTest.java
index b402e77..facabbe 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningUnlimitedRateLimiterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/ratelimiter/WarningUnlimitedRateLimiterTest.java
@@ -73,7 +73,10 @@
   public void testReplenishPermitsIsScheduled() {
     verify(scheduledExecutorMock)
         .scheduleAtFixedRate(
-            any(), eq(1L), eq(DEFAULT_TIME_LAPSE_IN_MINUTES), eq(TimeUnit.MINUTES));
+            any(),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
+            eq(TimeUnit.MINUTES));
   }
 
   @Test
@@ -82,7 +85,7 @@
     verify(scheduledExecutorMock)
         .scheduleAtFixedRate(
             runnableCaptor.capture(),
-            eq(1L),
+            eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
             eq(DEFAULT_TIME_LAPSE_IN_MINUTES),
             eq(TimeUnit.MINUTES));