Rely on WaitUtil moved to the acceptance framework WaitUtil has been moved to the acceptance framework in Gerrit core. Depends-On: https://gerrit-review.googlesource.com/c/gerrit/+/291229 Change-Id: I3a31335c7878a9e5b9082d6685b860e8e6c42325
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java index 420cdf8..afe1d82 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java
@@ -20,6 +20,7 @@ import com.google.gerrit.acceptance.LightweightPluginDaemonTest; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; +import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.entities.Project; import com.google.gerrit.server.config.SitePaths;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFanoutIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFanoutIT.java index 3619add..536080e 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFanoutIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFanoutIT.java
@@ -22,6 +22,7 @@ import com.google.gerrit.acceptance.PushOneCommit.Result; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; +import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.projects.BranchInput; import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java index fdea8d0..ba6f94d 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
@@ -21,6 +21,7 @@ import com.google.gerrit.acceptance.PushOneCommit.Result; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; +import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.changes.NotifyHandling; import com.google.gerrit.extensions.api.projects.BranchInput;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java index dd584ce..ff96b1c 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
@@ -20,6 +20,7 @@ import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; +import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.projects.BranchInput; import com.googlesource.gerrit.plugins.replication.Destination.QueueInfo;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/WaitUtil.java b/src/test/java/com/googlesource/gerrit/plugins/replication/WaitUtil.java deleted file mode 100644 index 586b56c..0000000 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/WaitUtil.java +++ /dev/null
@@ -1,34 +0,0 @@ -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.googlesource.gerrit.plugins.replication; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; - -import com.google.common.base.Stopwatch; -import java.time.Duration; -import java.util.function.Supplier; - -public class WaitUtil { - public static void waitUntil(Supplier<Boolean> waitCondition, Duration timeout) - throws InterruptedException { - Stopwatch stopwatch = Stopwatch.createStarted(); - while (!waitCondition.get()) { - if (stopwatch.elapsed().compareTo(timeout) > 0) { - throw new InterruptedException(); - } - MILLISECONDS.sleep(50); - } - } -}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/WaitUtilTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/WaitUtilTest.java deleted file mode 100644 index 0ccb0af..0000000 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/WaitUtilTest.java +++ /dev/null
@@ -1,40 +0,0 @@ -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.googlesource.gerrit.plugins.replication; - -import static com.google.gerrit.testing.GerritJUnit.assertThrows; -import static com.googlesource.gerrit.plugins.replication.WaitUtil.waitUntil; - -import java.time.Duration; -import org.junit.Test; - -public class WaitUtilTest { - - @Test - public void shouldFailWhenConditionNotMetWithinTimeout() throws Exception { - assertThrows( - InterruptedException.class, - () -> waitUntil(() -> returnTrue() == false, Duration.ofSeconds(1))); - } - - @Test - public void shouldNotFailWhenConditionIsMetWithinTimeout() throws Exception { - waitUntil(() -> returnTrue() == true, Duration.ofSeconds(1)); - } - - private static boolean returnTrue() { - return true; - } -}