Merge branch 'stable-3.0' into stable-3.1
* stable-3.0:
Serve reindexing simulating a GET request for /meta ref caching
Auto-reload the indexTs file for auto-reindexing
Download plugins from archive-ci.gerritforge.com
Pin haproxy to 1.8.30-buster and fix associated issues
Fix issue with change indexing during the NoteDb online migration
Remove references to ReviewDb in README.md
Change-Id: I0861860028071010adc40d0ddd19c5ca5120f60c
diff --git a/.mailmap b/.mailmap
deleted file mode 100644
index 84de0f3..0000000
--- a/.mailmap
+++ /dev/null
@@ -1 +0,0 @@
-Hector Oswaldo Caballero <hector.caballero@ericsson.com>
diff --git a/WORKSPACE b/WORKSPACE
index 666572c..6969594 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "a029d8e41d6211c8b23052aa0a0c2c7649577e85",
+ commit = "87fd5f0d0a89d01df13deaf2d21a4bdb3bc03cfd",
#local_path = "/home/<user>/projects/bazlets",
)
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/AccountReindexRunnable.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/AccountReindexRunnable.java
index eb65106..70ef751 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/AccountReindexRunnable.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/AccountReindexRunnable.java
@@ -18,7 +18,7 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
import com.ericsson.gerrit.plugins.highavailability.forwarder.rest.AbstractIndexRestApiServlet;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.account.Accounts;
import com.google.gerrit.server.util.OneOffRequestContext;
@@ -53,12 +53,11 @@
@Override
protected Optional<Timestamp> indexIfNeeded(AccountState as, Timestamp sinceTs) {
try {
- Account a = as.getAccount();
- Timestamp accountTs = a.getRegisteredOn();
+ Account a = as.account();
+ Timestamp accountTs = a.registeredOn();
if (accountTs.after(sinceTs)) {
- log.atInfo().log(
- "Index %s/%s/%s/%s", a.getId(), a.getFullName(), a.getPreferredEmail(), accountTs);
- accountIdx.index(a.getId(), Operation.INDEX, Optional.empty());
+ log.atInfo().log("Index %s/%s/%s/%s", a.id(), a.fullName(), a.preferredEmail(), accountTs);
+ accountIdx.index(a.id(), Operation.INDEX, Optional.empty());
return Optional.of(accountTs);
}
} catch (IOException e) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ChangeReindexRunnable.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ChangeReindexRunnable.java
index dd323b4..0787953 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ChangeReindexRunnable.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ChangeReindexRunnable.java
@@ -19,8 +19,8 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.rest.AbstractIndexRestApiServlet;
import com.google.common.collect.Streams;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeNotes.Factory.ChangeNotesResult;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnable.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnable.java
index 35445cc..76c2e44 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnable.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnable.java
@@ -20,8 +20,8 @@
import com.google.common.collect.Streams;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.data.GroupReference;
-import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
-import com.google.gerrit.reviewdb.client.AccountGroupMemberAudit;
+import com.google.gerrit.entities.AccountGroupByIdAudit;
+import com.google.gerrit.entities.AccountGroupMemberAudit;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.group.InternalGroup;
@@ -77,27 +77,27 @@
Repository allUsersRepo = repoManager.openRepository(allUsers);
- List<AccountGroupByIdAud> subGroupMembersAud =
+ List<AccountGroupByIdAudit> subGroupMembersAud =
groups.getSubgroupsAudit(allUsersRepo, g.getUUID());
Stream<Timestamp> groupIdAudAddedTs =
subGroupMembersAud.stream()
- .map(AccountGroupByIdAud::getAddedOn)
+ .map(AccountGroupByIdAudit::addedOn)
.filter(Objects::nonNull);
Stream<Timestamp> groupIdAudRemovedTs =
subGroupMembersAud.stream()
- .map(AccountGroupByIdAud::getRemovedOn)
- .filter(Objects::nonNull);
+ .map(AccountGroupByIdAudit::removedOn)
+ .filter(Optional<Timestamp>::isPresent)
+ .map(Optional<Timestamp>::get);
List<AccountGroupMemberAudit> groupMembersAud =
groups.getMembersAudit(allUsersRepo, g.getUUID());
Stream<Timestamp> groupMemberAudAddedTs =
- groupMembersAud.stream()
- .map(AccountGroupMemberAudit::getAddedOn)
- .filter(Objects::nonNull);
+ groupMembersAud.stream().map(AccountGroupMemberAudit::addedOn).filter(Objects::nonNull);
Stream<Timestamp> groupMemberAudRemovedTs =
groupMembersAud.stream()
- .map(AccountGroupMemberAudit::getRemovedOn)
- .filter(Objects::nonNull);
+ .map(AccountGroupMemberAudit::removedOn)
+ .filter(Optional<Timestamp>::isPresent)
+ .map(Optional<Timestamp>::get);
Optional<Timestamp> groupLastTs =
Streams.concat(
@@ -109,7 +109,7 @@
.max(Comparator.naturalOrder());
if (groupLastTs.isPresent() && groupLastTs.get().after(sinceTs)) {
- log.atInfo().log("Index {}/{}/{}", g.getUUID(), g.getName(), groupLastTs.get());
+ log.atInfo().log("Index %s/%s/%s", g.getUUID(), g.getName(), groupLastTs.get());
indexer.index(g.getUUID(), Operation.INDEX, Optional.empty());
return groupLastTs;
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ProjectReindexRunnable.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ProjectReindexRunnable.java
index ff5a965..00c574d 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ProjectReindexRunnable.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ProjectReindexRunnable.java
@@ -15,7 +15,7 @@
package com.ericsson.gerrit.plugins.highavailability.autoreindex;
import com.ericsson.gerrit.plugins.highavailability.forwarder.rest.AbstractIndexRestApiServlet;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.inject.Inject;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/ProjectNameKeyAdapter.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/ProjectNameKeyAdapter.java
deleted file mode 100644
index 8c00282..0000000
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/event/ProjectNameKeyAdapter.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (C) 2020 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.ericsson.gerrit.plugins.highavailability.event;
-
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-import java.lang.reflect.Type;
-
-public class ProjectNameKeyAdapter
- implements JsonSerializer<Project.NameKey>, JsonDeserializer<Project.NameKey> {
- @Override
- public JsonElement serialize(
- Project.NameKey project, Type typeOfSrc, JsonSerializationContext context) {
- return new JsonPrimitive(project.get());
- }
-
- @Override
- public Project.NameKey deserialize(
- JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException {
- if (json.isJsonObject()) {
- return Project.nameKey(json.getAsJsonObject().get("name").getAsJsonPrimitive().getAsString());
- }
- return Project.nameKey(json.getAsString());
- }
-}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandler.java
index f31331d..b1a595c 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandler.java
@@ -14,7 +14,7 @@
package com.ericsson.gerrit.plugins.highavailability.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/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java
index 42f3cef..770259d 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java
@@ -20,8 +20,9 @@
import com.ericsson.gerrit.plugins.highavailability.index.ChangeCheckerImpl;
import com.ericsson.gerrit.plugins.highavailability.index.ForwardedIndexExecutor;
import com.google.common.base.Splitter;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.NoSuchChangeException;
@@ -76,7 +77,13 @@
throws IOException {
try {
ChangeChecker checker = changeCheckerFactory.create(id);
- Optional<ChangeNotes> changeNotes = checker.getChangeNotes();
+ Optional<ChangeNotes> changeNotes;
+ try {
+ changeNotes = checker.getChangeNotes();
+ } catch (StorageException e) {
+ log.atWarning().withCause(e).log("Change %s: cannot load change notes", id);
+ changeNotes = Optional.empty();
+ }
if (changeNotes.isPresent()) {
ChangeNotes notes = changeNotes.get();
reindex(notes);
@@ -152,11 +159,11 @@
}
private static Change.Id parseChangeId(String id) {
- return new Change.Id(Integer.parseInt(getChangeIdParts(id).get(1)));
+ return Change.id(Integer.parseInt(getChangeIdParts(id).get(1)));
}
private static Project.NameKey parseProject(String id) {
- return new Project.NameKey(getChangeIdParts(id).get(0));
+ return Project.nameKey(getChangeIdParts(id).get(0));
}
private static List<String> getChangeIdParts(String id) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandler.java
index 127af36..ab31659 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandler.java
@@ -14,7 +14,7 @@
package com.ericsson.gerrit.plugins.highavailability.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.inject.Inject;
import com.google.inject.Singleton;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandler.java
index b6daf41..20ffefd 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandler.java
@@ -14,8 +14,8 @@
package com.ericsson.gerrit.plugins.highavailability.forwarder;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.index.project.ProjectIndexer;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Optional;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandler.java
index 84f4675..857d2db 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandler.java
@@ -15,7 +15,7 @@
package com.ericsson.gerrit.plugins.highavailability.forwarder;
import com.google.common.flogger.FluentLogger;
-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;
@@ -45,7 +45,7 @@
* @throws IOException
*/
public void update(String projectName, boolean remove) throws IOException {
- Project.NameKey projectKey = new Project.NameKey(projectName);
+ Project.NameKey projectKey = Project.nameKey(projectName);
try {
Context.setForwardedEvent(true);
if (remove) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java
index 09d4603..6b23588 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java
@@ -23,10 +23,11 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.IndexEvent;
import com.google.common.base.Charsets;
import com.google.gerrit.server.cache.PerThreadCache;
+import com.google.gerrit.server.events.EventGson;
import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
@@ -34,11 +35,11 @@
public abstract class AbstractIndexRestApiServlet<T> extends AbstractRestApiServlet {
private static final long serialVersionUID = -1L;
- private static final Gson gson = new GsonBuilder().create();
private final ForwardedIndexingHandler<T> forwardedIndexingHandler;
private final IndexName indexName;
private final boolean allowDelete;
+ private final Gson gson;
public enum IndexName {
CHANGE,
@@ -57,15 +58,17 @@
AbstractIndexRestApiServlet(
ForwardedIndexingHandler<T> forwardedIndexingHandler,
IndexName indexName,
- boolean allowDelete) {
+ boolean allowDelete,
+ @EventGson Gson gson) {
this.forwardedIndexingHandler = forwardedIndexingHandler;
this.indexName = indexName;
this.allowDelete = allowDelete;
+ this.gson = gson;
}
AbstractIndexRestApiServlet(
ForwardedIndexingHandler<T> forwardedIndexingHandler, IndexName indexName) {
- this(forwardedIndexingHandler, indexName, false);
+ this(forwardedIndexingHandler, indexName, false, new Gson());
}
@Override
@@ -118,9 +121,9 @@
protected Optional<IndexEvent> parseBody(HttpServletRequest req) throws IOException {
String contentType = req.getContentType();
if (contentType != null && contentType.contains("application/json")) {
- return Optional.ofNullable(
- gson.fromJson(
- new InputStreamReader(req.getInputStream(), Charsets.UTF_8), IndexEvent.class));
+ try (Reader reader = new InputStreamReader(req.getInputStream(), Charsets.UTF_8)) {
+ return Optional.ofNullable(gson.fromJson(reader, IndexEvent.class));
+ }
}
return Optional.empty();
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java
index 3d2d25e..37f0f20 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java
@@ -23,7 +23,9 @@
import com.google.common.io.CharStreams;
import com.google.common.net.MediaType;
import com.google.gerrit.server.events.Event;
+import com.google.gerrit.server.events.EventGson;
import com.google.gerrit.server.permissions.PermissionBackendException;
+import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
@@ -35,10 +37,10 @@
private static final long serialVersionUID = -1L;
private final ForwardedEventHandler forwardedEventHandler;
- private final GsonProvider gson;
+ private final Gson gson;
@Inject
- EventRestApiServlet(ForwardedEventHandler forwardedEventHandler, GsonProvider gson) {
+ EventRestApiServlet(ForwardedEventHandler forwardedEventHandler, @EventGson Gson gson) {
this.forwardedEventHandler = forwardedEventHandler;
this.gson = gson;
}
@@ -61,6 +63,6 @@
private Event getEventFromRequest(HttpServletRequest req) throws IOException {
String jsonEvent = CharStreams.toString(req.getReader());
- return gson.get().fromJson(jsonEvent, Event.class);
+ return gson.fromJson(jsonEvent, Event.class);
}
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParser.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParser.java
index 8db2488..de02912 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParser.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParser.java
@@ -16,9 +16,12 @@
import com.ericsson.gerrit.plugins.highavailability.cache.Constants;
import com.google.common.base.Strings;
-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.JsonElement;
+import com.google.gson.JsonObject;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -27,32 +30,40 @@
private final Gson gson;
@Inject
- GsonParser(GsonProvider gson) {
- this.gson = gson.get();
+ public GsonParser(@EventGson Gson gson) {
+ this.gson = gson;
}
- public Object fromJson(String cacheName, String json) {
+ public Object fromJson(String cacheName, String jsonString) {
+ JsonElement json = gson.fromJson(Strings.nullToEmpty(jsonString), JsonElement.class);
Object key;
// Need to add a case for 'adv_bases'
+ if (!json.isJsonObject()) {
+ return json.getAsString();
+ }
+ JsonObject asJsonObject = json.getAsJsonObject();
switch (cacheName) {
case Constants.ACCOUNTS:
- key = gson.fromJson(Strings.nullToEmpty(json).trim(), Account.Id.class);
+ key = asJsonObject.has("id") ? Account.id(asJsonObject.get("id").getAsInt()) : null;
break;
case Constants.GROUPS:
- key = gson.fromJson(Strings.nullToEmpty(json).trim(), AccountGroup.Id.class);
+ key = asJsonObject.has("id") ? AccountGroup.id(asJsonObject.get("id").getAsInt()) : null;
break;
case Constants.GROUPS_BYINCLUDE:
case Constants.GROUPS_MEMBERS:
- key = gson.fromJson(Strings.nullToEmpty(json).trim(), AccountGroup.UUID.class);
+ key =
+ asJsonObject.has("uuid")
+ ? AccountGroup.uuid(asJsonObject.get("uuid").getAsString())
+ : null;
break;
case Constants.PROJECT_LIST:
- key = gson.fromJson(Strings.nullToEmpty(json), Object.class);
+ key = gson.fromJson(json, Object.class);
break;
default:
try {
- key = gson.fromJson(Strings.nullToEmpty(json).trim(), String.class);
+ key = gson.fromJson(json, String.class);
} catch (Exception e) {
- key = gson.fromJson(Strings.nullToEmpty(json), Object.class);
+ key = gson.fromJson(json, Object.class);
}
}
return key;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonProvider.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonProvider.java
deleted file mode 100644
index c600019..0000000
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.ericsson.gerrit.plugins.highavailability.forwarder.rest;
-
-import com.ericsson.gerrit.plugins.highavailability.event.ProjectNameKeyAdapter;
-import com.google.common.base.Supplier;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.server.events.Event;
-import com.google.gerrit.server.events.EventDeserializer;
-import com.google.gerrit.server.events.SupplierDeserializer;
-import com.google.gerrit.server.events.SupplierSerializer;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.inject.Provider;
-
-public class GsonProvider implements Provider<Gson> {
-
- @Override
- public Gson get() {
- return new GsonBuilder()
- .registerTypeAdapter(Event.class, new EventDeserializer())
- .registerTypeAdapter(Project.NameKey.class, new ProjectNameKeyAdapter())
- .registerTypeAdapter(Supplier.class, new SupplierSerializer())
- .registerTypeAdapter(Supplier.class, new SupplierDeserializer())
- .create();
- }
-}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSession.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSession.java
index cf98aae..6d801f6 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSession.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSession.java
@@ -15,8 +15,8 @@
package com.ericsson.gerrit.plugins.highavailability.forwarder.rest;
import com.ericsson.gerrit.plugins.highavailability.forwarder.rest.HttpResponseHandler.HttpResult;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.net.MediaType;
+import com.google.gerrit.server.events.EventGson;
import com.google.gson.Gson;
import com.google.inject.Inject;
import java.io.IOException;
@@ -33,9 +33,9 @@
private final Gson gson;
@Inject
- HttpSession(CloseableHttpClient httpClient, GsonProvider gsonProvider) {
+ HttpSession(CloseableHttpClient httpClient, @EventGson Gson gson) {
this.httpClient = httpClient;
- this.gson = gsonProvider.get();
+ this.gson = gson;
}
HttpResult post(String uri) throws IOException {
@@ -65,8 +65,7 @@
}
}
- @VisibleForTesting
- String jsonEncode(Object content) {
+ private String jsonEncode(Object content) {
if (content instanceof String) {
return (String) content;
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServlet.java
index e7f1447..fa38cc3 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServlet.java
@@ -15,7 +15,7 @@
package com.ericsson.gerrit.plugins.highavailability.forwarder.rest;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexAccountHandler;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -30,6 +30,6 @@
@Override
Account.Id parse(String id) {
- return new Account.Id(Integer.parseInt(id));
+ return Account.id(Integer.parseInt(id));
}
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexBatchChangeRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexBatchChangeRestApiServlet.java
index 6613ee6..bebfae9 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexBatchChangeRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexBatchChangeRestApiServlet.java
@@ -16,6 +16,8 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexBatchChangeHandler;
import com.google.gerrit.extensions.restapi.Url;
+import com.google.gerrit.server.events.EventGson;
+import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -24,8 +26,8 @@
private static final long serialVersionUID = -1L;
@Inject
- IndexBatchChangeRestApiServlet(ForwardedIndexBatchChangeHandler handler) {
- super(handler, IndexName.CHANGE, true);
+ IndexBatchChangeRestApiServlet(ForwardedIndexBatchChangeHandler handler, @EventGson Gson gson) {
+ super(handler, IndexName.CHANGE, true, gson);
}
@Override
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java
index 046611e..71e10fb 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServlet.java
@@ -16,6 +16,8 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexChangeHandler;
import com.google.gerrit.extensions.restapi.Url;
+import com.google.gerrit.server.events.EventGson;
+import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -24,8 +26,8 @@
private static final long serialVersionUID = -1L;
@Inject
- IndexChangeRestApiServlet(ForwardedIndexChangeHandler handler) {
- super(handler, IndexName.CHANGE, true);
+ IndexChangeRestApiServlet(ForwardedIndexChangeHandler handler, @EventGson Gson gson) {
+ super(handler, IndexName.CHANGE, true, gson);
}
@Override
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServlet.java
index a8bbb5e..35c526f 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServlet.java
@@ -15,7 +15,7 @@
package com.ericsson.gerrit.plugins.highavailability.forwarder.rest;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexGroupHandler;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.AccountGroup;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -30,6 +30,6 @@
@Override
AccountGroup.UUID parse(String id) {
- return new AccountGroup.UUID(id);
+ return AccountGroup.uuid(id);
}
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServlet.java
index cc87442..31df2bb 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServlet.java
@@ -15,8 +15,8 @@
package com.ericsson.gerrit.plugins.highavailability.forwarder.rest;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexProjectHandler;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.restapi.Url;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -31,6 +31,6 @@
@Override
Project.NameKey parse(String projectName) {
- return new Project.NameKey(Url.decode(projectName));
+ return Project.nameKey(Url.decode(projectName));
}
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
index 6426b5a..c0eb6ae 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
@@ -25,6 +25,8 @@
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.server.events.Event;
+import com.google.gerrit.server.events.EventGson;
+import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
@@ -46,7 +48,7 @@
private final String pluginRelativePath;
private final Configuration cfg;
private final Provider<Set<PeerInfo>> peerInfoProvider;
- private final GsonProvider gson;
+ private final Gson gson;
private final RestForwarderScheduler scheduler;
@Inject
@@ -55,7 +57,7 @@
@PluginName String pluginName,
Configuration cfg,
Provider<Set<PeerInfo>> peerInfoProvider,
- GsonProvider gson,
+ @EventGson Gson gson,
RestForwarderScheduler scheduler) {
this.httpSession = httpClient;
this.pluginRelativePath = Joiner.on("/").join("plugins", pluginName);
@@ -81,6 +83,7 @@
event);
}
+ @Override
public CompletableFuture<Boolean> batchIndexChange(
String projectName, int changeId, IndexEvent event) {
return execute(
@@ -124,7 +127,7 @@
@Override
public CompletableFuture<Boolean> evict(final String cacheName, final Object key) {
- String json = gson.get().toJson(key);
+ String json = gson.toJson(key);
return execute(RequestMethod.POST, "invalidate cache " + cacheName, "cache", cacheName, json);
}
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java
index 1656eb9..23712be 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java
@@ -16,9 +16,9 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.IndexEvent;
import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Comment;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Comment;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeFinder;
import com.google.gerrit.server.git.GitRepositoryManager;
@@ -74,7 +74,7 @@
IndexEvent event = new IndexEvent();
event.eventCreatedOn = ts;
try (Repository repo = gitRepoMgr.openRepository(changeNotes.get().getProjectName())) {
- event.targetSha = getBranchTargetSha(repo);
+ event.targetSha = getBranchTargetSha();
event.metaSha = getMetaSha(repo);
return Optional.of(event);
} catch (IOException e) {
@@ -107,7 +107,7 @@
return (computedChangeTs.get() > indexEvent.eventCreatedOn)
|| (computedChangeTs.get() == indexEvent.eventCreatedOn)
&& (Objects.isNull(indexEvent.targetSha)
- || Objects.equals(getBranchTargetSha(repo), indexEvent.targetSha))
+ || Objects.equals(getBranchTargetSha(), indexEvent.targetSha))
&& (Objects.isNull(indexEvent.metaSha)
|| Objects.equals(getMetaSha(repo), indexEvent.metaSha));
}
@@ -136,7 +136,7 @@
+ "@"
+ getComputedChangeTs().map(IndexEvent::format)
+ "/target:"
- + getBranchTargetSha(repo)
+ + getBranchTargetSha()
+ "/meta:"
+ getMetaSha(repo);
} catch (IOException e) {
@@ -145,9 +145,9 @@
}
}
- private String getBranchTargetSha(Repository repo) {
- try {
- String refName = changeNotes.get().getChange().getDest().get();
+ private String getBranchTargetSha() {
+ try (Repository repo = gitRepoMgr.openRepository(changeNotes.get().getProjectName())) {
+ String refName = changeNotes.get().getChange().getDest().branch();
Ref ref = repo.exactRef(refName);
if (ref == null) {
log.atWarning().log("Unable to find target ref %s for change %s", refName, changeId);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandler.java
index 73e842f..4f77508 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandler.java
@@ -116,7 +116,7 @@
}
});
} catch (Exception e) {
- log.atWarning().withCause(e).log("Unable to create task to reindex change {}", changeId);
+ log.atWarning().withCause(e).log("Unable to create task to reindex change %s", changeId);
}
}
}
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index fd0b56e..83d3862 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -103,3 +103,17 @@
For further information and supported options, refer to [config](config.md)
documentation.
+
+### Last index update timestamp storage
+
+The plugin keeps track of the timestamp when it lastly updated an index.
+When the [`autoReindex.enabled` option](config.md) is set to `true`, the timestamp
+is used to determine which changes to reindex when a node is temporarily out of
+sync with the primary, for example, after a node being offline for a long time.
+
+The HA plugin keeps the last update timestamp for each index in the following files:
+* `<gerrit_home>/data/high-availability/group`
+* `<gerrit_home>/data/high-availability/account`
+* `<gerrit_home>/data/high-availability/change`
+
+The timestamp is stored in this format `yyyy-mm-ddTHH:MM:SS.ss`, i.e.: `2020-12-18T12:17:53.25`.
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 360218d..5186bd1 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -3,8 +3,8 @@
=========================
The @PLUGIN@ plugin must be installed on all the instances. Each instance should
-be configured with the same [gerrit.serverId](https://gerrit-documentation.storage.googleapis.com/Documentation/3.0.0/config-gerrit.html#gerrit.serverId).
-If there are existing changes in [NoteDb](https://gerrit-documentation.storage.googleapis.com/Documentation/3.0.0/note-db.html)
+be configured with the same [gerrit.serverId](https://gerrit-documentation.storage.googleapis.com/Documentation/3.1.0/config-gerrit.html#gerrit.serverId).
+If there are existing changes in [NoteDb](https://gerrit-documentation.storage.googleapis.com/Documentation/3.1.0/note-db.html)
made with another `serverId`, then this plugin might not be able to access them.
Likewise, if the HA gerrit.serverIds differ, then changes conveyed by one
instance will not be accessible by the other.
@@ -180,7 +180,11 @@
Defaults to true.
```index.numStripedLocks```
-: Number of striped locks to use during reindexing.
+: Number of striped locks to use during reindexing. Should be of the same order
+ of magnitude of the open changes. I.e.: if one has 5000 changes, one might want
+ to have at least 1000 striped locks. The value has to be tuned empirically
+ by checking the number of failures in acquiring the locking. Checking the
+ `consider increasing the number of shards` warnings should help.
Defaults to 10.
```index.synchronize```
diff --git a/src/test/docker/README.md b/src/test/docker/README.md
index d97e929..4604423 100644
--- a/src/test/docker/README.md
+++ b/src/test/docker/README.md
@@ -55,7 +55,7 @@
created on gerrit 1 (port 8081) but from gerrit 2 (on 8082). The
scenario therefore expects Gerrit HA to have properly synchronized
the new project from 1 to 2. That project gets deleted after, here
-using HA Gerrit straight (no specific port).
+using HA Gerrit straight (through default http port 80).
Scenario scala source files and their companion json resource ones are
stored under the usual src/test directories. That structure follows the
diff --git a/src/test/docker/gerrit/Dockerfile b/src/test/docker/gerrit/Dockerfile
index ec7ebd8..c40d91b 100644
--- a/src/test/docker/gerrit/Dockerfile
+++ b/src/test/docker/gerrit/Dockerfile
@@ -1,6 +1,6 @@
-FROM gerritcodereview/gerrit:3.0.12
+FROM gerritcodereview/gerrit:3.1.15
-ENV GERRIT_BRANCH=stable-3.0
+ENV GERRIT_BRANCH=stable-3.1
ENV GERRIT_CI_URL=https://archive-ci.gerritforge.com/job
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnableTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnableTest.java
index 9517f29..5139a66 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnableTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/GroupReindexRunnableTest.java
@@ -24,14 +24,12 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.data.GroupReference;
-import com.google.gerrit.reviewdb.client.Account.Id;
-import com.google.gerrit.reviewdb.client.AccountGroup;
-import com.google.gerrit.reviewdb.client.AccountGroup.UUID;
-import com.google.gerrit.reviewdb.client.AccountGroupById;
-import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
-import com.google.gerrit.reviewdb.client.AccountGroupMember;
-import com.google.gerrit.reviewdb.client.AccountGroupMember.Key;
-import com.google.gerrit.reviewdb.client.AccountGroupMemberAudit;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.Account.Id;
+import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.entities.AccountGroup.UUID;
+import com.google.gerrit.entities.AccountGroupByIdAudit;
+import com.google.gerrit.entities.AccountGroupMemberAudit;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.group.InternalGroup;
@@ -65,7 +63,7 @@
public void setUp() throws Exception {
groupReindexRunnable =
new GroupReindexRunnable(indexer, indexTs, ctx, groups, repoManager, allUsers);
- uuid = new UUID("123");
+ uuid = UUID.parse("123");
when(groupReference.getUUID()).thenReturn(uuid);
}
@@ -110,10 +108,12 @@
when(groups.getMembersAudit(any(), any()))
.thenReturn(
Collections.singletonList(
- new AccountGroupMemberAudit(
- new AccountGroupMember(new Key(new Id(1), new AccountGroup.Id(2))),
- null,
- afterCurrentTime)));
+ AccountGroupMemberAudit.builder()
+ .addedBy(Account.Id.tryParse("1").get())
+ .addedOn(afterCurrentTime)
+ .memberId(Account.Id.tryParse("1").get())
+ .groupId(AccountGroup.Id.parse("1"))
+ .build()));
Optional<Timestamp> groupLastTs =
groupReindexRunnable.indexIfNeeded(groupReference, currentTime);
assertThat(groupLastTs.isPresent()).isTrue();
@@ -128,11 +128,13 @@
Timestamp beforeCurrentTime = new Timestamp(currentTime.getTime() - 1000L);
AccountGroupMemberAudit accountGroupMemberAudit =
- new AccountGroupMemberAudit(
- new AccountGroupMember(new Key(new Id(1), new AccountGroup.Id(2))),
- null,
- beforeCurrentTime);
- accountGroupMemberAudit.removed(new Id(1), afterCurrentTime);
+ AccountGroupMemberAudit.builder()
+ .addedBy(Account.Id.tryParse("1").get())
+ .addedOn(beforeCurrentTime)
+ .memberId(Account.Id.tryParse("1").get())
+ .groupId(AccountGroup.Id.parse("2"))
+ .removed(Account.Id.tryParse("2").get(), afterCurrentTime)
+ .build();
when(groups.getGroup(uuid)).thenReturn(getInternalGroup(currentTime));
when(groups.getMembersAudit(any(), any()))
.thenReturn(Collections.singletonList(accountGroupMemberAudit));
@@ -152,11 +154,12 @@
when(groups.getSubgroupsAudit(any(), any()))
.thenReturn(
Collections.singletonList(
- new AccountGroupByIdAud(
- new AccountGroupById(
- new AccountGroupById.Key(new AccountGroup.Id(1), new UUID("123"))),
- null,
- afterCurrentTime)));
+ AccountGroupByIdAudit.builder()
+ .groupId(AccountGroup.Id.parse("1"))
+ .includeUuid(UUID.parse("123"))
+ .addedBy(Account.Id.tryParse("1").get())
+ .addedOn(afterCurrentTime)
+ .build()));
Optional<Timestamp> groupLastTs =
groupReindexRunnable.indexIfNeeded(groupReference, currentTime);
assertThat(groupLastTs.isPresent()).isTrue();
@@ -170,12 +173,15 @@
Timestamp afterCurrentTime = new Timestamp(currentTime.getTime() + 1000L);
Timestamp beforeCurrentTime = new Timestamp(currentTime.getTime() - 1000L);
- AccountGroupByIdAud accountGroupByIdAud =
- new AccountGroupByIdAud(
- new AccountGroupById(new AccountGroupById.Key(new AccountGroup.Id(1), new UUID("123"))),
- null,
- beforeCurrentTime);
- accountGroupByIdAud.removed(new Id(1), afterCurrentTime);
+ AccountGroupByIdAudit accountGroupByIdAud =
+ AccountGroupByIdAudit.builder()
+ .groupId(AccountGroup.Id.parse("1"))
+ .includeUuid(UUID.parse("123"))
+ .addedBy(Account.Id.tryParse("1").get())
+ .addedOn(beforeCurrentTime)
+ .removed(Account.Id.tryParse("2").get(), afterCurrentTime)
+ .build();
+
when(groups.getGroup(uuid)).thenReturn(getInternalGroup(beforeCurrentTime));
when(groups.getSubgroupsAudit(any(), any()))
.thenReturn(Collections.singletonList(accountGroupByIdAud));
@@ -189,7 +195,7 @@
private Optional<InternalGroup> getInternalGroup(Timestamp timestamp) {
AccountGroup accountGroup =
- new AccountGroup(new AccountGroup.NameKey("Test"), new AccountGroup.Id(1), uuid, timestamp);
+ new AccountGroup(AccountGroup.nameKey("Test"), AccountGroup.id(1), uuid, timestamp);
return Optional.ofNullable(
InternalGroup.create(
accountGroup,
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java
index 7233aac..e91e2ae 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionIT.java
@@ -33,7 +33,7 @@
import com.google.gerrit.acceptance.TestPlugin;
import com.google.gerrit.acceptance.UseLocalDisk;
import com.google.gerrit.acceptance.UseSsh;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.AccountGroup;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import java.util.Collections;
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventDeserializerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventDeserializerTest.java
deleted file mode 100644
index 2b9ee35..0000000
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/event/EventDeserializerTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (C) 2020 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.ericsson.gerrit.plugins.highavailability.event;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.ericsson.gerrit.plugins.highavailability.forwarder.rest.GsonProvider;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.server.data.AccountAttribute;
-import com.google.gerrit.server.data.RefUpdateAttribute;
-import com.google.gerrit.server.events.RefUpdatedEvent;
-import com.google.gson.Gson;
-import org.junit.Test;
-
-public class EventDeserializerTest {
- private static final String LEGACY_PROJECT_KEY = "{\"name\": \"project\"}";
-
- private static final String NEW_PROJECT_KEY = "\"project\"";
-
- private final Gson gson = new GsonProvider().get();
-
- @Test
- public void deserializePatchSetCreatedEventLegacyProjectKey() {
- Project.NameKey n = gson.fromJson(LEGACY_PROJECT_KEY, Project.NameKey.class);
- assertThat(n.get()).isEqualTo("project");
- }
-
- @Test
- public void deserializePatchSetCreatedEventNewProjectKey() {
- Project.NameKey n = gson.fromJson(NEW_PROJECT_KEY, Project.NameKey.class);
- assertThat(n.get()).isEqualTo("project");
- }
-
- @Test
- public void refUpdatedEventRoundTrip() {
- RefUpdatedEvent refUpdatedEvent = new RefUpdatedEvent();
-
- RefUpdateAttribute refUpdatedAttribute = new RefUpdateAttribute();
- refUpdatedAttribute.refName = "refs/heads/master";
- refUpdatedEvent.refUpdate = createSupplier(refUpdatedAttribute);
-
- AccountAttribute accountAttribute = new AccountAttribute();
- accountAttribute.email = "some.user@domain.com";
- refUpdatedEvent.submitter = createSupplier(accountAttribute);
-
- String serializedEvent = gson.toJson(refUpdatedEvent);
- RefUpdatedEvent e = gson.fromJson(serializedEvent, RefUpdatedEvent.class);
-
- assertThat(e).isNotNull();
- assertThat(e.refUpdate).isInstanceOf(Supplier.class);
- assertThat(e.refUpdate.get().refName).isEqualTo(refUpdatedAttribute.refName);
- assertThat(e.submitter).isInstanceOf(Supplier.class);
- assertThat(e.submitter.get().email).isEqualTo(accountAttribute.email);
- }
-
- private static <T> Supplier<T> createSupplier(T value) {
- return Suppliers.memoize(() -> value);
- }
-}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedCacheEvictionHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedCacheEvictionHandlerTest.java
index 44bb1ea..e09adae 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedCacheEvictionHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedCacheEvictionHandlerTest.java
@@ -22,8 +22,8 @@
import com.ericsson.gerrit.plugins.highavailability.cache.Constants;
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 org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,7 +55,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);
@@ -73,7 +73,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
@@ -96,7 +96,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/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedEventHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedEventHandlerTest.java
index 8ef8e2f..3e1f8fd 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedEventHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedEventHandlerTest.java
@@ -15,7 +15,7 @@
package com.ericsson.gerrit.plugins.highavailability.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;
@@ -82,12 +82,9 @@
.postEvent(event);
assertThat(Context.isForwardedEvent()).isFalse();
- try {
- handler.dispatch(event);
- fail("should have throw a PermissionBackendException");
- } catch (PermissionBackendException e) {
- assertThat(e.getMessage()).isEqualTo("someMessage");
- }
+ PermissionBackendException thrown =
+ assertThrows(PermissionBackendException.class, () -> handler.dispatch(event));
+ assertThat(thrown).hasMessageThat().isEqualTo("someMessage");
assertThat(Context.isForwardedEvent()).isFalse();
verify(dispatcherMock).postEvent(event);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandlerTest.java
index 14f3d54..0e9cee8 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexAccountHandlerTest.java
@@ -16,12 +16,11 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
-import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.server.index.account.AccountIndexer;
import java.io.IOException;
import java.util.Optional;
@@ -42,7 +41,7 @@
@Before
public void setUp() throws Exception {
handler = new ForwardedIndexAccountHandler(indexerMock);
- id = new Account.Id(123);
+ id = Account.id(123);
}
@Test
@@ -92,12 +91,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/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandlerTest.java
index a6da8e2..7c1e6df 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandlerTest.java
@@ -15,7 +15,7 @@
package com.ericsson.gerrit.plugins.highavailability.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.times;
@@ -26,7 +26,7 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
import com.ericsson.gerrit.plugins.highavailability.index.ChangeChecker;
import com.ericsson.gerrit.plugins.highavailability.index.ChangeCheckerImpl;
-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.OneOffRequestContext;
@@ -66,7 +66,7 @@
@Before
public void setUp() throws Exception {
- id = new Change.Id(TEST_CHANGE_NUMBER);
+ id = Change.id(TEST_CHANGE_NUMBER);
Change change = new Change(null, id, null, null, TimeUtil.nowTs());
when(changeNotes.getChange()).thenReturn(change);
when(configMock.index()).thenReturn(indexMock);
@@ -137,12 +137,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));
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandlerTest.java
index 7e30dea..5fdb151 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexGroupHandlerTest.java
@@ -16,12 +16,11 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
-import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.server.index.group.GroupIndexer;
import java.io.IOException;
import java.util.Optional;
@@ -42,7 +41,7 @@
@Before
public void setUp() throws Exception {
handler = new ForwardedIndexGroupHandler(indexerMock);
- uuid = new AccountGroup.UUID("123");
+ uuid = AccountGroup.uuid("123");
}
@Test
@@ -92,12 +91,10 @@
.index(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(uuid);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandlerTest.java
index ea36532..0c896b3 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexProjectHandlerTest.java
@@ -16,13 +16,12 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
-import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.index.project.ProjectIndexer;
-import com.google.gerrit.reviewdb.client.Project;
import java.io.IOException;
import java.util.Optional;
import org.junit.Before;
@@ -42,7 +41,7 @@
@Before
public void setUp() {
handler = new ForwardedIndexProjectHandler(indexerMock);
- nameKey = new Project.NameKey("project/name");
+ nameKey = Project.nameKey("project/name");
}
@Test
@@ -92,12 +91,10 @@
.index(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(nameKey);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java
index f5521c5..2067265 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java
@@ -19,7 +19,7 @@
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 org.junit.Before;
import org.junit.Test;
@@ -33,7 +33,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);
@Mock private ProjectCache projectCacheMock;
private ForwardedProjectListUpdateHandler handler;
@@ -108,7 +108,7 @@
assertThat(Context.isForwardedEvent()).isFalse();
RuntimeException thrown =
assertThrows(RuntimeException.class, () -> handler.update(PROJECT_NAME, false));
- assertThat(thrown).hasMessageThat().contains(SOME_MESSAGE);
+ assertThat(thrown).hasMessageThat().isEqualTo(SOME_MESSAGE);
assertThat(Context.isForwardedEvent()).isFalse();
verify(projectCacheMock).onCreateProject(PROJECT_KEY);
@@ -128,7 +128,7 @@
assertThat(Context.isForwardedEvent()).isFalse();
RuntimeException thrown =
assertThrows(RuntimeException.class, () -> handler.update(PROJECT_NAME, true));
- assertThat(thrown).hasMessageThat().contains(SOME_MESSAGE);
+ assertThat(thrown).hasMessageThat().isEqualTo(SOME_MESSAGE);
assertThat(Context.isForwardedEvent()).isFalse();
verify(projectCacheMock).remove(PROJECT_KEY);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java
index 8b08d24..44dd7f0 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java
@@ -24,6 +24,7 @@
import com.ericsson.gerrit.plugins.highavailability.cache.Constants;
import com.ericsson.gerrit.plugins.highavailability.forwarder.CacheNotFoundException;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedCacheEvictionHandler;
+import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
@@ -45,8 +46,7 @@
@Before
public void setUp() {
servlet =
- new CacheRestApiServlet(
- forwardedCacheEvictionHandlerMock, new GsonParser(new GsonProvider()));
+ new CacheRestApiServlet(forwardedCacheEvictionHandlerMock, new GsonParser(new Gson()));
}
@Test
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServletTest.java
index 7872785..3c6b931 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServletTest.java
@@ -25,10 +25,12 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedEventHandler;
import com.google.common.net.MediaType;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.server.events.EventGsonProvider;
import com.google.gerrit.server.events.EventTypes;
import com.google.gerrit.server.events.RefEvent;
import com.google.gerrit.server.permissions.PermissionBackendException;
+import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
@@ -49,6 +51,7 @@
@Mock private HttpServletRequest requestMock;
@Mock private HttpServletResponse responseMock;
private EventRestApiServlet eventRestApiServlet;
+ private Gson gson = new EventGsonProvider().get();
@BeforeClass
public static void setup() {
@@ -57,7 +60,7 @@
@Before
public void createEventsRestApiServlet() throws Exception {
- eventRestApiServlet = new EventRestApiServlet(forwardedEventHandlerMock, new GsonProvider());
+ eventRestApiServlet = new EventRestApiServlet(forwardedEventHandlerMock, gson);
when(requestMock.getContentType()).thenReturn(MediaType.JSON_UTF_8.toString());
}
@@ -129,7 +132,7 @@
@Override
public Project.NameKey getProjectNameKey() {
- return new Project.NameKey(project);
+ return Project.nameKey(project);
}
@Override
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java
index 2f6ce7e..5b76598 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java
@@ -17,33 +17,34 @@
import static com.google.common.truth.Truth.assertThat;
import com.ericsson.gerrit.plugins.highavailability.cache.Constants;
-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 org.junit.Test;
public class GsonParserTest {
private static final Object EMPTY_JSON = "{}";
- private final Gson gson = new Gson();
- private final GsonParser objectUnderTest = new GsonParser(new GsonProvider());
+ private final Gson gson = new EventGsonProvider().get();
+ private final GsonParser objectUnderTest = new GsonParser(gson);
@Test
public void accountIDParse() {
- Account.Id accountId = new Account.Id(1);
+ Account.Id accountId = Account.id(1);
String json = gson.toJson(accountId);
assertThat(accountId).isEqualTo(objectUnderTest.fromJson(Constants.ACCOUNTS, json));
}
@Test
public void accountGroupIDParse() {
- AccountGroup.Id accountGroupId = new AccountGroup.Id(1);
+ AccountGroup.Id accountGroupId = AccountGroup.id(1);
String json = gson.toJson(accountGroupId);
assertThat(accountGroupId).isEqualTo(objectUnderTest.fromJson(Constants.GROUPS, json));
}
@Test
public void accountGroupUUIDParse() {
- AccountGroup.UUID accountGroupUuid = new AccountGroup.UUID("abc123");
+ AccountGroup.UUID accountGroupUuid = AccountGroup.uuid("abc123");
String json = gson.toJson(accountGroupUuid);
assertThat(accountGroupUuid)
.isEqualTo(objectUnderTest.fromJson(Constants.GROUPS_BYINCLUDE, json));
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java
index 4071363..1edcd43 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpSessionTest.java
@@ -28,7 +28,7 @@
import com.github.tomakehurst.wiremock.http.Fault;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.github.tomakehurst.wiremock.stubbing.Scenario;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gson.Gson;
import java.net.SocketTimeoutException;
import org.junit.Before;
import org.junit.Rule;
@@ -71,7 +71,7 @@
when(configMock.http().socketTimeout()).thenReturn(TIMEOUT);
when(configMock.http().retryInterval()).thenReturn(RETRY_INTERVAL);
- httpSession = new HttpSession(new HttpClientProvider(configMock).get(), new GsonProvider());
+ httpSession = new HttpSession(new HttpClientProvider(configMock).get(), new Gson());
}
@Test
@@ -171,12 +171,4 @@
assertThat(httpSession.post(uri).isSuccessful()).isFalse();
}
-
- @Test
- public void encodeProjectName() {
- String projectStr = "project";
- Project.NameKey project = Project.nameKey(projectStr);
- String json = httpSession.jsonEncode(project);
- assertThat(json).isEqualTo("\"" + projectStr + "\"");
- }
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java
index 4622a17..83102a9 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java
@@ -26,7 +26,7 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexAccountHandler;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
-import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.entities.Account;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -51,7 +51,7 @@
@Before
public void setUpMocks() {
servlet = new IndexAccountRestApiServlet(handlerMock);
- id = new Account.Id(ACCOUNT_NUMBER);
+ id = Account.id(ACCOUNT_NUMBER);
when(requestMock.getRequestURI())
.thenReturn("http://gerrit.com/index/account/" + ACCOUNT_NUMBER);
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
index fb3649e..3da35d4 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
@@ -25,6 +25,7 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexChangeHandler;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
+import com.google.gson.Gson;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -50,7 +51,7 @@
@Before
public void setUpMocks() {
- servlet = new IndexChangeRestApiServlet(handlerMock);
+ servlet = new IndexChangeRestApiServlet(handlerMock, new Gson());
when(requestMock.getRequestURI())
.thenReturn("http://gerrit.com/index/change/" + PROJECT_NAME_URL_ENC + "~" + CHANGE_NUMBER);
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java
index 6291142..fb5788d 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java
@@ -26,7 +26,7 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexGroupHandler;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
-import com.google.gerrit.reviewdb.client.AccountGroup;
+import com.google.gerrit.entities.AccountGroup;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -51,7 +51,7 @@
@Before
public void setUpMocks() {
servlet = new IndexGroupRestApiServlet(handlerMock);
- uuid = new AccountGroup.UUID(UUID);
+ uuid = AccountGroup.uuid(UUID);
when(requestMock.getRequestURI()).thenReturn("http://gerrit.com/index/group/" + UUID);
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServletTest.java
index 83420b9..da6e70d 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexProjectRestApiServletTest.java
@@ -26,8 +26,8 @@
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexProjectHandler;
import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.restapi.Url;
-import com.google.gerrit.reviewdb.client.Project;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -52,7 +52,7 @@
@Before
public void setUpMocks() {
servlet = new IndexProjectRestApiServlet(handlerMock);
- nameKey = new Project.NameKey(PROJECT_NAME);
+ nameKey = Project.nameKey(PROJECT_NAME);
when(requestMock.getRequestURI())
.thenReturn("http://gerrit.com/index/project/" + Url.encode(nameKey.get()));
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java
index 55aa2c9..11ae77d 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java
@@ -20,8 +20,8 @@
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.TestPlugin;
import com.google.gerrit.acceptance.UseLocalDisk;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.restapi.Url;
-import com.google.gerrit.reviewdb.client.Project;
import org.junit.Test;
@NoHttpd
@@ -30,7 +30,7 @@
sysModule = "com.ericsson.gerrit.plugins.highavailability.Module",
httpModule = "com.ericsson.gerrit.plugins.highavailability.HttpModule")
public class ProjectListRestApiServletIT extends LightweightPluginDaemonTest {
- private static final Project.NameKey SOME_PROJECT = new Project.NameKey("org-a/some-project");
+ private static final Project.NameKey SOME_PROJECT = Project.nameKey("org-a/some-project");
@Test
@UseLocalDisk
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
index cb90461..7908669 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
@@ -30,8 +30,8 @@
import com.ericsson.gerrit.plugins.highavailability.peers.PeerInfo;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
-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.Event;
import com.google.gson.Gson;
import com.google.inject.Provider;
@@ -85,9 +85,6 @@
private static final String INDEX_GROUP_ENDPOINT =
Joiner.on("/").join(URL, PLUGINS, PLUGIN_NAME, "index/group", UUID);
- private GsonProvider gsonProvider = new GsonProvider();
- private Gson gson = gsonProvider.get();
-
// Event
private static Event event = new TestEvent();
private static final String EVENT_ENDPOINT =
@@ -98,6 +95,7 @@
private RestForwarder forwarder;
private HttpSession httpSessionMock;
+ private Gson gson = new Gson();
private Configuration configMock;
Provider<Set<PeerInfo>> peersMock;
@@ -116,7 +114,7 @@
PLUGIN_NAME,
configMock,
peersMock,
- gsonProvider, // TODO: Create provider
+ gson, // TODO: Create provider
new RestForwarderScheduler(Executors.newScheduledThreadPool(1)));
}
@@ -293,7 +291,7 @@
@Test
public void testEvictAccountsOK() throws Exception {
- Account.Id key = new Account.Id(123);
+ Account.Id key = Account.id(123);
String keyJson = gson.toJson(key);
when(httpSessionMock.post(buildCacheEndpoint(Constants.ACCOUNTS), keyJson))
.thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
@@ -303,7 +301,7 @@
@Test
public void testEvictGroupsOK() throws Exception {
- AccountGroup.Id key = new AccountGroup.Id(123);
+ AccountGroup.Id key = AccountGroup.id(123);
String keyJson = gson.toJson(key);
String endpoint = buildCacheEndpoint(Constants.GROUPS);
when(httpSessionMock.post(endpoint, keyJson)).thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
@@ -313,7 +311,7 @@
@Test
public void testEvictGroupsByIncludeOK() throws Exception {
- AccountGroup.UUID key = new AccountGroup.UUID("90b3042d9094a37985f3f9281391dbbe9a5addad");
+ AccountGroup.UUID key = AccountGroup.uuid("90b3042d9094a37985f3f9281391dbbe9a5addad");
String keyJson = gson.toJson(key);
when(httpSessionMock.post(buildCacheEndpoint(Constants.GROUPS_BYINCLUDE), keyJson))
.thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
@@ -324,7 +322,7 @@
@Test
public void testEvictGroupsMembersOK() throws Exception {
- AccountGroup.UUID key = new AccountGroup.UUID("90b3042d9094a37985f3f9281391dbbe9a5addad");
+ AccountGroup.UUID key = AccountGroup.uuid("90b3042d9094a37985f3f9281391dbbe9a5addad");
String keyJson = gson.toJson(key);
when(httpSessionMock.post(buildCacheEndpoint(Constants.GROUPS_MEMBERS), keyJson))
.thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerIT.java
index bc5210d..febf8f0 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerIT.java
@@ -20,7 +20,7 @@
import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
import com.google.gerrit.acceptance.PushOneCommit.Result;
import com.google.gerrit.acceptance.TestPlugin;
-import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.entities.RefNames;
import java.io.IOException;
import java.util.Optional;
import org.eclipse.jgit.lib.Ref;
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java
index 5f08cc5..578dc17 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java
@@ -35,9 +35,9 @@
import com.ericsson.gerrit.plugins.highavailability.index.IndexEventHandler.IndexGroupTask;
import com.ericsson.gerrit.plugins.highavailability.index.IndexEventHandler.IndexTask;
import com.ericsson.gerrit.plugins.highavailability.index.IndexEventLocks.VoidFunction;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.AccountGroup;
-import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.entities.Change;
import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext;
@@ -102,9 +102,9 @@
@Before
public void setUpMocks() throws Exception {
- changeId = new Change.Id(CHANGE_ID);
- accountId = new Account.Id(ACCOUNT_ID);
- accountGroupUUID = new AccountGroup.UUID(UUID);
+ changeId = Change.id(CHANGE_ID);
+ accountId = Account.id(ACCOUNT_ID);
+ accountGroupUUID = AccountGroup.uuid(UUID);
when(changeCheckerFactoryMock.create(any())).thenReturn(changeCheckerMock);
when(changeCheckerMock.newIndexEvent()).thenReturn(Optional.of(new IndexEvent()));
diff --git a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json
index 2405b03..026b03a 100644
--- a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json
+++ b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json
@@ -1,5 +1,5 @@
[
{
- "url": "HTTP_SCHEME://HOSTNAME/a/projects/PROJECT/delete-project~delete"
+ "url": "HTTP_SCHEME://HOSTNAME:CLUSTER_PORT/a/projects/PROJECT/delete-project~delete"
}
]
diff --git a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.json b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.json
index 25521c7..8401fa4 100644
--- a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.json
+++ b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.json
@@ -1,5 +1,5 @@
[
{
- "url": "HTTP_SCHEME://HOSTNAME/a/config/server/caches/projects"
+ "url": "HTTP_SCHEME://HOSTNAME:CLUSTER_PORT/a/config/server/caches/projects"
}
]
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CheckProjectsCacheFlushEntriesUsingHAGerrit1.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CheckProjectsCacheFlushEntriesUsingHAGerrit1.scala
index 6a0d07f..09ba6d4 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CheckProjectsCacheFlushEntriesUsingHAGerrit1.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CheckProjectsCacheFlushEntriesUsingHAGerrit1.scala
@@ -22,9 +22,10 @@
class CheckProjectsCacheFlushEntriesUsingHAGerrit1 extends CacheFlushSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
override def replaceOverride(in: String): String = {
- replaceProperty("http_port1", 8081, in)
+ replaceProperty("http_port1", default.httpPort1, in)
}
def this(producer: CacheFlushSimulation) {
@@ -42,7 +43,7 @@
}
})
.exec(http(uniqueName).get("${url}")
- .check(regex("\"" + memKey + "\": (\\d+)")
+ .check(regex("\"" + memKey + "\":(\\d+)")
.is(session => session(entriesKey).as[String])))
setUp(
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
index 4fa0ca5..a03a731 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
@@ -23,6 +23,7 @@
class CloneUsingHAGerrit2 extends GitSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
private var projectName = className
def this(projectName: String) {
@@ -31,7 +32,7 @@
}
override def replaceOverride(in: String): String = {
- val next = replaceProperty("http_port2", 8082, in)
+ val next = replaceProperty("http_port2", default.httpPort2, in)
replaceKeyWith("_project", projectName, next)
}
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/ClusterDefault.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/ClusterDefault.scala
new file mode 100644
index 0000000..58bbc7e
--- /dev/null
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/ClusterDefault.scala
@@ -0,0 +1,21 @@
+// 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.ericsson.gerrit.plugins.highavailability.scenarios
+
+class ClusterDefault {
+ val clusterHttpPort: Int = 80
+ val httpPort1: Int = 8081
+ val httpPort2: Int = 8082
+}
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateChangeUsingHAGerrit1.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateChangeUsingHAGerrit1.scala
index 26732b6..7969af0 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateChangeUsingHAGerrit1.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateChangeUsingHAGerrit1.scala
@@ -24,20 +24,20 @@
class CreateChangeUsingHAGerrit1 extends GerritSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
private val projectName = className
- private val numberKey = "_number"
override def relativeRuntimeWeight = 10
override def replaceOverride(in: String): String = {
- replaceProperty("http_port1", 8081, in)
+ replaceProperty("http_port1", default.httpPort1, in)
}
private val test: ScenarioBuilder = scenario(uniqueName)
.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/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
index 5773bcf..72a1068 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
@@ -21,6 +21,7 @@
class CreateProjectUsingHAGerrit1 extends ProjectSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
def this(projectName: String) {
this()
@@ -28,7 +29,7 @@
}
override def replaceOverride(in: String): String = {
- val next = replaceProperty("http_port1", 8081, in)
+ val next = replaceProperty("http_port1", default.httpPort1, in)
super.replaceOverride(next)
}
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteChangeUsingHAGerrit2.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteChangeUsingHAGerrit2.scala
index d3dc7c1..c8e1c50 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteChangeUsingHAGerrit2.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteChangeUsingHAGerrit2.scala
@@ -22,24 +22,25 @@
class DeleteChangeUsingHAGerrit2 extends GerritSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
var number: Option[Int] = None
override def relativeRuntimeWeight = 10
override def replaceOverride(in: String): String = {
- replaceProperty("http_port2", 8082, in)
+ replaceProperty("http_port2", default.httpPort2, in)
}
val test: ScenarioBuilder = scenario(uniqueName)
.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(
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
index cdc6e9e..d9feedb 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
@@ -21,12 +21,18 @@
class DeleteProjectUsingHAGerrit extends ProjectSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
def this(projectName: String) {
this()
this.projectName = projectName
}
+ override def replaceOverride(in: String): String = {
+ val next = replaceProperty("cluster_port", default.clusterHttpPort, in)
+ super.replaceOverride(next)
+ }
+
val test: ScenarioBuilder = scenario(uniqueName)
.feed(data)
.exec(httpRequest)
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/FlushProjectsCacheUsingHAGerrit2.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/FlushProjectsCacheUsingHAGerrit2.scala
index 4f619b8..d6eff71 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/FlushProjectsCacheUsingHAGerrit2.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/FlushProjectsCacheUsingHAGerrit2.scala
@@ -23,12 +23,13 @@
class FlushProjectsCacheUsingHAGerrit2 extends CacheFlushSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
private val projectName = className
override def relativeRuntimeWeight = 2
override def replaceOverride(in: String): String = {
- replaceProperty("http_port2", 8082, in)
+ replaceProperty("http_port2", default.httpPort2, in)
}
private val flushCache: ScenarioBuilder = scenario(uniqueName)
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.scala
index ed19c0b..6938c74 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/GetProjectsCacheEntries.scala
@@ -22,16 +22,21 @@
class GetProjectsCacheEntries extends CacheFlushSimulation {
private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+ private val default: ClusterDefault = new ClusterDefault
def this(consumer: CacheFlushSimulation) {
this()
this.consumer = Some(consumer)
}
+ override def replaceOverride(in: String): String = {
+ replaceProperty("cluster_port", default.clusterHttpPort, in)
+ }
+
val test: ScenarioBuilder = scenario(uniqueName)
.feed(data)
.exec(http(uniqueName).get("${url}")
- .check(regex("\"" + memKey + "\": (\\d+)").saveAs(entriesKey)))
+ .check(regex("\"" + memKey + "\":(\\d+)").saveAs(entriesKey)))
.exec(session => {
if (consumer.nonEmpty) {
consumer.get.entriesBeforeFlush(session(entriesKey).as[Int])