Merge branch 'stable-3.0' into stable-3.1
* stable-3.0:
Honour index retries when indexing groups
Change-Id: Ie84aec008712435a73389d21c9c69d7aee97ec44
diff --git a/.gitignore b/.gitignore
index 4d4a78b..73f4353 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,8 +8,6 @@
/.settings/
/bazel-bin
-/bazel-genfiles
-/bazel-multi-site
/bazel-out
/bazel-reviewers
/bazel-testlogs
diff --git a/DESIGN.md b/DESIGN.md
index 3cdef94..1bbe78f 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -192,6 +192,10 @@
to push them again. However, someone needs to manually detect the issue in the
replication log and get in touch with the user.
+The [pull-replication plugin](https://gerrit.googlesource.com/plugins/pull-replication)
+supports synchronous replication and has the structure to perform also the
+asynchronous variant in the future.
+
## History and maturity level of the multi-site plugin
This plugin expands upon the excellent work on the high-availability plugin,
@@ -250,8 +254,8 @@
The current limitations of Stage #9 are:
- **Limited supports for many sites**:
- One could, potentially, support a very high number of sites, but replication lag
- to all sites could have a serious consequence in the overall perceived latency.
+ One could, potentially, support a very high number of sites, but the pull-replication
+ logic to all sites could have a serious consequence in the overall perceived latency.
Having to deal with a very high number of site requires the implementation of a quorum on
all the nodes available for replication.
@@ -648,9 +652,6 @@
- Implement more global-refdb storage layers (e.g. TiKV) and more cloud-native
message brokers (e.g. NATS)
-- Implement a synchronous pull-replication plugin for triggering the replication
- logic on all the other sites, based on Git protocol v2 upload-pack.
-
- Implement a quorum-based policy for accepting or rejecting changes in the pull-replication
plugin
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index fa6c4e7..9cbb332 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -3,12 +3,12 @@
def external_plugin_deps():
maven_jar(
name = "global-refdb",
- artifact = "com.gerritforge:global-refdb:3.0.2",
- sha1 = "293a807bd82a284c215213b442b3930258e01f5e",
+ artifact = "com.gerritforge:global-refdb:3.1.2",
+ sha1 = "6ddee3de0f3fe9254453118ae1eca481ec03e957",
)
maven_jar(
name = "events-broker",
- artifact = "com.gerritforge:events-broker:3.0.5",
- sha1 = "7abf72d2252f975baff666fbbf28b7036767aa81",
+ artifact = "com.gerritforge:events-broker:3.1.4",
+ sha1 = "5672908dde0bd02cabc95efe34a8d8507d44b6ac",
)
diff --git a/setup_local_env/configs/gerrit.config b/setup_local_env/configs/gerrit.config
index f9eca89..884b5be 100644
--- a/setup_local_env/configs/gerrit.config
+++ b/setup_local_env/configs/gerrit.config
@@ -39,7 +39,7 @@
allowRemoteAdmin = true
[plugin "websession-flatfile"]
directory = $FAKE_NFS
-[plugin "kafka-events"]
+[plugin "events-kafka"]
sendAsync = true
bootstrapServers = localhost:$KAFKA_PORT
groupId = $KAFKA_GROUP_ID
diff --git a/setup_local_env/configs/replication.config b/setup_local_env/configs/replication.config
index cf7f66a..ece1b3e 100644
--- a/setup_local_env/configs/replication.config
+++ b/setup_local_env/configs/replication.config
@@ -1,6 +1,7 @@
[remote "Replication"]
$REPLICATION_URL
push = +refs/*:refs/*
+ mirror = true
timeout = 600
rescheduleDelay = 15
replicationDelay = $REPLICATION_DELAY_SEC
diff --git a/setup_local_env/setup.sh b/setup_local_env/setup.sh
index a97afc3..87af305 100755
--- a/setup_local_env/setup.sh
+++ b/setup_local_env/setup.sh
@@ -16,9 +16,10 @@
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-GERRIT_BRANCH=stable-3.0
+GERRIT_BRANCH=stable-3.1
GERRIT_CI=https://gerrit-ci.gerritforge.com/view/Plugins-$GERRIT_BRANCH/job
LAST_BUILD=lastSuccessfulBuild/artifact/bazel-bin/plugins
+EVENTS_BROKER_VER=`grep 'com.gerritforge:events-broker' $(dirname $0)/../external_plugin_deps.bzl | cut -d '"' -f 2 | cut -d ':' -f 3`
function check_application_requirements {
type haproxy >/dev/null 2>&1 || { echo >&2 "Require haproxy but it's not installed. Aborting."; exit 1; }
@@ -356,13 +357,13 @@
ing"; exit 1; }
echo "Downloading events-broker library $GERRIT_BRANCH"
- wget https://repo1.maven.org/maven2/com/gerritforge/events-broker/3.0.5/events-broker-3.0.5.jar \
+ wget https://repo1.maven.org/maven2/com/gerritforge/events-broker/$EVENTS_BROKER_VER/events-broker-$EVENTS_BROKER_VER.jar \
-O $DEPLOYMENT_LOCATION/events-broker.jar || { echo >&2 "Cannot download events-broker library: Check internet connection. Abort\
ing"; exit 1; }
-echo "Downloading kafka-events plugin $GERRIT_BRANCH"
- wget $GERRIT_CI/plugin-kafka-events-bazel-$GERRIT_BRANCH/$LAST_BUILD/kafka-events/kafka-events.jar \
- -O $DEPLOYMENT_LOCATION/kafka-events.jar || { echo >&2 "Cannot download kafka-events plugin: Check internet connection. Abort\
+echo "Downloading events-kafka plugin $GERRIT_BRANCH"
+ wget $GERRIT_CI/plugin-events-kafka-bazel-$GERRIT_BRANCH/$LAST_BUILD/events-kafka/events-kafka.jar \
+ -O $DEPLOYMENT_LOCATION/events-kafka.jar || { echo >&2 "Cannot download events-kafka plugin: Check internet connection. Abort\
ing"; exit 1; }
echo "Downloading metrics-reporter-prometheus plugin $GERRIT_BRANCH"
@@ -412,8 +413,8 @@
echo "Copy events broker library"
cp -f $DEPLOYMENT_LOCATION/events-broker.jar $LOCATION_TEST_SITE_1/lib/events-broker.jar
- echo "Copy kafka events plugin"
- cp -f $DEPLOYMENT_LOCATION/kafka-events.jar $LOCATION_TEST_SITE_1/plugins/kafka-events.jar
+ echo "Copy events kafka plugin"
+ cp -f $DEPLOYMENT_LOCATION/events-kafka.jar $LOCATION_TEST_SITE_1/plugins/events-kafka.jar
echo "Copy metrics-reporter-prometheus plugin"
cp -f $DEPLOYMENT_LOCATION/metrics-reporter-prometheus.jar $LOCATION_TEST_SITE_1/plugins/metrics-reporter-prometheus.jar
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jProjectVersionLogger.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jProjectVersionLogger.java
index 7e38e06..c2c4b46 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jProjectVersionLogger.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jProjectVersionLogger.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.multisite;
-import com.google.gerrit.reviewdb.client.Project.NameKey;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.util.SystemLog;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -34,7 +34,7 @@
}
@Override
- public void log(NameKey projectName, long currentVersion, long replicationLag) {
+ public void log(Project.NameKey projectName, long currentVersion, long replicationLag) {
if (replicationLag > 0) {
verLog.warn(
"{ \"project\":\"{}\", \"version\":{}, \"lag\":{} }",
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jSharedRefLogger.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jSharedRefLogger.java
index 95202b5..003ce5b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jSharedRefLogger.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/Log4jSharedRefLogger.java
@@ -19,9 +19,9 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.common.GitPerson;
import com.google.gerrit.json.OutputFormat;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.CommonConverters;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.util.SystemLog;
@@ -59,8 +59,7 @@
@Override
public void logRefUpdate(String project, Ref currRef, ObjectId newRefValue) {
if (!ObjectId.zeroId().equals(newRefValue)) {
- try (Repository repository =
- gitRepositoryManager.openRepository(new Project.NameKey(project));
+ try (Repository repository = gitRepositoryManager.openRepository(Project.nameKey(project));
RevWalk walk = new RevWalk(repository)) {
GitPerson committer = null;
String commitMessage = null;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/MultiSiteMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/MultiSiteMetrics.java
new file mode 100644
index 0000000..fbe1152
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/MultiSiteMetrics.java
@@ -0,0 +1,35 @@
+// 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.multisite;
+
+import com.google.gerrit.metrics.Description;
+import com.google.gerrit.metrics.Field;
+import com.google.gerrit.server.logging.PluginMetadata;
+
+public abstract class MultiSiteMetrics {
+
+ public Field<String> stringField(String metadataKey, String description) {
+ return Field.ofString(
+ metadataKey,
+ (metadataBuilder, fieldValue) ->
+ metadataBuilder.addPluginMetadata(PluginMetadata.create(metadataKey, fieldValue)))
+ .description(description)
+ .build();
+ }
+
+ public Description rateDescription(String unit, String description) {
+ return new Description(description).setRate().setUnit(unit);
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectVersionLogger.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectVersionLogger.java
index 0ae1cc2..6ababb6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectVersionLogger.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectVersionLogger.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.multisite;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
public interface ProjectVersionLogger {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/SharedRefDatabaseWrapper.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/SharedRefDatabaseWrapper.java
index 0ea78a9..b56f2ea 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/SharedRefDatabaseWrapper.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/SharedRefDatabaseWrapper.java
@@ -18,8 +18,8 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException;
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
import com.google.common.annotations.VisibleForTesting;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.registration.DynamicItem;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/broker/BrokerMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/broker/BrokerMetrics.java
index f6be65a..1d9f46d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/broker/BrokerMetrics.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/broker/BrokerMetrics.java
@@ -15,14 +15,13 @@
package com.googlesource.gerrit.plugins.multisite.broker;
import com.google.gerrit.metrics.Counter1;
-import com.google.gerrit.metrics.Description;
-import com.google.gerrit.metrics.Field;
import com.google.gerrit.metrics.MetricMaker;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import com.googlesource.gerrit.plugins.multisite.MultiSiteMetrics;
@Singleton
-public class BrokerMetrics {
+public class BrokerMetrics extends MultiSiteMetrics {
private static final String PUBLISHER_SUCCESS_COUNTER = "broker_msg_publisher_counter";
private static final String PUBLISHER_FAILURE_COUNTER = "broker_msg_publisher_failure_counter";
@@ -35,17 +34,15 @@
this.brokerPublisherSuccessCounter =
metricMaker.newCounter(
"multi_site/broker/broker_message_publisher_counter",
- new Description("Number of messages published by the broker publisher")
- .setRate()
- .setUnit("messages"),
- Field.ofString(PUBLISHER_SUCCESS_COUNTER, "Broker message published count"));
+ rateDescription("messages", "Number of messages published by the broker publisher"),
+ stringField(PUBLISHER_SUCCESS_COUNTER, "Broker message published count"));
+
this.brokerPublisherFailureCounter =
metricMaker.newCounter(
"multi_site/broker/broker_message_publisher_failure_counter",
- new Description("Number of messages failed to publish by the broker publisher")
- .setRate()
- .setUnit("errors"),
- Field.ofString(PUBLISHER_FAILURE_COUNTER, "Broker failed to publish message count"));
+ rateDescription(
+ "errors", "Number of messages failed to publish by the broker publisher"),
+ stringField(PUBLISHER_FAILURE_COUNTER, "Broker failed to publish message count"));
}
public void incrementBrokerPublishedMessage() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java
index 1474262..4459859 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java
@@ -16,15 +16,15 @@
import com.gerritforge.gerrit.eventbroker.EventMessage;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.metrics.Counter1;
import com.google.gerrit.metrics.Description;
-import com.google.gerrit.metrics.Field;
import com.google.gerrit.metrics.MetricMaker;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import com.googlesource.gerrit.plugins.multisite.MultiSiteMetrics;
import com.googlesource.gerrit.plugins.multisite.ProjectVersionLogger;
import com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate;
import com.googlesource.gerrit.plugins.replication.RefReplicatedEvent;
@@ -37,7 +37,7 @@
import java.util.Optional;
@Singleton
-public class SubscriberMetrics {
+public class SubscriberMetrics extends MultiSiteMetrics {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String SUBSCRIBER_SUCCESS_COUNTER = "subscriber_msg_consumer_counter";
private static final String SUBSCRIBER_FAILURE_COUNTER =
@@ -67,15 +67,14 @@
new Description("Number of messages consumed by the subscriber")
.setRate()
.setUnit("messages"),
- Field.ofString(SUBSCRIBER_SUCCESS_COUNTER, "Subscriber message consumed count"));
+ stringField(SUBSCRIBER_SUCCESS_COUNTER, "Subscriber message consumed count"));
this.subscriberFailureCounter =
metricMaker.newCounter(
"multi_site/subscriber/subscriber_message_consumer_failure_counter",
new Description("Number of messages failed to consume by the subscriber consumer")
.setRate()
.setUnit("errors"),
- Field.ofString(
- SUBSCRIBER_FAILURE_COUNTER, "Subscriber failed to consume messages count"));
+ stringField(SUBSCRIBER_FAILURE_COUNTER, "Subscriber failed to consume messages count"));
metricMaker.newCallbackMetric(
REPLICATION_LAG_SEC,
Long.class,
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandler.java
index 6d1d6cf..5212aa4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandler.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.server.index.account.AccountIndexer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandler.java
index 8340a5f..8d41500 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandler.java
@@ -15,7 +15,7 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import com.google.common.base.Splitter;
-import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.entities.Change;
import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.util.ManualRequestContext;
@@ -23,15 +23,12 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.googlesource.gerrit.plugins.multisite.Configuration;
-import com.googlesource.gerrit.plugins.multisite.Configuration.Index;
import com.googlesource.gerrit.plugins.multisite.forwarder.events.ChangeIndexEvent;
import com.googlesource.gerrit.plugins.multisite.index.ChangeChecker;
import com.googlesource.gerrit.plugins.multisite.index.ChangeCheckerImpl;
import com.googlesource.gerrit.plugins.multisite.index.ForwardedIndexExecutor;
import java.util.Optional;
-import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
/**
* Index a change using {@link ChangeIndexer}. This class is meant to be used on the receiving side
@@ -41,12 +38,8 @@
*/
@Singleton
public class ForwardedIndexChangeHandler
- extends ForwardedIndexingHandler<String, ChangeIndexEvent> {
+ extends ForwardedIndexingHandlerWithRetries<String, ChangeIndexEvent> {
private final ChangeIndexer indexer;
- private final ScheduledExecutorService indexExecutor;
- private final OneOffRequestContext oneOffCtx;
- private final int retryInterval;
- private final int maxTries;
private final ChangeCheckerImpl.Factory changeCheckerFactory;
@Inject
@@ -56,43 +49,22 @@
@ForwardedIndexExecutor ScheduledExecutorService indexExecutor,
OneOffRequestContext oneOffCtx,
ChangeCheckerImpl.Factory changeCheckerFactory) {
- super(configuration.index().numStripedLocks());
+ super(indexExecutor, configuration, oneOffCtx);
this.indexer = indexer;
- this.indexExecutor = indexExecutor;
- this.oneOffCtx = oneOffCtx;
this.changeCheckerFactory = changeCheckerFactory;
-
- Index indexConfig = configuration.index();
- this.retryInterval = indexConfig != null ? indexConfig.retryInterval() : 0;
- this.maxTries = indexConfig != null ? indexConfig.maxTries() : 0;
}
@Override
protected void doIndex(String id, Optional<ChangeIndexEvent> indexEvent) {
- doIndex(id, indexEvent, 0);
+ attemptToIndex(id, indexEvent, 0);
}
- private void doIndex(String id, Optional<ChangeIndexEvent> indexEvent, int retryCount) {
+ @Override
+ protected void attemptToIndex(String id, Optional<ChangeIndexEvent> indexEvent, int retryCount) {
ChangeChecker checker = changeCheckerFactory.create(id);
Optional<ChangeNotes> changeNotes = checker.getChangeNotes();
if (changeNotes.isPresent()) {
- ChangeNotes notes = changeNotes.get();
- reindex(notes);
-
- if (checker.isChangeUpToDate(indexEvent)) {
- if (retryCount > 0) {
- log.warn("Change {} has been eventually indexed after {} attempt(s)", id, retryCount);
- } else {
- log.debug("Change {} successfully indexed", id);
- }
- } else {
- log.warn(
- "Change {} seems too old compared to the event timestamp (event={} >> change-Ts={})",
- id,
- indexEvent,
- checker);
- rescheduleIndex(id, indexEvent, retryCount + 1);
- }
+ reindexAndCheckIsUpToDate(id, indexEvent, checker, retryCount);
} else {
log.warn(
"Change {} not present yet in local Git repository (event={}) after {} attempt(s)",
@@ -106,42 +78,20 @@
}
}
- private void reindex(ChangeNotes notes) {
+ @Override
+ protected void reindex(String id) {
try (ManualRequestContext ctx = oneOffCtx.open()) {
+ ChangeChecker checker = changeCheckerFactory.create(id);
+ Optional<ChangeNotes> changeNotes = checker.getChangeNotes();
+ ChangeNotes notes = changeNotes.get();
notes.reload();
indexer.index(notes.getChange());
}
}
- private boolean rescheduleIndex(
- String id, Optional<ChangeIndexEvent> indexEvent, int retryCount) {
- if (retryCount > maxTries) {
- log.error(
- "Change {} could not be indexed after {} retries. Change index could be stale.",
- id,
- retryCount);
- return false;
- }
-
- log.warn(
- "Retrying for the #{} time to index Change {} after {} msecs",
- retryCount,
- id,
- retryInterval);
- @SuppressWarnings("unused")
- Future<?> possiblyIgnoredError =
- indexExecutor.schedule(
- () -> {
- try (ManualRequestContext ctx = oneOffCtx.open()) {
- Context.setForwardedEvent(true);
- doIndex(id, indexEvent, retryCount);
- } catch (Exception e) {
- log.warn("Change {} could not be indexed", id, e);
- }
- },
- retryInterval,
- TimeUnit.MILLISECONDS);
- return true;
+ @Override
+ protected String indexName() {
+ return "change";
}
@Override
@@ -151,7 +101,7 @@
}
private static Change.Id parseChangeId(String id) {
- Change.Id changeId = new Change.Id(Integer.parseInt(Splitter.on("~").splitToList(id).get(1)));
+ Change.Id changeId = Change.id(Integer.parseInt(Splitter.on("~").splitToList(id).get(1)));
return changeId;
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandler.java
index f9423b5..c4906a9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandler.java
@@ -14,8 +14,9 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.server.index.group.GroupIndexer;
+import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.googlesource.gerrit.plugins.multisite.Configuration;
@@ -23,9 +24,7 @@
import com.googlesource.gerrit.plugins.multisite.index.ForwardedIndexExecutor;
import com.googlesource.gerrit.plugins.multisite.index.GroupChecker;
import java.util.Optional;
-import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
/**
* Index a group using {@link GroupIndexer}. This class is meant to be used on the receiving side of
@@ -34,76 +33,42 @@
* done for the same group uuid
*/
@Singleton
-public class ForwardedIndexGroupHandler extends ForwardedIndexingHandler<String, GroupIndexEvent> {
+public class ForwardedIndexGroupHandler
+ extends ForwardedIndexingHandlerWithRetries<String, GroupIndexEvent> {
private final GroupIndexer indexer;
private final GroupChecker groupChecker;
- private final ScheduledExecutorService indexExecutor;
- private final int retryInterval;
- private final int maxTries;
@Inject
ForwardedIndexGroupHandler(
GroupIndexer indexer,
Configuration config,
GroupChecker groupChecker,
+ OneOffRequestContext oneOffRequestContext,
@ForwardedIndexExecutor ScheduledExecutorService indexExecutor) {
- super(config.index().numStripedLocks());
+ super(indexExecutor, config, oneOffRequestContext);
this.indexer = indexer;
this.groupChecker = groupChecker;
- this.indexExecutor = indexExecutor;
- Configuration.Index indexConfig = config.index();
- this.retryInterval = indexConfig != null ? indexConfig.retryInterval() : 0;
- this.maxTries = indexConfig != null ? indexConfig.maxTries() : 0;
}
@Override
protected void doIndex(String uuid, Optional<GroupIndexEvent> event) {
- doIndex(uuid, event, 0);
+ attemptToIndex(uuid, event, 0);
}
- protected void doIndex(String uuid, Optional<GroupIndexEvent> groupIndexEvent, int retryCount) {
- indexer.index(new AccountGroup.UUID(uuid));
- if (groupChecker.isGroupUpToDate(groupIndexEvent)) {
- if (retryCount > 0) {
- log.warn("Group '{}' has been eventually indexed after {} attempt(s)", uuid, retryCount);
- } else {
- log.debug("Group '{}' successfully indexed", uuid);
- }
- } else {
- log.debug("Group '{}' rescheduling indexing", uuid);
- rescheduleIndex(uuid, groupIndexEvent, retryCount + 1);
- }
+ @Override
+ protected void reindex(String id) {
+ indexer.index(AccountGroup.uuid(id));
}
- private boolean rescheduleIndex(
- String uuid, Optional<GroupIndexEvent> indexEvent, int retryCount) {
- if (retryCount > maxTries) {
- log.error(
- "Group '{}' could not be indexed after {} retries. Group index could be stale.",
- uuid,
- retryCount);
- return false;
- }
+ @Override
+ protected String indexName() {
+ return "group";
+ }
- log.warn(
- "Retrying for the #{} time to index Group {} after {} msecs",
- retryCount,
- uuid,
- retryInterval);
- @SuppressWarnings("unused")
- Future<?> possiblyIgnoredError =
- indexExecutor.schedule(
- () -> {
- try {
- Context.setForwardedEvent(true);
- doIndex(uuid, indexEvent, retryCount);
- } catch (Exception e) {
- log.warn("Group {} could not be indexed", uuid, e);
- }
- },
- retryInterval,
- TimeUnit.MILLISECONDS);
- return true;
+ @Override
+ protected void attemptToIndex(
+ String uuid, Optional<GroupIndexEvent> groupIndexEvent, int retryCount) {
+ reindexAndCheckIsUpToDate(uuid, groupIndexEvent, groupChecker, retryCount);
}
@Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java
index e5f7e10..3787a80 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java
@@ -14,8 +14,9 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.index.project.ProjectIndexer;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.googlesource.gerrit.plugins.multisite.Configuration;
@@ -24,7 +25,6 @@
import com.googlesource.gerrit.plugins.multisite.index.ProjectChecker;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
/**
* Index a project using {@link ProjectIndexer}. This class is meant to be used on the receiving
@@ -34,78 +34,40 @@
*/
@Singleton
public class ForwardedIndexProjectHandler
- extends ForwardedIndexingHandler<String, ProjectIndexEvent> {
+ extends ForwardedIndexingHandlerWithRetries<String, ProjectIndexEvent> {
private final ProjectIndexer indexer;
- private final int retryInterval;
- private final int maxTries;
private final ProjectChecker projectChecker;
- private final ScheduledExecutorService indexExecutor;
@Inject
ForwardedIndexProjectHandler(
ProjectIndexer indexer,
ProjectChecker projectChecker,
+ OneOffRequestContext oneOffRequestContext,
@ForwardedIndexExecutor ScheduledExecutorService indexExecutor,
Configuration config) {
- super(config.index().numStripedLocks());
+ super(indexExecutor, config, oneOffRequestContext);
this.indexer = indexer;
- Configuration.Index indexConfig = config.index();
- this.retryInterval = indexConfig != null ? indexConfig.retryInterval() : 0;
- this.maxTries = indexConfig != null ? indexConfig.maxTries() : 0;
- this.indexExecutor = indexExecutor;
this.projectChecker = projectChecker;
}
@Override
protected void doIndex(String projectName, Optional<ProjectIndexEvent> event) {
- if (!attemptIndex(projectName, event)) {
- log.warn("First Attempt failed, scheduling again after {} msecs", retryInterval);
- rescheduleIndex(projectName, event, 1);
- }
+ attemptToIndex(projectName, event, 0);
}
- public boolean attemptIndex(String projectName, Optional<ProjectIndexEvent> event) {
- log.debug("Attempt to index project {}, event: [{}]", projectName, event);
- final Project.NameKey projectNameKey = new Project.NameKey(projectName);
- if (projectChecker.isProjectUpToDate(projectNameKey)) {
- indexer.index(projectNameKey);
- log.debug("Project {} successfully indexed", projectName);
- return true;
- }
- return false;
+ @Override
+ protected void reindex(String id) {
+ indexer.index(Project.nameKey(id));
}
- public void rescheduleIndex(
- String projectName, Optional<ProjectIndexEvent> event, int retryCount) {
- if (retryCount > maxTries) {
- log.error(
- "Project {} could not be indexed after {} retries. index could be stale.",
- projectName,
- retryCount);
+ @Override
+ protected String indexName() {
+ return "project";
+ }
- return;
- }
-
- log.warn(
- "Retrying for the #{} time to index project {} after {} msecs",
- retryCount,
- projectName,
- retryInterval);
-
- indexExecutor.schedule(
- () -> {
- Context.setForwardedEvent(true);
- if (!attemptIndex(projectName, event)) {
- log.warn(
- "Attempt {} to index project {} failed, scheduling again after {} msecs",
- retryCount,
- projectName,
- retryInterval);
- rescheduleIndex(projectName, event, retryCount + 1);
- }
- },
- retryInterval,
- TimeUnit.MILLISECONDS);
+ @Override
+ protected void attemptToIndex(String id, Optional<ProjectIndexEvent> indexEvent, int retryCount) {
+ reindexAndCheckIsUpToDate(id, indexEvent, projectChecker, retryCount);
}
@Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexingHandlerWithRetries.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexingHandlerWithRetries.java
new file mode 100644
index 0000000..5c64431
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexingHandlerWithRetries.java
@@ -0,0 +1,109 @@
+// Copyright (C) 2021 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.multisite.forwarder;
+
+import com.google.gerrit.server.util.ManualRequestContext;
+import com.google.gerrit.server.util.OneOffRequestContext;
+import com.googlesource.gerrit.plugins.multisite.Configuration;
+import com.googlesource.gerrit.plugins.multisite.forwarder.events.IndexEvent;
+import com.googlesource.gerrit.plugins.multisite.index.UpToDateChecker;
+import java.util.Optional;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Base class to handle forwarded indexing. This class is meant to be extended by classes used on
+ * the receiving side of the {@link IndexEvent} since it will prevent indexing to be forwarded again
+ * causing an infinite forwarding loop between the 2 nodes. It will also make sure no concurrent
+ * indexing is done for the same id.
+ */
+public abstract class ForwardedIndexingHandlerWithRetries<T, E extends IndexEvent>
+ extends ForwardedIndexingHandler<T, E> {
+
+ private final int retryInterval;
+ private final int maxTries;
+ private final ScheduledExecutorService indexExecutor;
+ protected final OneOffRequestContext oneOffCtx;
+
+ ForwardedIndexingHandlerWithRetries(
+ ScheduledExecutorService indexExecutor,
+ Configuration configuration,
+ OneOffRequestContext oneOffCtx) {
+ super(configuration.index().numStripedLocks());
+
+ Configuration.Index indexConfig = configuration.index();
+ this.oneOffCtx = oneOffCtx;
+ this.indexExecutor = indexExecutor;
+ this.retryInterval = indexConfig != null ? indexConfig.retryInterval() : 0;
+ this.maxTries = indexConfig != null ? indexConfig.maxTries() : 0;
+ }
+
+ protected abstract void reindex(T id);
+
+ protected abstract String indexName();
+
+ protected abstract void attemptToIndex(T id, Optional<E> indexEvent, int retryCount);
+
+ protected boolean rescheduleIndex(T id, Optional<E> indexEvent, int retryCount) {
+ if (retryCount > maxTries) {
+ log.error(
+ "{} {} could not be indexed after {} retries. {} index could be stale.",
+ indexName(),
+ id,
+ retryCount,
+ indexName());
+ return false;
+ }
+
+ log.warn(
+ "Retrying for the #{} time to index {} {} after {} msecs",
+ retryCount,
+ indexName(),
+ id,
+ retryInterval);
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ indexExecutor.schedule(
+ () -> {
+ try (ManualRequestContext ctx = oneOffCtx.open()) {
+ Context.setForwardedEvent(true);
+ attemptToIndex(id, indexEvent, retryCount);
+ } catch (Exception e) {
+ log.warn("{} {} could not be indexed", indexName(), id, e);
+ }
+ },
+ retryInterval,
+ TimeUnit.MILLISECONDS);
+ return true;
+ }
+
+ public final void reindexAndCheckIsUpToDate(
+ T id, Optional<E> indexEvent, UpToDateChecker<E> upToDateChecker, int retryCount) {
+ reindex(id);
+
+ if (!upToDateChecker.isUpToDate(indexEvent)) {
+ log.warn("{} {} is not up-to-date. Rescheduling", indexName(), id);
+ rescheduleIndex(id, indexEvent, retryCount + 1);
+ return;
+ }
+ if (retryCount > 0) {
+ log.warn(
+ "{} {} has been eventually indexed after {} attempt(s)", indexName(), id, retryCount);
+ } else {
+ log.debug("{} {} successfully indexed", indexName(), id);
+ }
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandler.java
index 30b2b35..919a64f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandler.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -47,7 +47,7 @@
* @throws IOException
*/
public void update(ProjectListUpdateEvent event) throws IOException {
- Project.NameKey projectKey = new Project.NameKey(event.projectName);
+ Project.NameKey projectKey = Project.nameKey(event.projectName);
try {
Context.setForwardedEvent(true);
if (event.remove) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParser.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParser.java
index ddc184a..0bbdada 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParser.java
@@ -15,31 +15,36 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import com.google.common.base.MoreObjects;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.server.events.EventGson;
import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.multisite.cache.Constants;
public final class GsonParser {
+ private final Gson gson;
- private GsonParser() {}
+ @Inject
+ public GsonParser(@EventGson Gson gson) {
+ this.gson = gson;
+ }
@SuppressWarnings("cast")
- public static Object fromJson(String cacheName, Object json) {
- Gson gson = new GsonBuilder().create();
+ public Object fromJson(String cacheName, Object json) {
Object key;
// Need to add a case for 'adv_bases'
switch (cacheName) {
case Constants.ACCOUNTS:
- key = gson.fromJson(nullToEmpty(json).toString().trim(), Account.Id.class);
+ key = Account.id(jsonElement(json).getAsJsonObject().get("id").getAsInt());
break;
case Constants.GROUPS:
- key = gson.fromJson(nullToEmpty(json).toString().trim(), AccountGroup.Id.class);
+ key = AccountGroup.id(jsonElement(json).getAsJsonObject().get("id").getAsInt());
break;
case Constants.GROUPS_BYINCLUDE:
case Constants.GROUPS_MEMBERS:
- key = gson.fromJson(nullToEmpty(json).toString().trim(), AccountGroup.UUID.class);
+ key = AccountGroup.uuid(jsonElement(json).getAsJsonObject().get("uuid").getAsString());
break;
case Constants.PROJECT_LIST:
key = gson.fromJson(nullToEmpty(json).toString(), Object.class);
@@ -58,33 +63,11 @@
return key;
}
- public static String toJson(String cacheName, Object key) {
- Gson gson = new GsonBuilder().create();
- String json;
- // Need to add a case for 'adv_bases'
- switch (cacheName) {
- case Constants.ACCOUNTS:
- json = gson.toJson(key, Account.Id.class);
- break;
- case Constants.GROUPS:
- json = gson.toJson(key, AccountGroup.Id.class);
- break;
- case Constants.GROUPS_BYINCLUDE:
- case Constants.GROUPS_MEMBERS:
- json = gson.toJson(key, AccountGroup.UUID.class);
- break;
- case Constants.PROJECT_LIST:
- default:
- if (key instanceof String) {
- json = (String) key;
- } else {
- json = gson.toJson(key);
- }
- }
- return json;
+ private JsonElement jsonElement(Object json) {
+ return gson.fromJson(nullToEmpty(json), JsonElement.class);
}
- private static Object nullToEmpty(Object value) {
- return MoreObjects.firstNonNull(value, "");
+ private static String nullToEmpty(Object value) {
+ return MoreObjects.firstNonNull(value, "").toString().trim();
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/CacheEvictionEventRouter.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/CacheEvictionEventRouter.java
index a6cd8c4..0fb0c0a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/CacheEvictionEventRouter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/CacheEvictionEventRouter.java
@@ -23,15 +23,18 @@
public class CacheEvictionEventRouter implements ForwardedEventRouter<CacheEvictionEvent> {
private final ForwardedCacheEvictionHandler cacheEvictionHanlder;
+ private final GsonParser gsonParser;
@Inject
- public CacheEvictionEventRouter(ForwardedCacheEvictionHandler cacheEvictionHanlder) {
+ public CacheEvictionEventRouter(
+ ForwardedCacheEvictionHandler cacheEvictionHanlder, GsonParser gsonParser) {
this.cacheEvictionHanlder = cacheEvictionHanlder;
+ this.gsonParser = gsonParser;
}
@Override
public void route(CacheEvictionEvent cacheEvictionEvent) throws CacheNotFoundException {
- Object parsedKey = GsonParser.fromJson(cacheEvictionEvent.cacheName, cacheEvictionEvent.key);
+ Object parsedKey = gsonParser.fromJson(cacheEvictionEvent.cacheName, cacheEvictionEvent.key);
cacheEvictionHanlder.evict(CacheEntry.from(cacheEvictionEvent.cacheName, parsedKey));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/IndexEventRouter.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/IndexEventRouter.java
index 6ab8c72..202fb42 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/IndexEventRouter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/router/IndexEventRouter.java
@@ -18,9 +18,8 @@
import static com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedIndexingHandler.Operation.INDEX;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.extensions.events.LifecycleListener;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Account.Id;
import com.google.gerrit.server.config.AllUsersName;
import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedIndexAccountHandler;
@@ -72,7 +71,7 @@
Optional.of(changeIndexEvent));
} else if (sourceEvent instanceof AccountIndexEvent) {
AccountIndexEvent accountIndexEvent = (AccountIndexEvent) sourceEvent;
- indexAccountHandler.indexAsync(new Account.Id(accountIndexEvent.accountId), INDEX);
+ indexAccountHandler.indexAsync(Account.id(accountIndexEvent.accountId), INDEX);
} else if (sourceEvent instanceof GroupIndexEvent) {
GroupIndexEvent groupIndexEvent = (GroupIndexEvent) sourceEvent;
indexGroupHandler.index(groupIndexEvent.groupUUID, INDEX, Optional.of(groupIndexEvent));
@@ -102,13 +101,13 @@
@Override
public void stop() {
- Set<Id> accountsToIndex = indexAccountHandler.pendingAccountsToIndex();
+ Set<Account.Id> accountsToIndex = indexAccountHandler.pendingAccountsToIndex();
if (!accountsToIndex.isEmpty()) {
logger.atWarning().log("Forcing reindex of accounts %s upon shutdown", accountsToIndex);
indexAccountHandler.doAsyncIndex();
}
- Set<Id> accountsIndexFailed = indexAccountHandler.pendingAccountsToIndex();
+ Set<Account.Id> accountsIndexFailed = indexAccountHandler.pendingAccountsToIndex();
if (!accountsIndexFailed.isEmpty()) {
logger.atSevere().log(
"The accounts %s failed to be indexed and their Lucene index is stale",
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeChecker.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeChecker.java
index 3646b3a..9ee59eb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeChecker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeChecker.java
@@ -20,7 +20,7 @@
import java.util.Optional;
/** Encapsulates the logic of verifying the up-to-date status of a change. */
-public interface ChangeChecker {
+public interface ChangeChecker extends UpToDateChecker<ChangeIndexEvent> {
/**
* Return the Change nodes read from ReviewDb or NoteDb.
@@ -48,7 +48,7 @@
* @param indexEvent indexing event
* @return true if the local Change is up-to-date, false otherwise.
*/
- public boolean isChangeUpToDate(Optional<ChangeIndexEvent> indexEvent);
+ public boolean isUpToDate(Optional<ChangeIndexEvent> indexEvent);
/**
* Return the last computed up-to-date Change time-stamp.
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java
index f1e80cc..6ba18ed 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java
@@ -14,9 +14,9 @@
package com.googlesource.gerrit.plugins.multisite.index;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Comment;
import com.google.gerrit.exceptions.StorageException;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Comment;
import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeFinder;
import com.google.gerrit.server.git.GitRepositoryManager;
@@ -85,7 +85,7 @@
}
@Override
- public boolean isChangeUpToDate(Optional<ChangeIndexEvent> indexEvent) {
+ public boolean isUpToDate(Optional<ChangeIndexEvent> indexEvent) {
getComputedChangeTs();
if (!computedChangeTs.isPresent()) {
log.warn("Unable to compute last updated ts for change {}", changeId);
@@ -126,7 +126,7 @@
private String getBranchTargetSha() {
try {
try (Repository repo = gitRepoMgr.openRepository(changeNotes.get().getProjectName())) {
- String refName = changeNotes.get().getChange().getDest().get();
+ String refName = changeNotes.get().getChange().getDest().branch();
Ref ref = repo.exactRef(refName);
if (ref == null) {
log.warn("Unable to find target ref {} for change {}", refName, changeId);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupChecker.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupChecker.java
index 03ac30c..c19d04a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupChecker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupChecker.java
@@ -18,8 +18,10 @@
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
-public interface GroupChecker {
- boolean isGroupUpToDate(Optional<GroupIndexEvent> groupIndexEvent);
+public interface GroupChecker extends UpToDateChecker<GroupIndexEvent> {
+
+ @Override
+ boolean isUpToDate(Optional<GroupIndexEvent> groupIndexEvent);
ObjectId getGroupHead(String groupUUID);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImpl.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImpl.java
index 5e2a039..e9e40f3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImpl.java
@@ -16,8 +16,8 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.AccountGroup;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
@@ -44,13 +44,13 @@
}
@Override
- public boolean isGroupUpToDate(Optional<GroupIndexEvent> groupIndexEvent) {
+ public boolean isUpToDate(Optional<GroupIndexEvent> groupIndexEvent) {
if (!groupIndexEvent.isPresent()) {
logger.atWarning().log("Group Index empty, considering this group up-to-date");
return true;
}
GroupIndexEvent event = groupIndexEvent.get();
- AccountGroup.UUID groupUUID = new AccountGroup.UUID(event.groupUUID);
+ AccountGroup.UUID groupUUID = AccountGroup.uuid(event.groupUUID);
if (event.sha1 == null) {
logger.atWarning().log(
@@ -79,8 +79,7 @@
@Override
public ObjectId getGroupHead(String groupUUID) {
try (Repository repo = repoManager.openRepository(allUsers)) {
- return Optional.ofNullable(
- repo.exactRef(RefNames.refsGroups(new AccountGroup.UUID(groupUUID))))
+ return Optional.ofNullable(repo.exactRef(RefNames.refsGroups(AccountGroup.uuid(groupUUID))))
.map(Ref::getObjectId)
.orElse(ObjectId.zeroId());
} catch (Exception e) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectChecker.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectChecker.java
index 3fabbbd..e040fce 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectChecker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectChecker.java
@@ -14,9 +14,7 @@
package com.googlesource.gerrit.plugins.multisite.index;
-import com.google.gerrit.reviewdb.client.Project;
+import com.googlesource.gerrit.plugins.multisite.forwarder.events.ProjectIndexEvent;
/** Encapsulates the logic of verifying the up-to-date status of a project. */
-public interface ProjectChecker {
- boolean isProjectUpToDate(Project.NameKey projectName);
-}
+public interface ProjectChecker extends UpToDateChecker<ProjectIndexEvent> {}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectCheckerImpl.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectCheckerImpl.java
index 606ff9d..ba2a7d6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectCheckerImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ProjectCheckerImpl.java
@@ -14,9 +14,11 @@
package com.googlesource.gerrit.plugins.multisite.index;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
+import com.googlesource.gerrit.plugins.multisite.forwarder.events.ProjectIndexEvent;
+import java.util.Optional;
public class ProjectCheckerImpl implements ProjectChecker {
private final ProjectCache projectCache;
@@ -27,7 +29,7 @@
}
@Override
- public boolean isProjectUpToDate(Project.NameKey projectName) {
- return projectCache.get(projectName) != null;
+ public boolean isUpToDate(Optional<ProjectIndexEvent> indexEvent) {
+ return indexEvent.map(e -> Project.nameKey(e.projectName)).map(projectCache::get).isPresent();
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/UpToDateChecker.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/UpToDateChecker.java
new file mode 100644
index 0000000..8a7a231
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/UpToDateChecker.java
@@ -0,0 +1,28 @@
+// Copyright (C) 2021 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.multisite.index;
+
+import com.googlesource.gerrit.plugins.multisite.forwarder.events.IndexEvent;
+import java.util.Optional;
+
+public interface UpToDateChecker<E extends IndexEvent> {
+ /**
+ * Check if the local Change is aligned with the indexEvent received.
+ *
+ * @param indexEvent indexing event
+ * @return true if the local Change is up-to-date, false otherwise.
+ */
+ boolean isUpToDate(Optional<E> indexEvent);
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteGitRepositoryManager.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteGitRepositoryManager.java
index 594b4a0..6ece734 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteGitRepositoryManager.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteGitRepositoryManager.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.multisite.validation;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
import com.google.gerrit.server.git.RepositoryCaseMismatchException;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRepository.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRepository.java
index b3678c6..fa3de64 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRepository.java
@@ -53,7 +53,6 @@
public class MultiSiteRepository extends Repository {
- private final MultiSiteRefDatabase.Factory multiSiteRefDbFactory;
private final Repository repository;
private final RefDatabase refDatabase;
private final MultiSiteRefDatabase multiSiteRefDatabase;
@@ -68,7 +67,6 @@
@Assisted String projectName,
@Assisted Repository repository) {
super(new BaseRepositoryBuilder());
- this.multiSiteRefDbFactory = multiSiteRefDbFactory;
this.repository = repository;
this.refDatabase = repository.getRefDatabase();
this.multiSiteRefDatabase = multiSiteRefDbFactory.create(projectName, refDatabase);
@@ -157,6 +155,7 @@
return repository.getFS();
}
+ @SuppressWarnings("deprecation")
@Override
public boolean hasObject(AnyObjectId objectId) {
return repository.hasObject(objectId);
@@ -230,16 +229,19 @@
return repository.getAdditionalHaves();
}
+ @SuppressWarnings("deprecation")
@Override
public Map<String, Ref> getAllRefs() {
return repository.getAllRefs();
}
+ @SuppressWarnings("deprecation")
@Override
public Map<String, Ref> getTags() {
return repository.getTags();
}
+ @SuppressWarnings("deprecation")
@Override
public Ref peel(Ref ref) {
return repository.peel(ref);
@@ -397,4 +399,9 @@
public void autoGC(ProgressMonitor monitor) {
repository.autoGC(monitor);
}
+
+ @Override
+ public String getIdentifier() {
+ return repository.getIdentifier();
+ }
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java
index b666c02..f831671 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java
@@ -17,7 +17,7 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException;
import com.google.common.base.Preconditions;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -63,7 +63,7 @@
Set<String> outdatedChanges = new HashSet<>();
try (Repository repository =
- gitRepositoryManager.openRepository(Project.NameKey.parse(projectName))) {
+ gitRepositoryManager.openRepository(Project.nameKey(projectName))) {
List<RemoteRefUpdate> filteredRefUpdates =
remoteUpdatesList.stream()
.filter(
@@ -107,7 +107,7 @@
String ref = refUpdate.getSrcRef();
try {
if (sharedRefDb.isUpToDate(
- new Project.NameKey(projectName),
+ Project.nameKey(projectName),
new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, ref, refUpdate.getNewObjectId()))) {
return true;
}
@@ -116,7 +116,7 @@
projectName, refUpdate, ref);
return sharedRefDb.isUpToDate(
- new Project.NameKey(projectName),
+ Project.nameKey(projectName),
new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, ref, getNotNullExactRef(repository, ref)));
} catch (GlobalRefDbLockException gle) {
String message =
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectDeletedSharedDbCleanup.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectDeletedSharedDbCleanup.java
index 9c93793..329c1c3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectDeletedSharedDbCleanup.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectDeletedSharedDbCleanup.java
@@ -16,8 +16,8 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.events.ProjectDeletedListener;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.multisite.SharedRefDatabaseWrapper;
@@ -42,7 +42,7 @@
"Deleting project '%s'. Will perform a cleanup in Shared-Ref database.", projectName);
try {
- sharedDb.remove(new Project.NameKey(projectName));
+ sharedDb.remove(Project.nameKey(projectName));
} catch (GlobalRefDbSystemError e) {
validationMetrics.incrementSplitBrain();
logger.atSevere().withCause(e).log(
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 3b82582..73bab49 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
@@ -20,8 +20,8 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.events.EventListener;
import com.google.gerrit.server.events.RefUpdatedEvent;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java
index aec5619..d7fafe0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java
@@ -17,7 +17,7 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
import com.google.common.base.MoreObjects;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.googlesource.gerrit.plugins.multisite.LockWrapper;
@@ -171,7 +171,7 @@
try {
succeeded =
sharedRefDb.compareAndPut(
- new Project.NameKey(projectName), refPair.compareRef, refPair.putValue);
+ Project.nameKey(projectName), refPair.compareRef, refPair.putValue);
} catch (GlobalRefDbSystemError e) {
logger.atWarning().withCause(e).log(
"Not able to persist the data in Zookeeper for project '{}' and ref '{}', message: {}",
@@ -198,17 +198,15 @@
String.format("%s-%s", projectName, refName),
() ->
lockWrapperFactory.create(
- projectName,
- refName,
- sharedRefDb.lockRef(new Project.NameKey(projectName), refName)));
+ projectName, refName, sharedRefDb.lockRef(Project.nameKey(projectName), refName)));
RefPair latestRefPair = getLatestLocalRef(refPair);
- if (sharedRefDb.isUpToDate(new Project.NameKey(projectName), latestRefPair.compareRef)) {
+ if (sharedRefDb.isUpToDate(Project.nameKey(projectName), latestRefPair.compareRef)) {
return latestRefPair;
}
if (isNullRef(latestRefPair.compareRef)
- || sharedRefDb.exists(new Project.NameKey(projectName), refName)) {
+ || sharedRefDb.exists(Project.nameKey(projectName), refName)) {
validationMetrics.incrementSplitBrainPrevention();
softFailBasedOnEnforcement(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationMetrics.java
index ee9c5e5..cd2129a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationMetrics.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationMetrics.java
@@ -15,14 +15,13 @@
package com.googlesource.gerrit.plugins.multisite.validation;
import com.google.gerrit.metrics.Counter1;
-import com.google.gerrit.metrics.Description;
-import com.google.gerrit.metrics.Field;
import com.google.gerrit.metrics.MetricMaker;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import com.googlesource.gerrit.plugins.multisite.MultiSiteMetrics;
@Singleton
-public class ValidationMetrics {
+public class ValidationMetrics extends MultiSiteMetrics {
private static final String GIT_UPDATE_SPLIT_BRAIN_PREVENTED = "git_update_split_brain_prevented";
private static final String GIT_UPDATE_SPLIT_BRAIN = "git_update_split_brain";
@@ -34,16 +33,16 @@
this.splitBrainPreventionCounter =
metricMaker.newCounter(
"multi_site/validation/git_update_split_brain_prevented",
- new Description("Rate of REST API error responses").setRate().setUnit("errors"),
- Field.ofString(
+ rateDescription("errors", "Rate of REST API error responses"),
+ stringField(
GIT_UPDATE_SPLIT_BRAIN_PREVENTED,
"Ref-update operations, split-brain detected and prevented"));
this.splitBrainCounter =
metricMaker.newCounter(
"multi_site/validation/git_update_split_brain",
- new Description("Rate of REST API error responses").setRate().setUnit("errors"),
- Field.ofString(
+ rateDescription("errors", "Rate of REST API error responses"),
+ stringField(
GIT_UPDATE_SPLIT_BRAIN,
"Ref-update operation left node in a split-brain scenario"));
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/NoopSharedRefDatabase.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/NoopSharedRefDatabase.java
index ef8d9b8..1530838 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/NoopSharedRefDatabase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/NoopSharedRefDatabase.java
@@ -17,7 +17,7 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDatabase;
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException;
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/OutOfSyncException.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/OutOfSyncException.java
index 036fa6e..50f06b9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/OutOfSyncException.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/OutOfSyncException.java
@@ -25,7 +25,7 @@
super(
localRef == null
? String.format(
- "Local ref does exists locally for project %s but exists in the shared ref-db",
+ "Local ref doesn't exists locally for project %s but exists in the shared ref-db",
project)
: String.format(
"Local ref %s (ObjectId=%s) on project %s is out of sync with the shared ref-db",
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetricsTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetricsTest.java
index ead3189..99148fa 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetricsTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetricsTest.java
@@ -19,8 +19,8 @@
import com.gerritforge.gerrit.eventbroker.EventMessage;
import com.google.common.base.Suppliers;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.metrics.MetricMaker;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.RefUpdateAttribute;
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/event/CacheEvictionEventRouterTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/event/CacheEvictionEventRouterTest.java
index 9292262..a632b74 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/event/CacheEvictionEventRouterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/event/CacheEvictionEventRouterTest.java
@@ -16,8 +16,10 @@
import static org.mockito.Mockito.verify;
+import com.google.gson.Gson;
import com.googlesource.gerrit.plugins.multisite.forwarder.CacheEntry;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedCacheEvictionHandler;
+import com.googlesource.gerrit.plugins.multisite.forwarder.GsonParser;
import com.googlesource.gerrit.plugins.multisite.forwarder.events.CacheEvictionEvent;
import com.googlesource.gerrit.plugins.multisite.forwarder.router.CacheEvictionEventRouter;
import org.junit.Before;
@@ -34,7 +36,7 @@
@Before
public void setUp() {
- router = new CacheEvictionEventRouter(cacheEvictionHandler);
+ router = new CacheEvictionEventRouter(cacheEvictionHandler, new GsonParser(new Gson()));
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/event/IndexEventRouterTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/event/IndexEventRouterTest.java
index dd9b20d..1dc07bd 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/event/IndexEventRouterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/event/IndexEventRouterTest.java
@@ -14,10 +14,11 @@
package com.googlesource.gerrit.plugins.multisite.event;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.server.config.AllUsersName;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedEventHandler;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedIndexAccountHandler;
@@ -35,7 +36,6 @@
import com.googlesource.gerrit.plugins.replication.RefReplicationDoneEvent;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -70,7 +70,7 @@
router.route(event);
verify(indexAccountHandler)
- .indexAsync(new Account.Id(event.accountId), ForwardedIndexingHandler.Operation.INDEX);
+ .indexAsync(Account.id(event.accountId), ForwardedIndexingHandler.Operation.INDEX);
verifyZeroInteractions(indexChangeHandler, indexGroupHandler, indexProjectHandler);
}
@@ -84,7 +84,7 @@
router.route(event);
verify(indexAccountHandler)
- .indexAsync(new Account.Id(event.accountId), ForwardedIndexingHandler.Operation.INDEX);
+ .indexAsync(Account.id(event.accountId), ForwardedIndexingHandler.Operation.INDEX);
verifyZeroInteractions(indexChangeHandler, indexGroupHandler, indexProjectHandler);
@@ -149,12 +149,8 @@
public void routerShouldFailForNotRecognisedEvents() throws Exception {
final IndexEvent newEventType = new IndexEvent("new-type") {};
- try {
- router.route(newEventType);
- Assert.fail("Expected exception for not supported event");
- } catch (UnsupportedOperationException expected) {
- verifyZeroInteractions(
- indexAccountHandler, indexChangeHandler, indexGroupHandler, indexProjectHandler);
- }
+ assertThrows(UnsupportedOperationException.class, () -> router.route(newEventType));
+ verifyZeroInteractions(
+ indexAccountHandler, indexChangeHandler, indexGroupHandler, indexProjectHandler);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/event/StreamEventRouterTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/event/StreamEventRouterTest.java
index 31afa79..3b4bec5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/event/StreamEventRouterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/event/StreamEventRouterTest.java
@@ -16,9 +16,9 @@
import static org.mockito.Mockito.verify;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Change;
import com.google.gerrit.server.events.CommentAddedEvent;
import com.google.gerrit.server.util.time.TimeUtil;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedEventHandler;
@@ -51,10 +51,10 @@
private Change aChange() {
return new Change(
- new Change.Key("Iabcd1234abcd1234abcd1234abcd1234abcd1234"),
- new Change.Id(1),
- new Account.Id(1),
- new Branch.NameKey("proj", "refs/heads/master"),
+ Change.key("Iabcd1234abcd1234abcd1234abcd1234abcd1234"),
+ Change.id(1),
+ Account.id(1),
+ BranchNameKey.create("proj", "refs/heads/master"),
TimeUtil.nowTs());
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
index c166077..747da79 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
@@ -20,8 +20,8 @@
import static org.mockito.Mockito.verify;
import com.google.common.cache.Cache;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.extensions.registration.DynamicMap;
-import com.google.gerrit.reviewdb.client.Account;
import com.googlesource.gerrit.plugins.multisite.cache.Constants;
import org.junit.Before;
import org.junit.Rule;
@@ -57,7 +57,7 @@
@Test
public void testSuccessfulCacheEviction() throws Exception {
- CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, new Account.Id(123));
+ CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, Account.id(123));
doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
handler.evict(entry);
@@ -75,7 +75,7 @@
@Test
public void shouldSetAndUnsetForwardedContext() throws Exception {
- CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, new Account.Id(456));
+ CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, Account.id(456));
doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
// this doAnswer is to allow to assert that context is set to forwarded
@@ -98,7 +98,7 @@
@Test
public void shouldSetAndUnsetForwardedContextEvenIfExceptionIsThrown() throws Exception {
- CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, new Account.Id(789));
+ CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, Account.id(789));
doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
doAnswer(
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java
index ff6f00e..704401b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java
@@ -15,7 +15,7 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -91,12 +91,8 @@
.postEvent(event);
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.dispatch(event);
- fail("should have throw an StorageException");
- } catch (StorageException e) {
- assertThat(e.getMessage()).isEqualTo("someMessage");
- }
+ StorageException thrown = assertThrows(StorageException.class, () -> handler.dispatch(event));
+ assertThat(thrown).hasMessageThat().isEqualTo("someMessage");
assertThat(Context.isForwardedEvent()).isFalse();
verify(dispatcherMock).postEvent(event);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java
index 0d452a4..32c6319 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java
@@ -15,12 +15,12 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.server.index.account.AccountIndexer;
import com.googlesource.gerrit.plugins.multisite.Configuration;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedIndexingHandler.Operation;
@@ -50,7 +50,7 @@
when(config.index()).thenReturn(index);
when(index.numStripedLocks()).thenReturn(10);
handler = new ForwardedIndexAccountHandler(indexerMock, config);
- id = new Account.Id(123);
+ id = Account.id(123);
}
@Test
@@ -98,12 +98,9 @@
.index(id);
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.index(id, Operation.INDEX, Optional.empty());
- fail("should have thrown an IOException");
- } catch (IOException e) {
- assertThat(e.getMessage()).isEqualTo("someMessage");
- }
+ IOException thrown =
+ assertThrows(IOException.class, () -> handler.index(id, Operation.INDEX, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("someMessage");
assertThat(Context.isForwardedEvent()).isFalse();
verify(indexerMock).index(id);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java
index 0a910c5..96470b6 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java
@@ -15,7 +15,7 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
@@ -24,9 +24,9 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.exceptions.StorageException;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.notedb.ChangeNotes;
@@ -82,7 +82,7 @@
@Before
public void setUp() throws Exception {
when(ctxMock.open()).thenReturn(manualRequestContextMock);
- id = new Change.Id(TEST_CHANGE_NUMBER);
+ id = Change.id(TEST_CHANGE_NUMBER);
change = new Change(null, id, null, null, TimeUtil.nowTs());
when(changeNotes.getChange()).thenReturn(change);
when(changeCheckerFactoryMock.create(any())).thenReturn(changeCheckerAbsentMock);
@@ -163,12 +163,11 @@
.index(any(Change.class));
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.index(TEST_CHANGE_ID, Operation.INDEX, Optional.empty());
- fail("should have thrown an IOException");
- } catch (IOException e) {
- assertThat(e.getMessage()).isEqualTo("someMessage");
- }
+ IOException thrown =
+ assertThrows(
+ IOException.class,
+ () -> handler.index(TEST_CHANGE_ID, Operation.INDEX, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("someMessage");
assertThat(Context.isForwardedEvent()).isFalse();
verify(indexerMock, times(1)).index(any(Change.class));
@@ -190,6 +189,6 @@
}
}
- when(changeCheckerPresentMock.isChangeUpToDate(any())).thenReturn(changeIsUpToDate);
+ when(changeCheckerPresentMock.isUpToDate(any())).thenReturn(changeIsUpToDate);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java
index b333af0..24cbbc2 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java
@@ -15,15 +15,16 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.server.index.group.GroupIndexer;
+import com.google.gerrit.server.util.OneOffRequestContext;
import com.googlesource.gerrit.plugins.multisite.Configuration;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedIndexingHandler.Operation;
import com.googlesource.gerrit.plugins.multisite.forwarder.events.GroupIndexEvent;
@@ -46,6 +47,7 @@
@Rule public ExpectedException exception = ExpectedException.none();
@Mock private GroupIndexer indexerMock;
+ @Mock private OneOffRequestContext ctxMock;
@Mock private ScheduledExecutorService indexExecutorMock;
@Mock private Configuration config;
@Mock private Configuration.Index index;
@@ -67,7 +69,7 @@
@Test
public void testSuccessfulIndexing() throws Exception {
handler.index(uuid, Operation.INDEX, Optional.empty());
- verify(indexerMock).index(new AccountGroup.UUID(uuid));
+ verify(indexerMock).index(AccountGroup.uuid(uuid));
}
@Test
@@ -88,13 +90,13 @@
return null;
})
.when(indexerMock)
- .index(new AccountGroup.UUID(uuid));
+ .index(AccountGroup.uuid(uuid));
assertThat(Context.isForwardedEvent()).isFalse();
handler.index(uuid, Operation.INDEX, Optional.empty());
assertThat(Context.isForwardedEvent()).isFalse();
- verify(indexerMock).index(new AccountGroup.UUID(uuid));
+ verify(indexerMock).index(AccountGroup.uuid(uuid));
}
@Test
@@ -106,18 +108,40 @@
throw new IOException("someMessage");
})
.when(indexerMock)
- .index(new AccountGroup.UUID(uuid));
+ .index(AccountGroup.uuid(uuid));
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.index(uuid, Operation.INDEX, Optional.empty());
- fail("should have thrown an IOException");
- } catch (IOException e) {
- assertThat(e.getMessage()).isEqualTo("someMessage");
- }
+ IOException thrown =
+ assertThrows(
+ IOException.class, () -> handler.index(uuid, Operation.INDEX, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("someMessage");
assertThat(Context.isForwardedEvent()).isFalse();
- verify(indexerMock).index(new AccountGroup.UUID(uuid));
+ verify(indexerMock).index(AccountGroup.uuid(uuid));
+ }
+
+ @Test
+ public void shouldChangeIndexEventWheNotUpToDate() throws IOException {
+ ForwardedIndexGroupHandler groupHandlerWithOutdatedEvent = groupHandler(false);
+ groupHandlerWithOutdatedEvent.index(uuid, Operation.INDEX, groupIndexEvent(uuid));
+ verify(indexerMock).index(AccountGroup.uuid(uuid));
+ }
+
+ @Test
+ public void shouldRescheduleGroupIndexingWhenItIsNotUpToDate() throws IOException {
+ ForwardedIndexGroupHandler groupHandlerWithOutdatedEvent = groupHandler(false);
+ groupHandlerWithOutdatedEvent.index(uuid, Operation.INDEX, groupIndexEvent(uuid));
+ verify(indexExecutorMock)
+ .schedule(any(Runnable.class), eq(new Long(RETRY_INTERVAL)), eq(TimeUnit.MILLISECONDS));
+ }
+
+ private ForwardedIndexGroupHandler groupHandler(boolean checkIsUpToDate) {
+ return new ForwardedIndexGroupHandler(
+ indexerMock, config, new TestGroupChecker(checkIsUpToDate), ctxMock, indexExecutorMock);
+ }
+
+ private Optional<GroupIndexEvent> groupIndexEvent(String uuid) {
+ return Optional.of(new GroupIndexEvent(uuid, null));
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java
index 9f94d5f..3ce5e14 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java
@@ -15,14 +15,15 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.index.project.ProjectIndexer;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.server.util.OneOffRequestContext;
import com.googlesource.gerrit.plugins.multisite.Configuration;
import com.googlesource.gerrit.plugins.multisite.forwarder.ForwardedIndexingHandler.Operation;
import com.googlesource.gerrit.plugins.multisite.index.ProjectChecker;
@@ -44,6 +45,7 @@
@Rule public ExpectedException exception = ExpectedException.none();
@Mock private ProjectIndexer indexerMock;
@Mock private Configuration configMock;
+ @Mock private OneOffRequestContext ctxMock;
@Mock private ProjectChecker projectCheckerMock;
@Mock private Configuration.Index indexMock;
@Mock private ScheduledExecutorService indexExecutorMock;
@@ -56,17 +58,17 @@
when(indexMock.numStripedLocks()).thenReturn(10);
when(indexMock.retryInterval()).thenReturn(0);
when(indexMock.maxTries()).thenReturn(2);
- when(projectCheckerMock.isProjectUpToDate(any())).thenReturn(true);
+ when(projectCheckerMock.isUpToDate(any())).thenReturn(true);
handler =
new ForwardedIndexProjectHandler(
- indexerMock, projectCheckerMock, indexExecutorMock, configMock);
+ indexerMock, projectCheckerMock, ctxMock, indexExecutorMock, configMock);
nameKey = "project/name";
}
@Test
public void testSuccessfulIndexing() throws Exception {
handler.index(nameKey, Operation.INDEX, Optional.empty());
- verify(indexerMock).index(new Project.NameKey(nameKey));
+ verify(indexerMock).index(Project.nameKey(nameKey));
}
@Test
@@ -87,13 +89,13 @@
return null;
})
.when(indexerMock)
- .index(new Project.NameKey(nameKey));
+ .index(Project.nameKey(nameKey));
assertThat(Context.isForwardedEvent()).isFalse();
handler.index(nameKey, Operation.INDEX, Optional.empty());
assertThat(Context.isForwardedEvent()).isFalse();
- verify(indexerMock).index(new Project.NameKey(nameKey));
+ verify(indexerMock).index(Project.nameKey(nameKey));
}
@Test
@@ -105,26 +107,15 @@
throw new IOException("someMessage");
})
.when(indexerMock)
- .index(new Project.NameKey(nameKey));
+ .index(Project.nameKey(nameKey));
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.index(nameKey, Operation.INDEX, Optional.empty());
- fail("should have thrown an IOException");
- } catch (IOException e) {
- assertThat(e.getMessage()).isEqualTo("someMessage");
- }
+ IOException thrown =
+ assertThrows(
+ IOException.class, () -> handler.index(nameKey, Operation.INDEX, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("someMessage");
assertThat(Context.isForwardedEvent()).isFalse();
- verify(indexerMock).index(new Project.NameKey(nameKey));
- }
-
- @Test
- public void indexAttemptShouldFailWhenCheckerFails() throws Exception {
- handler =
- new ForwardedIndexProjectHandler(
- indexerMock, (projectName) -> false, indexExecutorMock, configMock);
-
- assertThat(handler.attemptIndex(nameKey, Optional.empty())).isFalse();
+ verify(indexerMock).index(Project.nameKey(nameKey));
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandlerTest.java
index a3b82d0..9893ce7 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedProjectListUpdateHandlerTest.java
@@ -15,11 +15,11 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.project.ProjectCache;
import com.googlesource.gerrit.plugins.multisite.forwarder.events.ProjectListUpdateEvent;
import org.junit.Before;
@@ -36,7 +36,7 @@
private static final String PROJECT_NAME = "someProject";
private static final String SOME_MESSAGE = "someMessage";
- private static final Project.NameKey PROJECT_KEY = new Project.NameKey(PROJECT_NAME);
+ private static final Project.NameKey PROJECT_KEY = Project.nameKey(PROJECT_NAME);
@Rule public ExpectedException exception = ExpectedException.none();
@Mock private ProjectCache projectCacheMock;
private ForwardedProjectListUpdateHandler handler;
@@ -110,12 +110,11 @@
.onCreateProject(PROJECT_KEY);
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.update(new ProjectListUpdateEvent(PROJECT_NAME, false));
- fail("should have thrown a RuntimeException");
- } catch (RuntimeException e) {
- assertThat(e.getMessage()).isEqualTo(SOME_MESSAGE);
- }
+ RuntimeException thrown =
+ assertThrows(
+ RuntimeException.class,
+ () -> handler.update(new ProjectListUpdateEvent(PROJECT_NAME, false)));
+ assertThat(thrown).hasMessageThat().isEqualTo(SOME_MESSAGE);
assertThat(Context.isForwardedEvent()).isFalse();
verify(projectCacheMock).onCreateProject(PROJECT_KEY);
@@ -133,12 +132,11 @@
.remove(PROJECT_KEY);
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.update(new ProjectListUpdateEvent(PROJECT_NAME, true));
- fail("should have thrown a RuntimeException");
- } catch (RuntimeException e) {
- assertThat(e.getMessage()).isEqualTo(SOME_MESSAGE);
- }
+ RuntimeException thrown =
+ assertThrows(
+ RuntimeException.class,
+ () -> handler.update(new ProjectListUpdateEvent(PROJECT_NAME, true)));
+ assertThat(thrown).hasMessageThat().isEqualTo(SOME_MESSAGE);
assertThat(Context.isForwardedEvent()).isFalse();
verify(projectCacheMock).remove(PROJECT_KEY);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParserTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParserTest.java
index 0a1be19..12bdb74 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParserTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/GsonParserTest.java
@@ -16,46 +16,50 @@
import static com.google.common.truth.Truth.assertThat;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.server.events.EventGsonProvider;
+import com.google.gson.Gson;
import com.googlesource.gerrit.plugins.multisite.cache.Constants;
import org.junit.Test;
public class GsonParserTest {
private static final Object EMPTY_JSON = "{}";
+ private final Gson gson = new EventGsonProvider().get();
+ private final GsonParser gsonParser = new GsonParser(gson);
+
@Test
public void accountIDParse() {
- Account.Id accountId = new Account.Id(1);
- String json = GsonParser.toJson(Constants.ACCOUNTS, accountId);
- assertThat(accountId).isEqualTo(GsonParser.fromJson(Constants.ACCOUNTS, json));
+ Account.Id accountId = Account.id(1);
+ String json = gson.toJson(accountId);
+ assertThat(accountId).isEqualTo(gsonParser.fromJson(Constants.ACCOUNTS, json));
}
@Test
public void accountGroupIDParse() {
- AccountGroup.Id accountGroupId = new AccountGroup.Id(1);
- String json = GsonParser.toJson(Constants.GROUPS, accountGroupId);
- assertThat(accountGroupId).isEqualTo(GsonParser.fromJson(Constants.GROUPS, json));
+ AccountGroup.Id accountGroupId = AccountGroup.id(1);
+ String json = gson.toJson(accountGroupId);
+ assertThat(accountGroupId).isEqualTo(gsonParser.fromJson(Constants.GROUPS, json));
}
@Test
public void accountGroupUUIDParse() {
- AccountGroup.UUID accountGroupUuid = new AccountGroup.UUID("abc123");
- String json = GsonParser.toJson(Constants.GROUPS_BYINCLUDE, accountGroupUuid);
- assertThat(accountGroupUuid).isEqualTo(GsonParser.fromJson(Constants.GROUPS_BYINCLUDE, json));
+ AccountGroup.UUID accountGroupUuid = AccountGroup.uuid("abc123");
+ String json = gson.toJson(accountGroupUuid);
+ assertThat(accountGroupUuid).isEqualTo(gsonParser.fromJson(Constants.GROUPS_BYINCLUDE, json));
}
@Test
public void stringParse() {
String key = "key";
- String json = GsonParser.toJson(Constants.PROJECTS, key);
- assertThat(key).isEqualTo(GsonParser.fromJson(Constants.PROJECTS, json));
+ assertThat(key).isEqualTo(gsonParser.fromJson(Constants.PROJECTS, key));
}
@Test
public void noKeyParse() {
Object object = new Object();
- String json = GsonParser.toJson(Constants.PROJECT_LIST, object);
+ String json = gson.toJson(object);
assertThat(json).isEqualTo(EMPTY_JSON);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImplTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImplTest.java
index 653cffa..6403cce 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImplTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/index/GroupCheckerImplTest.java
@@ -18,8 +18,8 @@
import static org.mockito.Mockito.doReturn;
import com.google.gerrit.common.Nullable;
-import com.google.gerrit.reviewdb.client.AccountGroup;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.AllUsersNameProvider;
import com.google.gerrit.server.git.GitRepositoryManager;
@@ -57,15 +57,14 @@
@Test
public void isGroupUpToDate_shouldReturnTrueWhenEventIsEmpty() {
- assertThat(objectUnderTest.isGroupUpToDate(Optional.empty())).isTrue();
+ assertThat(objectUnderTest.isUpToDate(Optional.empty())).isTrue();
}
@Test
public void isGroupUpToDate_shouldReturnFalseWhenSha1DoesNotExistInAllUsers() {
setCommitExistsInRepo(false);
assertThat(
- objectUnderTest.isGroupUpToDate(
- groupIndexEvent(UUID.randomUUID().toString(), AN_OBJECT_ID)))
+ objectUnderTest.isUpToDate(groupIndexEvent(UUID.randomUUID().toString(), AN_OBJECT_ID)))
.isFalse();
}
@@ -73,8 +72,7 @@
public void isGroupUpToDate_shouldReturnFalseWhenSha1ExistsInAllUsers() {
setCommitExistsInRepo(true);
assertThat(
- objectUnderTest.isGroupUpToDate(
- groupIndexEvent(UUID.randomUUID().toString(), AN_OBJECT_ID)))
+ objectUnderTest.isUpToDate(groupIndexEvent(UUID.randomUUID().toString(), AN_OBJECT_ID)))
.isTrue();
}
@@ -83,8 +81,7 @@
UUID groupUUID = UUID.randomUUID();
setCommitExistsInRepo(true);
- assertThat(objectUnderTest.isGroupUpToDate(groupIndexEvent(groupUUID.toString(), null)))
- .isTrue();
+ assertThat(objectUnderTest.isUpToDate(groupIndexEvent(groupUUID.toString(), null))).isTrue();
}
@Test
@@ -119,7 +116,7 @@
private void setupExactRefInGroup(UUID groupUUID, @Nullable ObjectId objectId)
throws IOException {
- String groupRefName = RefNames.refsGroups(new AccountGroup.UUID(groupUUID.toString()));
+ String groupRefName = RefNames.refsGroups(AccountGroup.uuid(groupUUID.toString()));
ObjectIdRef.Unpeeled aRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, groupRefName, objectId);
doReturn(objectId == null ? null : aRef).when(refDatabaseMock).exactRef(groupRefName);
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/index/TestGroupChecker.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/index/TestGroupChecker.java
index a6c2675..0af7e9e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/index/TestGroupChecker.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/index/TestGroupChecker.java
@@ -31,7 +31,7 @@
private static final String someObjectId = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
@Override
- public boolean isGroupUpToDate(Optional<GroupIndexEvent> groupIndexEvent) {
+ public boolean isUpToDate(Optional<GroupIndexEvent> groupIndexEvent) {
return isUpToDate;
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/BatchRefUpdateValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/BatchRefUpdateValidatorTest.java
index 17e71ce..b79740d 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/BatchRefUpdateValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/BatchRefUpdateValidatorTest.java
@@ -22,8 +22,8 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.metrics.DisabledMetricMaker;
-import com.google.gerrit.reviewdb.client.Project;
import com.googlesource.gerrit.plugins.multisite.SharedRefDatabaseWrapper;
import com.googlesource.gerrit.plugins.multisite.validation.RefUpdateValidator.OneParameterVoidFunction;
import com.googlesource.gerrit.plugins.multisite.validation.dfsrefdb.DefaultSharedRefEnforcement;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/Log4jSharedRefLoggerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/Log4jSharedRefLoggerTest.java
index c6f0fc1..3debdf4 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/Log4jSharedRefLoggerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/Log4jSharedRefLoggerTest.java
@@ -18,8 +18,8 @@
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.PushOneCommit;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.json.OutputFormat;
-import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.notedb.Sequences;
import com.google.gerrit.server.util.SystemLog;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java
index 622cf9d..e9651fb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java
@@ -94,6 +94,7 @@
return "branch_" + nameRule.getMethodName();
}
+ @SuppressWarnings("deprecation")
private void setMockRequiredReturnValues() throws IOException {
doReturn(batchRefUpdate).when(refDatabase).newBatchUpdate();
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java
index 16cda4e..9e75c8f 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java
@@ -15,7 +15,7 @@
package com.googlesource.gerrit.plugins.multisite.validation;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -101,12 +101,8 @@
MultiSiteRefUpdate multiSiteRefUpdate =
getMultiSiteRefUpdateWithDefaultPolicyEnforcement(refUpdate);
- try {
- multiSiteRefUpdate.update();
- fail("Expecting an IOException to be thrown");
- } catch (IOException e) {
- verify(validationMetrics).incrementSplitBrainPrevention();
- }
+ assertThrows(IOException.class, () -> multiSiteRefUpdate.update());
+ verify(validationMetrics).incrementSplitBrainPrevention();
}
@Test
@@ -123,12 +119,8 @@
MultiSiteRefUpdate multiSiteRefUpdate =
getMultiSiteRefUpdateWithDefaultPolicyEnforcement(refUpdate);
- try {
- multiSiteRefUpdate.update();
- fail("Expecting an IOException to be thrown");
- } catch (IOException e) {
- verify(validationMetrics, never()).incrementSplitBrainPrevention();
- }
+ assertThrows(IOException.class, () -> multiSiteRefUpdate.update());
+ verify(validationMetrics, never()).incrementSplitBrainPrevention();
}
@Test
@@ -145,12 +137,8 @@
MultiSiteRefUpdate multiSiteRefUpdate =
getMultiSiteRefUpdateWithDefaultPolicyEnforcement(refUpdate);
- try {
- multiSiteRefUpdate.update();
- fail("Expecting an IOException to be thrown");
- } catch (IOException e) {
- verify(validationMetrics).incrementSplitBrain();
- }
+ assertThrows(IOException.class, () -> multiSiteRefUpdate.update());
+ verify(validationMetrics).incrementSplitBrain();
}
@Test
@@ -180,12 +168,8 @@
MultiSiteRefUpdate multiSiteRefUpdate =
getMultiSiteRefUpdateWithDefaultPolicyEnforcement(refUpdate);
- try {
- multiSiteRefUpdate.delete();
- fail("Expecting an IOException to be thrown");
- } catch (IOException e) {
- verify(validationMetrics).incrementSplitBrainPrevention();
- }
+ assertThrows(IOException.class, () -> multiSiteRefUpdate.delete());
+ verify(validationMetrics).incrementSplitBrainPrevention();
}
private MultiSiteRefUpdate getMultiSiteRefUpdateWithDefaultPolicyEnforcement(
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 6360227..2eefb5a 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
@@ -24,8 +24,8 @@
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.project.ProjectConfig;
@@ -239,8 +239,7 @@
@Test
public void shouldNotUpdateProjectVersionWhenProjectDoesntExist() throws IOException {
Context.setForwardedEvent(false);
- when(refUpdatedEvent.getProjectNameKey())
- .thenReturn(new Project.NameKey("aNonExistentProject"));
+ when(refUpdatedEvent.getProjectNameKey()).thenReturn(Project.nameKey("aNonExistentProject"));
when(refUpdatedEvent.getRefName()).thenReturn(A_TEST_REF_NAME);
new ProjectVersionRefUpdate(repoManager, sharedRefDb, gitReferenceUpdated, verLogger)
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java
index 09e60d3..323db63 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java
@@ -24,7 +24,7 @@
import static org.mockito.Mockito.when;
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.googlesource.gerrit.plugins.multisite.SharedRefDatabaseWrapper;
import com.googlesource.gerrit.plugins.multisite.validation.RefUpdateValidator.OneParameterFunction;
import com.googlesource.gerrit.plugins.multisite.validation.dfsrefdb.DefaultSharedRefEnforcement;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java
index fb8eb40..7e4593b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java
@@ -24,8 +24,8 @@
import com.gerritforge.gerrit.globalrefdb.GlobalRefDatabase;
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException;
import com.gerritforge.gerrit.globalrefdb.GlobalRefDbSystemError;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.registration.DynamicItem;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.testing.InMemoryRepositoryManager;
import com.google.gerrit.testing.InMemoryTestEnvironment;
import com.google.inject.Inject;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/RefFixture.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/RefFixture.java
index 8ddbf5c..baba94b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/RefFixture.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/RefFixture.java
@@ -14,8 +14,8 @@
package com.googlesource.gerrit.plugins.multisite.validation.dfsrefdb;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref;
@@ -29,7 +29,7 @@
static final String ALLOWED_NAME_CHARS =
ALLOWED_CHARS + ALLOWED_CHARS.toUpperCase() + ALLOWED_DIGITS;
static final String A_TEST_PROJECT_NAME = "A_TEST_PROJECT_NAME";
- static final Project.NameKey A_TEST_PROJECT_NAME_KEY = new Project.NameKey(A_TEST_PROJECT_NAME);
+ static final Project.NameKey A_TEST_PROJECT_NAME_KEY = Project.nameKey(A_TEST_PROJECT_NAME);
static final ObjectId AN_OBJECT_ID_1 = new ObjectId(1, 2, 3, 4, 5);
static final ObjectId AN_OBJECT_ID_2 = new ObjectId(1, 2, 3, 4, 6);
static final ObjectId AN_OBJECT_ID_3 = new ObjectId(1, 2, 3, 4, 7);
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateChangeUsingMultiGerrit.scala b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateChangeUsingMultiGerrit.scala
index eade1cf..fdacd81 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateChangeUsingMultiGerrit.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateChangeUsingMultiGerrit.scala
@@ -25,7 +25,6 @@
class CreateChangeUsingMultiGerrit extends GerritSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
private val projectName = className
- private val numberKey = "_number"
override def relativeRuntimeWeight = 10
@@ -33,7 +32,7 @@
.feed(data)
.exec(httpRequest
.body(ElFileBody(body)).asJson
- .check(regex("\"" + numberKey + "\":(\\d+),").saveAs(numberKey)))
+ .check(regex("\"_" + numberKey + "\":(\\d+),").saveAs(numberKey)))
.exec(session => {
deleteChange.number = Some(session(numberKey).as[Int])
session
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteChangeUsingMultiGerrit1.scala b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteChangeUsingMultiGerrit1.scala
index 457de0d..b509a19 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteChangeUsingMultiGerrit1.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteChangeUsingMultiGerrit1.scala
@@ -40,12 +40,12 @@
.feed(data)
.exec(session => {
if (number.nonEmpty) {
- session.set("number", number.get)
+ session.set(numberKey, number.get)
} else {
session
}
})
- .exec(http(uniqueName).delete("${url}${number}"))
+ .exec(http(uniqueName).delete("${url}${"+ numberKey +"}"))
setUp(
test.inject(