Destination: parse replication delay and retry as time units

The replication delay and retry values are interpreted as seconds and
minutes respectively, but are being parsed as integers.

This is inconsistent with how time units are handled in other Gerrit
confiuration settings, and can cause confusion when the user configures
them using the time unit syntax such as "15s" and it causes the plugin
to fail with "invalid value".

Change it so that the delay and retry are parsed as time units. The
value can be given in any recognised time unit. Defaults remain the
same as before - 15 seconds and 1 minute respectively.

Change-Id: I7e518c6b8cac7f7af35d66df33eb6fd85d924eea
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index a175285..eea1038 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -28,6 +28,7 @@
 import com.google.gerrit.server.account.GroupBackend;
 import com.google.gerrit.server.account.GroupBackends;
 import com.google.gerrit.server.account.ListGroupMembership;
+import com.google.gerrit.server.config.ConfigUtil;
 import com.google.gerrit.server.config.FactoryModule;
 import com.google.gerrit.server.config.RequestScopedReviewDbProvider;
 import com.google.gerrit.server.git.GitRepositoryManager;
@@ -103,8 +104,10 @@
       final GroupBackend groupBackend) {
     remote = rc;
     gitManager = gitRepositoryManager;
-    delay = Math.max(0, getInt(rc, cfg, "replicationdelay", 15));
-    retryDelay = Math.max(0, getInt(rc, cfg, "replicationretry", 1));
+    delay = Math.max(0,
+        getTimeUnit(rc, cfg, "replicationdelay", 15, TimeUnit.SECONDS));
+    retryDelay = Math.max(0,
+        getTimeUnit(rc, cfg, "replicationretry", 1, TimeUnit.MINUTES));
     lockErrorMaxRetries = cfg.getInt("replication", "lockErrorMaxRetries", 0);
     adminUrls = cfg.getStringList("remote", rc.getName(), "adminUrl");
 
@@ -199,6 +202,12 @@
     return cfg.getInt("remote", rc.getName(), name, defValue);
   }
 
+  private static int getTimeUnit(
+      RemoteConfig rc, Config cfg, String name, int defValue, TimeUnit unit) {
+    return (int)ConfigUtil.getTimeUnit(
+        cfg, "remote", rc.getName(), name, defValue, unit);
+  }
+
   private boolean isVisible(final Project.NameKey project,
       ReplicationState... states) {
     try {
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 29626d8..54251ce 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -183,17 +183,17 @@
 [2]: #example_file
 
 remote.NAME.replicationDelay
-:	Number of seconds to wait before scheduling a remote push
-	operation.  Setting the delay to 0 effectively disables the
-	delay, causing the push to start as soon as possible.
+:	Time to wait before scheduling a remote push operation. Setting
+	the delay to 0 effectively disables the delay, causing the push
+	to start as soon as possible.
 
 	This is a Gerrit specific extension to the Git remote block.
 
 	By default, 15 seconds.
 
 remote.NAME.replicationRetry
-:	Number of minutes to wait before scheduling a remote push
-	operation previously failed due to an offline remote server.
+:	Time to wait before scheduling a remote push operation previously
+	failed due to an offline remote server.
 
 	If a remote push operation fails because a remote server was
 	offline, all push operations to the same destination URL are