diff options
author | Martin Fick <mfick@codeaurora.org> | 2020-10-28 19:23:19 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-10-28 19:23:19 +0000 |
commit | 53e083fd0f17d1403b4d150e66655907c1ea139d (patch) | |
tree | 7db13409efed23fc179f0efa40b394c6ec3c9f60 | |
parent | 4cb59f096b84f4369f62c8645db326c61826be79 (diff) | |
parent | 86580a0b5f52ffcf461149b610b6894f7bd12152 (diff) |
Merge "ReplicationTasksStorage: Add multi-primary unit tests" into stable-2.16v2.16.23
2 files changed, 78 insertions, 2 deletions
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java new file mode 100644 index 0000000..cc0ae04 --- /dev/null +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java @@ -0,0 +1,76 @@ +// 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 static org.junit.Assert.assertTrue; + +import com.google.common.jimfs.Configuration; +import com.google.common.jimfs.Jimfs; +import java.nio.file.FileSystem; +import java.nio.file.Path; +import org.eclipse.jgit.transport.URIish; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ReplicationTasksStorageMPTest { + protected static final String PROJECT = "myProject"; + protected static final String REF = "myRef"; + protected static final String REMOTE = "myDest"; + protected static final URIish URISH = + ReplicationTasksStorageTest.getUrish("http://example.com/" + PROJECT + ".git"); + protected static final ReplicationTasksStorage.ReplicateRefUpdate REF_UPDATE = + new ReplicationTasksStorage.ReplicateRefUpdate(PROJECT, REF, URISH, REMOTE); + + protected ReplicationTasksStorage nodeA; + protected ReplicationTasksStorage nodeB; + protected ReplicationTasksStorage persistedView; + protected FileSystem fileSystem; + protected Path storageSite; + + @Before + public void setUp() throws Exception { + fileSystem = Jimfs.newFileSystem(Configuration.unix()); + storageSite = fileSystem.getPath("replication_site"); + nodeA = new ReplicationTasksStorage(storageSite); + nodeB = new ReplicationTasksStorage(storageSite); + persistedView = new ReplicationTasksStorage(storageSite); + } + + @After + public void tearDown() throws Exception { + persistedView = null; + nodeB = null; + nodeA = null; + storageSite = null; + fileSystem.close(); + } + + @Test + public void sameRefPersistedByOtherNodeIsDeduped() { + nodeA.persist(REF_UPDATE); + + nodeB.persist(REF_UPDATE); + ReplicationTasksStorageTest.assertContainsExactly(persistedView, REF_UPDATE); + } + + @Test + public void persistedRefCanBeCompletedByOtherNode() { + nodeA.persist(REF_UPDATE); + + nodeB.delete(REF_UPDATE); + assertTrue(persistedView.list().isEmpty()); + } +} 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 3ee85d7..fd02cf8 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java @@ -202,12 +202,12 @@ public class ReplicationTasksStorageTest { assertThat(storage.list()).isEmpty(); } - private void assertContainsExactly( + public static void assertContainsExactly( ReplicationTasksStorage tasksStorage, ReplicateRefUpdate update) { assertTrue(equals(tasksStorage.list().get(0), update)); } - private boolean equals(ReplicateRefUpdate one, ReplicateRefUpdate two) { + private static boolean equals(ReplicateRefUpdate one, ReplicateRefUpdate two) { return (one == null && two == null) || (one != null && two != null |