Merge branch 'stable-3.3' into master
* stable-3.3:
ReplicationIT: Remove unnecessary storage inspection
ReplicationIT: Fix invalid replicationDelay setting
Split replication plugins tests in two groups
Change-Id: I287200d0b7bacb6f39349a36a1080766881126fd
diff --git a/BUILD b/BUILD
index 9fb9a49..1ed5cf3 100644
--- a/BUILD
+++ b/BUILD
@@ -15,6 +15,7 @@
],
resources = glob(["src/main/resources/**/*"]),
deps = [
+ "//lib/auto:auto-value-gson",
"//lib/commons:io",
],
)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/AutoValueTypeAdapterFactory.java b/src/main/java/com/googlesource/gerrit/plugins/replication/AutoValueTypeAdapterFactory.java
new file mode 100644
index 0000000..5b27176
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/AutoValueTypeAdapterFactory.java
@@ -0,0 +1,25 @@
+// Copyright (C) 2020 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 com.google.gson.TypeAdapterFactory;
+import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory;
+
+@GsonTypeAdapterFactory
+public abstract class AutoValueTypeAdapterFactory implements TypeAdapterFactory {
+ public static TypeAdapterFactory create() {
+ return new AutoValueGson_AutoValueTypeAdapterFactory();
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
index 94b3f31..cd4a3fb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
@@ -186,7 +186,7 @@
for (URIish uri : cfg.getURIs(project, urlMatch)) {
if (!isPersisted) {
replicationTasksStorage.create(
- new ReplicateRefUpdate(project.get(), refName, uri, cfg.getRemoteConfigName()));
+ ReplicateRefUpdate.create(project.get(), refName, uri, cfg.getRemoteConfigName()));
}
cfg.schedule(project, refName, uri, state, now);
}
@@ -204,7 +204,7 @@
replaying = true;
for (ReplicationTasksStorage.ReplicateRefUpdate t : replicationTasksStorage.listWaiting()) {
try {
- fire(new URIish(t.uri), Project.nameKey(t.project), t.ref);
+ fire(new URIish(t.uri()), Project.nameKey(t.project()), t.ref());
} catch (URISyntaxException e) {
repLog.atSevere().withCause(e).log("Encountered malformed URI for persisted event %s", t);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
index fe5e7cb..68661cf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
@@ -16,10 +16,13 @@
import static java.nio.charset.StandardCharsets.UTF_8;
+import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.flogger.FluentLogger;
import com.google.common.hash.Hashing;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.TypeAdapter;
import com.google.inject.Inject;
import com.google.inject.ProvisionException;
import com.google.inject.Singleton;
@@ -64,10 +67,11 @@
public class ReplicationTasksStorage {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- public static class ReplicateRefUpdate {
- public static Optional<ReplicateRefUpdate> createOptionally(Path file) {
+ @AutoValue
+ public abstract static class ReplicateRefUpdate {
+ public static Optional<ReplicateRefUpdate> createOptionally(Path file, Gson gson) {
try {
- return Optional.of(create(file));
+ return Optional.of(create(file, gson));
} catch (NoSuchFileException e) {
logger.atFine().log("File %s not found while reading task", file);
} catch (IOException e) {
@@ -78,30 +82,35 @@
return Optional.empty();
}
- public static ReplicateRefUpdate create(Path file) throws IOException {
+ public static ReplicateRefUpdate create(Path file, Gson gson) throws IOException {
String json = new String(Files.readAllBytes(file), UTF_8);
- return GSON.fromJson(json, ReplicateRefUpdate.class);
+ return gson.fromJson(json, ReplicateRefUpdate.class);
}
- public final String project;
- public final String ref;
- public final String uri;
- public final String remote;
-
- public ReplicateRefUpdate(String project, String ref, URIish uri, String remote) {
- this.project = project;
- this.ref = ref;
- this.uri = uri.toASCIIString();
- this.remote = remote;
+ public static ReplicateRefUpdate create(String project, String ref, URIish uri, String remote) {
+ return new AutoValue_ReplicationTasksStorage_ReplicateRefUpdate(
+ project, ref, uri.toASCIIString(), remote);
}
+ public abstract String project();
+
+ public abstract String ref();
+
+ public abstract String uri();
+
+ public abstract String remote();
+
@Override
- public String toString() {
- return "ref-update " + project + ":" + ref + " uri:" + uri + " remote:" + remote;
+ public final String toString() {
+ return "ref-update " + project() + ":" + ref() + " uri:" + uri() + " remote:" + remote();
+ }
+
+ public static TypeAdapter<ReplicateRefUpdate> typeAdapter(Gson gson) {
+ return new AutoValue_ReplicationTasksStorage_ReplicateRefUpdate.GsonTypeAdapter(gson);
}
}
- private static final Gson GSON = new Gson();
+ private final Gson gson;
private final Path buildingUpdates;
private final Path runningUpdates;
@@ -117,6 +126,8 @@
buildingUpdates = refUpdates.resolve("building");
runningUpdates = refUpdates.resolve("running");
waitingUpdates = refUpdates.resolve("waiting");
+ gson =
+ new GsonBuilder().registerTypeAdapterFactory(AutoValueTypeAdapterFactory.create()).create();
}
public synchronized String create(ReplicateRefUpdate r) {
@@ -167,7 +178,7 @@
private Stream<ReplicateRefUpdate> streamRecursive(Path dir) {
return walk(dir)
- .map(path -> ReplicateRefUpdate.createOptionally(path))
+ .map(path -> ReplicateRefUpdate.createOptionally(path, gson))
.filter(Optional::isPresent)
.map(Optional::get);
}
@@ -205,7 +216,8 @@
public Task(ReplicateRefUpdate update) {
this.update = update;
- String key = update.project + "\n" + update.ref + "\n" + update.uri + "\n" + update.remote;
+ String key =
+ update.project() + "\n" + update.ref() + "\n" + update.uri() + "\n" + update.remote();
taskKey = sha1(key).name();
running = createDir(runningUpdates).resolve(taskKey);
waiting = createDir(waitingUpdates).resolve(taskKey);
@@ -216,7 +228,7 @@
return taskKey;
}
- String json = GSON.toJson(update) + "\n";
+ String json = gson.toJson(update) + "\n";
try {
Path tmp = Files.createTempFile(createDir(buildingUpdates), taskKey, null);
logger.atFine().log("CREATE %s %s", tmp, updateLog());
@@ -260,7 +272,7 @@
}
private String updateLog() {
- return String.format("(%s:%s => %s)", update.project, update.ref, update.uri);
+ return String.format("(%s:%s => %s)", update.project(), update.ref(), update.uri());
}
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java b/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java
index 9c56c8e..a9985d2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java
@@ -34,7 +34,7 @@
return getRefs().stream()
.map(
(ref) ->
- new ReplicationTasksStorage.ReplicateRefUpdate(
+ ReplicationTasksStorage.ReplicateRefUpdate.create(
getProjectNameKey().get(), ref, getURI(), getRemoteName()))
.collect(Collectors.toList());
}
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 c32a55d..7e336d1 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFanoutIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFanoutIT.java
@@ -248,7 +248,7 @@
Pattern refmaskPattern = Pattern.compile(refRegex);
synchronized (tasksStorage) {
return Stream.concat(tasksStorage.listWaiting().stream(), tasksStorage.listRunning().stream())
- .filter(task -> refmaskPattern.matcher(task.ref).matches())
+ .filter(task -> refmaskPattern.matcher(task.ref()).matches())
.collect(toList());
}
}
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 ecc71ba..6878923 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
@@ -283,7 +283,7 @@
.scheduleFullSync(project, urlMatch, new ReplicationState(NO_OP), true);
assertThat(listIncompleteTasks(Pattern.quote(PushOne.ALL_REFS))).hasSize(1);
- streamIncompleteTasks().forEach((task) -> assertThat(task.uri).isEqualTo(expectedURI));
+ streamIncompleteTasks().forEach((task) -> assertThat(task.uri()).isEqualTo(expectedURI));
}
@Test
@@ -302,7 +302,7 @@
.scheduleFullSync(project, urlMatch, new ReplicationState(NO_OP), true);
assertThat(listIncompleteTasks()).hasSize(1);
- streamIncompleteTasks().forEach((task) -> assertThat(task.uri).isEqualTo(expectedURI));
+ streamIncompleteTasks().forEach((task) -> assertThat(task.uri()).isEqualTo(expectedURI));
}
@Test
@@ -663,8 +663,8 @@
private Stream<ReplicateRefUpdate> changeReplicationTasksForRemote(
Stream<ReplicateRefUpdate> updates, String changeRef, String remote) {
return updates
- .filter(task -> changeRef.equals(task.ref))
- .filter(task -> remote.equals(task.remote));
+ .filter(task -> changeRef.equals(task.ref()))
+ .filter(task -> remote.equals(task.remote()));
}
private Project.NameKey createTestProject(String name) throws Exception {
@@ -674,7 +674,7 @@
private List<ReplicateRefUpdate> listIncompleteTasks(String refRegex) {
Pattern refmaskPattern = Pattern.compile(refRegex);
return streamIncompleteTasks()
- .filter(task -> refmaskPattern.matcher(task.ref).matches())
+ .filter(task -> refmaskPattern.matcher(task.ref()).matches())
.collect(toList());
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java
index ca69644..af084f1 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTaskTest.java
@@ -36,7 +36,7 @@
protected static final String REMOTE = "myDest";
protected static final URIish URISH = getUrish("http://example.com/" + PROJECT + ".git");
protected static final ReplicateRefUpdate REF_UPDATE =
- new ReplicateRefUpdate(PROJECT, REF, URISH, REMOTE);
+ ReplicateRefUpdate.create(PROJECT, REF, URISH, REMOTE);
protected ReplicationTasksStorage tasksStorage;
protected FileSystem fileSystem;
@@ -200,8 +200,8 @@
@Test
public void canHaveTwoWaitingTasksForDifferentRefs() throws Exception {
- Task updateA = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, "refA", URISH, REMOTE));
- Task updateB = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, "refB", URISH, REMOTE));
+ Task updateA = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, "refA", URISH, REMOTE));
+ Task updateB = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, "refB", URISH, REMOTE));
updateA.create();
updateB.create();
assertIsWaiting(updateA);
@@ -210,8 +210,8 @@
@Test
public void canHaveTwoRunningTasksForDifferentRefs() throws Exception {
- Task updateA = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, "refA", URISH, REMOTE));
- Task updateB = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, "refB", URISH, REMOTE));
+ Task updateA = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, "refA", URISH, REMOTE));
+ Task updateB = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, "refB", URISH, REMOTE));
updateA.create();
updateB.create();
updateA.start();
@@ -225,12 +225,12 @@
Task updateA =
tasksStorage
.new Task(
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
"projectA", REF, getUrish("http://example.com/projectA.git"), REMOTE));
Task updateB =
tasksStorage
.new Task(
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
"projectB", REF, getUrish("http://example.com/projectB.git"), REMOTE));
updateA.create();
updateB.create();
@@ -243,12 +243,12 @@
Task updateA =
tasksStorage
.new Task(
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
"projectA", REF, getUrish("http://example.com/projectA.git"), REMOTE));
Task updateB =
tasksStorage
.new Task(
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
"projectB", REF, getUrish("http://example.com/projectB.git"), REMOTE));
updateA.create();
updateB.create();
@@ -260,8 +260,8 @@
@Test
public void canHaveTwoWaitingTasksForDifferentRemotes() throws Exception {
- Task updateA = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, REF, URISH, "remoteA"));
- Task updateB = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, REF, URISH, "remoteB"));
+ Task updateA = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, REF, URISH, "remoteA"));
+ Task updateB = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, REF, URISH, "remoteB"));
updateA.create();
updateB.create();
assertIsWaiting(updateA);
@@ -270,8 +270,8 @@
@Test
public void canHaveTwoRunningTasksForDifferentRemotes() throws Exception {
- Task updateA = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, REF, URISH, "remoteA"));
- Task updateB = tasksStorage.new Task(new ReplicateRefUpdate(PROJECT, REF, URISH, "remoteB"));
+ Task updateA = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, REF, URISH, "remoteA"));
+ Task updateB = tasksStorage.new Task(ReplicateRefUpdate.create(PROJECT, REF, URISH, "remoteB"));
updateA.create();
updateB.create();
updateA.start();
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java
index 0a92c76..948044b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java
@@ -17,7 +17,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
@@ -25,8 +24,6 @@
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.Path;
-import java.util.List;
-import java.util.Objects;
import org.eclipse.jgit.transport.URIish;
import org.junit.After;
import org.junit.Before;
@@ -38,7 +35,7 @@
protected static final String REMOTE = "myDest";
protected static final URIish URISH = getUrish("http://example.com/" + PROJECT + ".git");
protected static final ReplicateRefUpdate REF_UPDATE =
- new ReplicateRefUpdate(PROJECT, REF, URISH, REMOTE);
+ ReplicateRefUpdate.create(PROJECT, REF, URISH, REMOTE);
protected ReplicationTasksStorage storage;
protected FileSystem fileSystem;
@@ -67,7 +64,7 @@
@Test
public void canListWaitingUpdate() throws Exception {
storage.create(REF_UPDATE);
- assertContainsExactly(storage.listWaiting(), REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(REF_UPDATE);
}
@Test
@@ -75,7 +72,7 @@
storage.create(REF_UPDATE);
storage.start(uriUpdates);
assertThat(storage.listWaiting()).isEmpty();
- assertContainsExactly(storage.listRunning(), REF_UPDATE);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE);
}
@Test
@@ -94,14 +91,14 @@
assertThat(persistedView.listWaiting()).isEmpty();
storage.create(REF_UPDATE);
- assertContainsExactly(storage.listWaiting(), REF_UPDATE);
- assertContainsExactly(persistedView.listWaiting(), REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(REF_UPDATE);
+ assertThat(persistedView.listWaiting()).containsExactly(REF_UPDATE);
storage.start(uriUpdates);
assertThat(storage.listWaiting()).isEmpty();
assertThat(persistedView.listWaiting()).isEmpty();
- assertContainsExactly(storage.listRunning(), REF_UPDATE);
- assertContainsExactly(persistedView.listRunning(), REF_UPDATE);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE);
+ assertThat(persistedView.listRunning()).containsExactly(REF_UPDATE);
storage.finish(uriUpdates);
assertThat(storage.listRunning()).isEmpty();
@@ -113,13 +110,13 @@
String key = storage.create(REF_UPDATE);
String secondKey = storage.create(REF_UPDATE);
assertEquals(key, secondKey);
- assertContainsExactly(storage.listWaiting(), REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(REF_UPDATE);
}
@Test
public void canCreateDifferentUris() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -134,7 +131,7 @@
@Test
public void canStartDifferentUris() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -144,18 +141,18 @@
storage.create(updateB);
storage.start(uriUpdates);
- assertContainsExactly(storage.listWaiting(), updateB);
- assertContainsExactly(storage.listRunning(), REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(updateB);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE);
storage.start(uriUpdatesB);
assertThat(storage.listWaiting()).isEmpty();
- assertContainsExactly(storage.listRunning(), REF_UPDATE, updateB);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE, updateB);
}
@Test
public void canFinishDifferentUris() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -167,7 +164,7 @@
storage.start(uriUpdatesB);
storage.finish(uriUpdates);
- assertContainsExactly(storage.listRunning(), updateB);
+ assertThat(storage.listRunning()).containsExactly(updateB);
storage.finish(uriUpdatesB);
assertThat(storage.listRunning()).isEmpty();
@@ -176,7 +173,7 @@
@Test
public void differentUrisCreatedTwiceIsStoredOnce() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -191,8 +188,8 @@
@Test
public void canCreateMulipleRefsForSameUri() throws Exception {
- ReplicateRefUpdate refA = new ReplicateRefUpdate(PROJECT, "refA", URISH, REMOTE);
- ReplicateRefUpdate refB = new ReplicateRefUpdate(PROJECT, "refB", URISH, REMOTE);
+ ReplicateRefUpdate refA = ReplicateRefUpdate.create(PROJECT, "refA", URISH, REMOTE);
+ ReplicateRefUpdate refB = ReplicateRefUpdate.create(PROJECT, "refB", URISH, REMOTE);
String keyA = storage.create(refA);
String keyB = storage.create(refB);
@@ -202,8 +199,8 @@
@Test
public void canFinishMulipleRefsForSameUri() throws Exception {
- ReplicateRefUpdate refUpdateA = new ReplicateRefUpdate(PROJECT, "refA", URISH, REMOTE);
- ReplicateRefUpdate refUpdateB = new ReplicateRefUpdate(PROJECT, "refB", URISH, REMOTE);
+ ReplicateRefUpdate refUpdateA = ReplicateRefUpdate.create(PROJECT, "refA", URISH, REMOTE);
+ ReplicateRefUpdate refUpdateB = ReplicateRefUpdate.create(PROJECT, "refB", URISH, REMOTE);
UriUpdates uriUpdatesA = TestUriUpdates.create(refUpdateA);
UriUpdates uriUpdatesB = TestUriUpdates.create(refUpdateB);
storage.create(refUpdateA);
@@ -212,7 +209,7 @@
storage.start(uriUpdatesB);
storage.finish(uriUpdatesA);
- assertContainsExactly(storage.listRunning(), refUpdateB);
+ assertThat(storage.listRunning()).containsExactly(refUpdateB);
storage.finish(uriUpdatesB);
assertThat(storage.listRunning()).isEmpty();
@@ -224,7 +221,7 @@
storage.start(uriUpdates);
storage.reset(uriUpdates);
- assertContainsExactly(storage.listWaiting(), REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(REF_UPDATE);
assertThat(storage.listRunning()).isEmpty();
}
@@ -235,7 +232,7 @@
storage.reset(uriUpdates);
storage.start(uriUpdates);
- assertContainsExactly(storage.listRunning(), REF_UPDATE);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE);
assertThat(storage.listWaiting()).isEmpty();
storage.finish(uriUpdates);
@@ -254,7 +251,7 @@
storage.start(uriUpdates);
storage.resetAll();
- assertContainsExactly(storage.listWaiting(), REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(REF_UPDATE);
assertThat(storage.listRunning()).isEmpty();
}
@@ -265,7 +262,7 @@
storage.resetAll();
storage.start(uriUpdates);
- assertContainsExactly(storage.listRunning(), REF_UPDATE);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE);
assertThat(storage.listWaiting()).isEmpty();
storage.finish(uriUpdates);
@@ -275,7 +272,7 @@
@Test
public void canResetAllMultipleUpdates() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -287,13 +284,13 @@
storage.start(uriUpdatesB);
storage.resetAll();
- assertContainsExactly(storage.listWaiting(), REF_UPDATE, updateB);
+ assertThat(storage.listWaiting()).containsExactly(REF_UPDATE, updateB);
}
@Test
public void canCompleteMultipleResetAllUpdates() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -306,11 +303,11 @@
storage.resetAll();
storage.start(uriUpdates);
- assertContainsExactly(storage.listRunning(), REF_UPDATE);
- assertContainsExactly(storage.listWaiting(), updateB);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE);
+ assertThat(storage.listWaiting()).containsExactly(updateB);
storage.start(uriUpdatesB);
- assertContainsExactly(storage.listRunning(), REF_UPDATE, updateB);
+ assertThat(storage.listRunning()).containsExactly(REF_UPDATE, updateB);
assertThat(storage.listWaiting()).isEmpty();
storage.finish(uriUpdates);
@@ -335,7 +332,7 @@
@Test(expected = Test.None.class /* no exception expected */)
public void illegalDoubleFinishDifferentUriIsGraceful() throws Exception {
ReplicateRefUpdate updateB =
- new ReplicateRefUpdate(
+ ReplicateRefUpdate.create(
PROJECT,
REF,
getUrish("ssh://example.com/" + PROJECT + ".git"), // uses ssh not http
@@ -358,24 +355,6 @@
assertThat(storage.listRunning()).isEmpty();
}
- private void assertContainsExactly(
- List<ReplicateRefUpdate> all, ReplicateRefUpdate... refUpdates) {
- assertThat(all).hasSize(refUpdates.length);
- for (int i = 0; i < refUpdates.length; i++) {
- assertTrue(equals(all.get(i), refUpdates[i]));
- }
- }
-
- private boolean equals(ReplicateRefUpdate one, ReplicateRefUpdate two) {
- return (one == null && two == null)
- || (one != null
- && two != null
- && Objects.equals(one.project, two.project)
- && Objects.equals(one.ref, two.ref)
- && Objects.equals(one.remote, two.remote)
- && Objects.equals(one.uri, two.uri));
- }
-
public static URIish getUrish(String uri) {
try {
return new URIish(uri);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java b/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java
index 2fd3ee3..f61114e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java
@@ -26,10 +26,10 @@
public abstract class TestUriUpdates implements UriUpdates {
public static TestUriUpdates create(ReplicateRefUpdate update) throws URISyntaxException {
return create(
- Project.nameKey(update.project),
- new URIish(update.uri),
- update.remote,
- Collections.singleton(update.ref));
+ Project.nameKey(update.project()),
+ new URIish(update.uri()),
+ update.remote(),
+ Collections.singleton(update.ref()));
}
public static TestUriUpdates create(