Use project versioning ref name from global-refdb library Global-refdb validation framework is moved to the global-refdb library. Use generic name for project versioning ref to avoid replication. Use global-refdb version 3.3.0 Feature: Issue 13429 Change-Id: Ic2641b9efbe5d69ccfdb13ce395fc544b94f1efb
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl index 19b06b1..998d3b9 100644 --- a/external_plugin_deps.bzl +++ b/external_plugin_deps.bzl
@@ -3,8 +3,8 @@ def external_plugin_deps(): maven_jar( name = "global-refdb", - artifact = "com.gerritforge:global-refdb:3.3.0-rc1", - sha1 = "1b005b31c27a30ff10de97f903fa2834051bcadf", + artifact = "com.gerritforge:global-refdb:3.3.0", + sha1 = "8ef0600757b7468dc023c5030ce2cfeaa8ea0b64", ) maven_jar(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java index 28eddbb..42eb4e2 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java +++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
@@ -14,6 +14,7 @@ package com.googlesource.gerrit.plugins.multisite.validation; +import static com.gerritforge.gerrit.globalrefdb.validation.RefUpdateValidator.SHARED_REF_DB_VERSIONING_REF; import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; @@ -51,10 +52,11 @@ private static final Set<RefUpdate.Result> SUCCESSFUL_RESULTS = ImmutableSet.of(RefUpdate.Result.NEW, RefUpdate.Result.FORCED, RefUpdate.Result.NO_CHANGE); - public static final String MULTI_SITE_VERSIONING_REF = "refs/multi-site/version"; - public static final String MULTI_SITE_VERSIONING_VALUE_REF = "refs/multi-site/version/value"; + public static final String SHARED_REF_DB_VERSIONING_VALUE_REF = + SHARED_REF_DB_VERSIONING_REF + "/value"; public static final Ref NULL_PROJECT_VERSION_REF = - new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, MULTI_SITE_VERSIONING_REF, ObjectId.zeroId()); + new ObjectIdRef.Unpeeled( + Ref.Storage.NETWORK, SHARED_REF_DB_VERSIONING_REF, ObjectId.zeroId()); private final GitRepositoryManager gitRepositoryManager; private final GitReferenceUpdated gitReferenceUpdated; @@ -91,7 +93,7 @@ private boolean isSpecialRefName(String refName) { return refName.startsWith(RefNames.REFS_SEQUENCES) || refName.startsWith(RefNames.REFS_STARRED_CHANGES) - || refName.equals(MULTI_SITE_VERSIONING_REF); + || refName.equals(SHARED_REF_DB_VERSIONING_REF); } private void updateProducerProjectVersionUpdate(RefUpdatedEvent refUpdatedEvent) { @@ -131,7 +133,8 @@ private RefUpdate getProjectVersionRefUpdate(Repository repository, Long version) throws IOException { - RefUpdate refUpdate = repository.getRefDatabase().newUpdate(MULTI_SITE_VERSIONING_REF, false); + RefUpdate refUpdate = + repository.getRefDatabase().newUpdate(SHARED_REF_DB_VERSIONING_REF, false); refUpdate.setNewObjectId(getNewId(repository, version)); refUpdate.setForceUpdate(true); return refUpdate; @@ -150,17 +153,19 @@ Ref sharedRef = sharedRefDb - .get(projectNameKey, MULTI_SITE_VERSIONING_REF, String.class) + .get(projectNameKey, SHARED_REF_DB_VERSIONING_REF, String.class) .map( (String objectId) -> new ObjectIdRef.Unpeeled( - Ref.Storage.NEW, MULTI_SITE_VERSIONING_REF, ObjectId.fromString(objectId))) + Ref.Storage.NEW, + SHARED_REF_DB_VERSIONING_REF, + ObjectId.fromString(objectId))) .orElse( new ObjectIdRef.Unpeeled( - Ref.Storage.NEW, MULTI_SITE_VERSIONING_REF, ObjectId.zeroId())); + Ref.Storage.NEW, SHARED_REF_DB_VERSIONING_REF, ObjectId.zeroId())); Optional<Long> sharedVersion = sharedRefDb - .get(projectNameKey, MULTI_SITE_VERSIONING_VALUE_REF, String.class) + .get(projectNameKey, SHARED_REF_DB_VERSIONING_VALUE_REF, String.class) .map(Long::parseLong); try { @@ -194,7 +199,7 @@ success = sharedRefDb.compareAndPut( projectNameKey, - MULTI_SITE_VERSIONING_VALUE_REF, + SHARED_REF_DB_VERSIONING_VALUE_REF, sharedVersion.map(Object::toString).orElse(null), newVersion.toString()); if (!success) { @@ -223,7 +228,7 @@ public Optional<Long> getProjectLocalVersion(String projectName) { try (Repository repository = gitRepositoryManager.openRepository(Project.NameKey.parse(projectName))) { - Optional<IntBlob> blob = IntBlob.parse(repository, MULTI_SITE_VERSIONING_REF); + Optional<IntBlob> blob = IntBlob.parse(repository, SHARED_REF_DB_VERSIONING_REF); if (blob.isPresent()) { Long repoVersion = Integer.toUnsignedLong(blob.get().value()); logger.atFine().log("Local project '%s' has version %d", projectName, repoVersion); @@ -240,7 +245,7 @@ public Optional<Long> getProjectRemoteVersion(String projectName) { Optional<String> globalVersion = sharedRefDb.get( - Project.NameKey.parse(projectName), MULTI_SITE_VERSIONING_VALUE_REF, String.class); + Project.NameKey.parse(projectName), SHARED_REF_DB_VERSIONING_VALUE_REF, String.class); return globalVersion.flatMap(longString -> getLongValueOf(longString)); }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java index 917c6bf..11ed304 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java
@@ -14,9 +14,9 @@ package com.googlesource.gerrit.plugins.multisite.validation; +import static com.gerritforge.gerrit.globalrefdb.validation.RefUpdateValidator.SHARED_REF_DB_VERSIONING_REF; import static com.google.common.truth.Truth.assertThat; -import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF; -import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF; +import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.atMost; @@ -93,14 +93,11 @@ @Test public void producerShouldUpdateProjectVersionUponRefUpdatedEvent() throws IOException { Context.setForwardedEvent(false); - when(sharedRefDb.get( - A_TEST_PROJECT_NAME_KEY, - ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF, - String.class)) + when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_REF, String.class)) .thenReturn(Optional.of("26f7ee61bf0e470e8393c884526eec8a9b943a63")); when(sharedRefDb.get( A_TEST_PROJECT_NAME_KEY, - ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF, + ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF, String.class)) .thenReturn(Optional.of("" + (masterCommit.getCommitTime() - 1))); when(sharedRefDb.compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class))) @@ -114,7 +111,7 @@ repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter) .onEvent(refUpdatedEvent); - Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF); + Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF); verify(sharedRefDb, atMost(1)) .compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class)); @@ -138,14 +135,11 @@ Thread.sleep(1000L); repo.branch("master").update(masterCommit); - when(sharedRefDb.get( - A_TEST_PROJECT_NAME_KEY, - ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF, - String.class)) + when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_REF, String.class)) .thenReturn(Optional.of("26f7ee61bf0e470e8393c884526eec8a9b943a63")); when(sharedRefDb.get( A_TEST_PROJECT_NAME_KEY, - ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF, + ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF, String.class)) .thenReturn(Optional.of("" + (masterCommit.getCommitTime() - 1))); when(sharedRefDb.compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class))) @@ -159,7 +153,7 @@ repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter) .onEvent(refUpdatedEvent); - Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF); + Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF); verify(sharedRefDb, atMost(1)) .compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class)); @@ -177,14 +171,11 @@ public void producerShouldCreateNewProjectVersionWhenMissingUponRefUpdatedEvent() throws IOException { Context.setForwardedEvent(false); - when(sharedRefDb.get( - A_TEST_PROJECT_NAME_KEY, - ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF, - String.class)) + when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_REF, String.class)) .thenReturn(Optional.empty()); when(sharedRefDb.get( A_TEST_PROJECT_NAME_KEY, - ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF, + ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF, String.class)) .thenReturn(Optional.empty()); @@ -199,7 +190,7 @@ repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter) .onEvent(refUpdatedEvent); - Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF); + Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF); verify(sharedRefDb, atMost(1)) .compareAndPut(any(Project.NameKey.class), isNull(), any(ObjectId.class)); @@ -242,7 +233,7 @@ repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter) .onEvent(refUpdatedEvent); - Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF); + Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF); assertThat(ref).isNull(); verifyZeroInteractions(verLogger); @@ -258,7 +249,7 @@ repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter) .onEvent(refUpdatedEvent); - Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF); + Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF); assertThat(ref).isNull(); verifyZeroInteractions(verLogger); @@ -280,7 +271,7 @@ repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter) .onEvent(refUpdatedEvent); - Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF); + Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF); assertThat(ref).isNull(); verifyZeroInteractions(verLogger); @@ -288,7 +279,7 @@ @Test public void getRemoteProjectVersionShouldReturnCorrectValue() { - when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, MULTI_SITE_VERSIONING_VALUE_REF, String.class)) + when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_VALUE_REF, String.class)) .thenReturn(Optional.of("123")); Optional<Long> version =