diff options
author | Patrick Hiesel <hiesel@google.com> | 2022-05-06 07:35:32 +0200 |
---|---|---|
committer | David Ostrovsky <david@ostrovsky.org> | 2022-05-11 10:20:30 +0200 |
commit | 3fdeacca5aa317633b91d28d91101da0568541f0 (patch) | |
tree | a7d9a4d5f4ed011640263e02bf5873eb53dad3cc | |
parent | 9a0fb8defab2630b12a87d6205818cd198669d4b (diff) |
IndexOperations: Centralize disabling reading/writing to/from indices
AbstractDaemonTest used to contain logic to disable secondary indices.
This means more code in an overly full class and also made it hard
to reuse that code in tests that did not inherit from AbstractDaemonTest.
This commit factors out this logic in the spirit of *Operations test APIs.
You can inject a IndexOperations.{Change,Account,...} and use it to
disable reads/writes.
Release-Notes: n/a
Change-Id: I26f59ac8a667b29d4138e8aadad647488d36f082
11 files changed, 200 insertions, 200 deletions
diff --git a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java index 2083050a1f..903b709093 100644 --- a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java +++ b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java @@ -100,8 +100,6 @@ import com.google.gerrit.extensions.common.EditInfo; import com.google.gerrit.extensions.restapi.BinaryResult; import com.google.gerrit.extensions.restapi.IdString; import com.google.gerrit.extensions.restapi.RestApiException; -import com.google.gerrit.index.project.ProjectIndex; -import com.google.gerrit.index.project.ProjectIndexCollection; import com.google.gerrit.json.OutputFormat; import com.google.gerrit.server.GerritPersonIdent; import com.google.gerrit.server.IdentifiedUser; @@ -128,11 +126,7 @@ import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.meta.MetaDataUpdate; import com.google.gerrit.server.group.SystemGroupBackend; -import com.google.gerrit.server.index.account.AccountIndex; -import com.google.gerrit.server.index.account.AccountIndexCollection; import com.google.gerrit.server.index.account.AccountIndexer; -import com.google.gerrit.server.index.change.ChangeIndex; -import com.google.gerrit.server.index.change.ChangeIndexCollection; import com.google.gerrit.server.index.change.ChangeIndexer; import com.google.gerrit.server.notedb.AbstractChangeNotes; import com.google.gerrit.server.notedb.ChangeNoteUtil; @@ -315,14 +309,11 @@ public abstract class AbstractDaemonTest { protected BlockStrategy noSleepBlockStrategy = t -> {}; // Don't sleep in tests. @Inject private AbstractChangeNotes.Args changeNotesArgs; - @Inject private AccountIndexCollection accountIndexes; @Inject private AccountIndexer accountIndexer; - @Inject private ChangeIndexCollection changeIndexes; @Inject private EventRecorder.Factory eventRecorderFactory; @Inject private InProcessProtocol inProcessProtocol; @Inject private PluginGuiceEnvironment pluginGuiceEnvironment; @Inject private PluginUser.Factory pluginUserFactory; - @Inject private ProjectIndexCollection projectIndexes; @Inject private RequestScopeOperations requestScopeOperations; @Inject private SitePaths sitePaths; @Inject private ProjectOperations projectOperations; @@ -1072,87 +1063,6 @@ public abstract class AbstractDaemonTest { }; } - protected void disableChangeIndexWrites() { - for (ChangeIndex i : changeIndexes.getWriteIndexes()) { - if (!(i instanceof ReadOnlyChangeIndex)) { - changeIndexes.addWriteIndex(new ReadOnlyChangeIndex(i)); - } - } - } - - protected void enableChangeIndexWrites() { - for (ChangeIndex i : changeIndexes.getWriteIndexes()) { - if (i instanceof ReadOnlyChangeIndex) { - changeIndexes.addWriteIndex(((ReadOnlyChangeIndex) i).unwrap()); - } - } - } - - protected AutoCloseable disableChangeIndex() { - disableChangeIndexWrites(); - ChangeIndex maybeDisabledSearchIndex = changeIndexes.getSearchIndex(); - if (!(maybeDisabledSearchIndex instanceof DisabledChangeIndex)) { - changeIndexes.setSearchIndex(new DisabledChangeIndex(maybeDisabledSearchIndex), false); - } - - return () -> { - enableChangeIndexWrites(); - ChangeIndex maybeEnabledSearchIndex = changeIndexes.getSearchIndex(); - if (maybeEnabledSearchIndex instanceof DisabledChangeIndex) { - changeIndexes.setSearchIndex( - ((DisabledChangeIndex) maybeEnabledSearchIndex).unwrap(), false); - } - }; - } - - protected AutoCloseable disableAccountIndex() { - AccountIndex maybeDisabledSearchIndex = accountIndexes.getSearchIndex(); - if (!(maybeDisabledSearchIndex instanceof DisabledAccountIndex)) { - accountIndexes.setSearchIndex(new DisabledAccountIndex(maybeDisabledSearchIndex), false); - } - - return () -> { - AccountIndex maybeEnabledSearchIndex = accountIndexes.getSearchIndex(); - if (maybeEnabledSearchIndex instanceof DisabledAccountIndex) { - accountIndexes.setSearchIndex( - ((DisabledAccountIndex) maybeEnabledSearchIndex).unwrap(), false); - } - }; - } - - protected AutoCloseable disableProjectIndex() { - disableProjectIndexWrites(); - ProjectIndex maybeDisabledSearchIndex = projectIndexes.getSearchIndex(); - if (!(maybeDisabledSearchIndex instanceof DisabledProjectIndex)) { - projectIndexes.setSearchIndex(new DisabledProjectIndex(maybeDisabledSearchIndex), false); - } - - return () -> { - enableProjectIndexWrites(); - ProjectIndex maybeEnabledSearchIndex = projectIndexes.getSearchIndex(); - if (maybeEnabledSearchIndex instanceof DisabledProjectIndex) { - projectIndexes.setSearchIndex( - ((DisabledProjectIndex) maybeEnabledSearchIndex).unwrap(), false); - } - }; - } - - protected void disableProjectIndexWrites() { - for (ProjectIndex i : projectIndexes.getWriteIndexes()) { - if (!(i instanceof DisabledProjectIndex)) { - projectIndexes.addWriteIndex(new DisabledProjectIndex(i)); - } - } - } - - protected void enableProjectIndexWrites() { - for (ProjectIndex i : projectIndexes.getWriteIndexes()) { - if (i instanceof DisabledProjectIndex) { - projectIndexes.addWriteIndex(((DisabledProjectIndex) i).unwrap()); - } - } - } - protected static Gson newGson() { return OutputFormat.JSON_COMPACT.newGson(); } diff --git a/java/com/google/gerrit/acceptance/ReadOnlyChangeIndex.java b/java/com/google/gerrit/acceptance/ReadOnlyChangeIndex.java deleted file mode 100644 index f7a0669739..0000000000 --- a/java/com/google/gerrit/acceptance/ReadOnlyChangeIndex.java +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2016 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.google.gerrit.acceptance; - -import com.google.gerrit.entities.Change; -import com.google.gerrit.index.QueryOptions; -import com.google.gerrit.index.Schema; -import com.google.gerrit.index.query.DataSource; -import com.google.gerrit.index.query.Predicate; -import com.google.gerrit.index.query.QueryParseException; -import com.google.gerrit.server.index.change.ChangeIndex; -import com.google.gerrit.server.query.change.ChangeData; - -class ReadOnlyChangeIndex implements ChangeIndex { - private final ChangeIndex index; - - ReadOnlyChangeIndex(ChangeIndex index) { - this.index = index; - } - - ChangeIndex unwrap() { - return index; - } - - @Override - public Schema<ChangeData> getSchema() { - return index.getSchema(); - } - - @Override - public void close() { - index.close(); - } - - @Override - public void insert(ChangeData obj) { - // do nothing - } - - @Override - public void replace(ChangeData obj) { - // do nothing - } - - @Override - public void delete(Change.Id key) { - // do nothing - } - - @Override - public void deleteAll() { - // do nothing - } - - @Override - public DataSource<ChangeData> getSource(Predicate<ChangeData> p, QueryOptions opts) - throws QueryParseException { - return index.getSource(p, opts); - } - - @Override - public void markReady(boolean ready) { - // do nothing - } -} diff --git a/java/com/google/gerrit/acceptance/testsuite/change/IndexOperations.java b/java/com/google/gerrit/acceptance/testsuite/change/IndexOperations.java new file mode 100644 index 0000000000..cba9b155c5 --- /dev/null +++ b/java/com/google/gerrit/acceptance/testsuite/change/IndexOperations.java @@ -0,0 +1,162 @@ +// Copyright (C) 2022 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.google.gerrit.acceptance.testsuite.change; + +import com.google.gerrit.acceptance.DisabledAccountIndex; +import com.google.gerrit.acceptance.DisabledChangeIndex; +import com.google.gerrit.acceptance.DisabledProjectIndex; +import com.google.gerrit.index.project.ProjectIndex; +import com.google.gerrit.index.project.ProjectIndexCollection; +import com.google.gerrit.server.index.account.AccountIndex; +import com.google.gerrit.server.index.account.AccountIndexCollection; +import com.google.gerrit.server.index.change.ChangeIndex; +import com.google.gerrit.server.index.change.ChangeIndexCollection; +import com.google.inject.Inject; + +/** Helpers to enable and disable reads/writes to secondary indices during testing. */ +public interface IndexOperations { + /** + * Disables reads from the secondary index that this instance is scoped to. Reads fail with {@code + * UnsupportedOperationException}. + */ + AutoCloseable disableReads(); + + /** + * Disables writes to the secondary index that this instance is scoped to. Writes fail with {@code + * UnsupportedOperationException}. + */ + AutoCloseable disableWrites(); + + /** Disables reads from and writes to the secondary index that this instance is scoped to. */ + default AutoCloseable disableReadsAndWrites() { + AutoCloseable reads = disableReads(); + AutoCloseable writes = disableWrites(); + return () -> { + reads.close(); + writes.close(); + }; + } + + class Change implements IndexOperations { + @Inject private ChangeIndexCollection indices; + + @Override + public AutoCloseable disableReads() { + ChangeIndex maybeDisabledSearchIndex = indices.getSearchIndex(); + if (!(maybeDisabledSearchIndex instanceof DisabledChangeIndex)) { + indices.setSearchIndex( + new DisabledChangeIndex(maybeDisabledSearchIndex), /* closeOld */ false); + } + + return () -> { + ChangeIndex maybeEnabledSearchIndex = indices.getSearchIndex(); + if (maybeEnabledSearchIndex instanceof DisabledChangeIndex) { + indices.setSearchIndex( + ((DisabledChangeIndex) maybeEnabledSearchIndex).unwrap(), /* closeOld */ false); + } + }; + } + + @Override + public AutoCloseable disableWrites() { + for (ChangeIndex i : indices.getWriteIndexes()) { + if (!(i instanceof DisabledChangeIndex)) { + indices.addWriteIndex(new DisabledChangeIndex(i)); + } + } + return () -> { + for (ChangeIndex i : indices.getWriteIndexes()) { + if (i instanceof DisabledChangeIndex) { + indices.addWriteIndex(((DisabledChangeIndex) i).unwrap()); + } + } + }; + } + } + + class Account implements IndexOperations { + @Inject private AccountIndexCollection indices; + + @Override + public AutoCloseable disableReads() { + AccountIndex maybeDisabledSearchIndex = indices.getSearchIndex(); + if (!(maybeDisabledSearchIndex instanceof DisabledAccountIndex)) { + indices.setSearchIndex( + new DisabledAccountIndex(maybeDisabledSearchIndex), /* closeOld */ false); + } + + return () -> { + AccountIndex maybeEnabledSearchIndex = indices.getSearchIndex(); + if (maybeEnabledSearchIndex instanceof DisabledAccountIndex) { + indices.setSearchIndex( + ((DisabledAccountIndex) maybeEnabledSearchIndex).unwrap(), /* closeOld */ false); + } + }; + } + + @Override + public AutoCloseable disableWrites() { + for (AccountIndex i : indices.getWriteIndexes()) { + if (!(i instanceof DisabledAccountIndex)) { + indices.addWriteIndex(new DisabledAccountIndex(i)); + } + } + return () -> { + for (AccountIndex i : indices.getWriteIndexes()) { + if (i instanceof DisabledAccountIndex) { + indices.addWriteIndex(((DisabledAccountIndex) i).unwrap()); + } + } + }; + } + } + + class Project implements IndexOperations { + @Inject private ProjectIndexCollection indices; + + @Override + public AutoCloseable disableReads() { + ProjectIndex maybeDisabledSearchIndex = indices.getSearchIndex(); + if (!(maybeDisabledSearchIndex instanceof DisabledProjectIndex)) { + indices.setSearchIndex( + new DisabledProjectIndex(maybeDisabledSearchIndex), /* closeOld */ false); + } + + return () -> { + ProjectIndex maybeEnabledSearchIndex = indices.getSearchIndex(); + if (maybeEnabledSearchIndex instanceof DisabledProjectIndex) { + indices.setSearchIndex( + ((DisabledProjectIndex) maybeEnabledSearchIndex).unwrap(), /* closeOld */ false); + } + }; + } + + @Override + public AutoCloseable disableWrites() { + for (ProjectIndex i : indices.getWriteIndexes()) { + if (!(i instanceof DisabledProjectIndex)) { + indices.addWriteIndex(new DisabledProjectIndex(i)); + } + } + return () -> { + for (ProjectIndex i : indices.getWriteIndexes()) { + if (i instanceof DisabledProjectIndex) { + indices.addWriteIndex(((DisabledProjectIndex) i).unwrap()); + } + } + }; + } + } +} diff --git a/javatests/com/google/gerrit/acceptance/api/change/ChangeIT.java b/javatests/com/google/gerrit/acceptance/api/change/ChangeIT.java index db7d3023a8..c5f0d232fb 100644 --- a/javatests/com/google/gerrit/acceptance/api/change/ChangeIT.java +++ b/javatests/com/google/gerrit/acceptance/api/change/ChangeIT.java @@ -85,6 +85,7 @@ import com.google.gerrit.acceptance.UseTimezone; import com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes; import com.google.gerrit.acceptance.config.GerritConfig; import com.google.gerrit.acceptance.testsuite.account.AccountOperations; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.group.GroupOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations; @@ -232,6 +233,7 @@ public class ChangeIT extends AbstractDaemonTest { @Inject private ProjectOperations projectOperations; @Inject private RequestScopeOperations requestScopeOperations; @Inject private ExtensionRegistry extensionRegistry; + @Inject private IndexOperations.Change changeIndexOperations; @Inject @Named("diff_intraline") @@ -3155,11 +3157,8 @@ public class ChangeIT extends AbstractDaemonTest { public void submitStaleChange() throws Exception { PushOneCommit.Result r = createChange(); - disableChangeIndexWrites(); - try { + try (AutoCloseable ignored = changeIndexOperations.disableWrites()) { r = amendChange(r.getChangeId()); - } finally { - enableChangeIndexWrites(); } gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve()); @@ -4700,7 +4699,7 @@ public class ChangeIT extends AbstractDaemonTest { PushOneCommit.Result change = createChange(); int number = gApi.changes().id(change.getChangeId()).get()._number; - try (AutoCloseable ignored = disableChangeIndex()) { + try (AutoCloseable ignored = changeIndexOperations.disableReadsAndWrites()) { assertThat(gApi.changes().id(project.get(), number).get(options).changeId) .isEqualTo(change.getChangeId()); } diff --git a/javatests/com/google/gerrit/acceptance/api/change/SubmitRequirementIT.java b/javatests/com/google/gerrit/acceptance/api/change/SubmitRequirementIT.java index 61e55ffc25..865dd6c1bf 100644 --- a/javatests/com/google/gerrit/acceptance/api/change/SubmitRequirementIT.java +++ b/javatests/com/google/gerrit/acceptance/api/change/SubmitRequirementIT.java @@ -34,6 +34,7 @@ import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.UseTimezone; import com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate; import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations; @@ -95,6 +96,7 @@ public class SubmitRequirementIT extends AbstractDaemonTest { @Inject private ProjectOperations projectOperations; @Inject private RequestScopeOperations requestScopeOperations; @Inject private ExtensionRegistry extensionRegistry; + @Inject private IndexOperations.Change changeIndexOperations; @Test public void submitRecords() throws Exception { @@ -1049,8 +1051,7 @@ public class SubmitRequirementIT extends AbstractDaemonTest { // disable change index writes so that the change in the index gets stale when the new submit // requirement is added - disableChangeIndexWrites(); - try { + try (AutoCloseable ignored = changeIndexOperations.disableWrites()) { // Override submit requirement in project (allow uploaders to self approve). configSubmitRequirement( project, @@ -1073,8 +1074,6 @@ public class SubmitRequirementIT extends AbstractDaemonTest { assertThat(actions).containsKey("submit"); ActionInfo submitAction = actions.get("submit"); assertThat(submitAction.enabled).isTrue(); - } finally { - enableChangeIndexWrites(); } } diff --git a/javatests/com/google/gerrit/acceptance/api/project/ProjectIndexerIT.java b/javatests/com/google/gerrit/acceptance/api/project/ProjectIndexerIT.java index e45d95c76f..a625a7088f 100644 --- a/javatests/com/google/gerrit/acceptance/api/project/ProjectIndexerIT.java +++ b/javatests/com/google/gerrit/acceptance/api/project/ProjectIndexerIT.java @@ -21,6 +21,7 @@ import static com.google.gerrit.testing.GerritJUnit.assertThrows; import com.google.common.collect.ImmutableSet; import com.google.gerrit.acceptance.AbstractDaemonTest; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.entities.Project; import com.google.gerrit.exceptions.StorageException; @@ -50,6 +51,7 @@ public class ProjectIndexerIT extends AbstractDaemonTest { @Inject private IndexConfig indexConfig; @Inject private StalenessChecker stalenessChecker; @Inject private ProjectOperations projectOperations; + @Inject private IndexOperations.Project projectIndexOperations; private static final ImmutableSet<String> FIELDS = ImmutableSet.of(ProjectField.NAME.getName(), ProjectField.REF_STATE.getName()); @@ -124,7 +126,7 @@ public class ProjectIndexerIT extends AbstractDaemonTest { assertThrows( StorageException.class, () -> { - try (AutoCloseable ignored = disableProjectIndex()) { + try (AutoCloseable ignored = projectIndexOperations.disableReadsAndWrites()) { try (ProjectConfigUpdate u = updateProject(project)) { update.accept(u.getConfig()); u.save(); diff --git a/javatests/com/google/gerrit/acceptance/git/RefAdvertisementIT.java b/javatests/com/google/gerrit/acceptance/git/RefAdvertisementIT.java index 0905587f1b..f58f81c192 100644 --- a/javatests/com/google/gerrit/acceptance/git/RefAdvertisementIT.java +++ b/javatests/com/google/gerrit/acceptance/git/RefAdvertisementIT.java @@ -32,6 +32,7 @@ import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.TestAccount; import com.google.gerrit.acceptance.config.GerritConfig; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations; import com.google.gerrit.common.Nullable; @@ -82,6 +83,7 @@ public class RefAdvertisementIT extends AbstractDaemonTest { @Inject private PermissionBackend permissionBackend; @Inject private ProjectOperations projectOperations; @Inject private RequestScopeOperations requestScopeOperations; + @Inject private IndexOperations.Change changeIndexOperations; private AccountGroup.UUID admins; private AccountGroup.UUID nonInteractiveUsers; @@ -1395,7 +1397,7 @@ public class RefAdvertisementIT extends AbstractDaemonTest { public void fetchSingleChangeWithoutIndexAccess() throws Exception { PushOneCommit.Result change = createChange(); String patchSetRef = change.getPatchSetId().toRefName(); - try (AutoCloseable ignored = disableChangeIndex(); + try (AutoCloseable ignored = changeIndexOperations.disableReadsAndWrites(); Repository repo = repoManager.openRepository(project)) { ImmutableList<Ref> singleRef = ImmutableList.of(repo.exactRef(patchSetRef)); ImmutableList<Ref> filteredRefs = diff --git a/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java b/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java index 1c8ca93c56..d2aab5b398 100644 --- a/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java +++ b/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java @@ -22,6 +22,7 @@ import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.UseClockStep; import com.google.gerrit.acceptance.config.GerritConfig; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.entities.Project; import com.google.gerrit.entities.RefNames; @@ -53,6 +54,8 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription { } @Inject private ProjectOperations projectOperations; + @Inject private IndexOperations.Change changeIndexOperations; + @Inject private IndexOperations.Account accountIndexOperations; @Inject private SubmitRuleEvaluator.Factory evaluatorFactory; @Test @@ -747,12 +750,10 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription { } private String getStatus(ChangeData cd) throws Exception { - - try (AutoCloseable changeIndex = disableChangeIndex()) { - try (AutoCloseable accountIndex = disableAccountIndex()) { - SubmitRuleEvaluator ruleEvaluator = evaluatorFactory.create(SubmitRuleOptions.defaults()); - return ruleEvaluator.evaluate(cd).iterator().next().status.toString(); - } + try (AutoCloseable ignored = changeIndexOperations.disableReadsAndWrites(); + AutoCloseable accountIndex = accountIndexOperations.disableReadsAndWrites()) { + SubmitRuleEvaluator ruleEvaluator = evaluatorFactory.create(SubmitRuleOptions.defaults()); + return ruleEvaluator.evaluate(cd).iterator().next().status.toString(); } } diff --git a/javatests/com/google/gerrit/acceptance/server/change/GetRelatedIT.java b/javatests/com/google/gerrit/acceptance/server/change/GetRelatedIT.java index fd3ac7f384..8bf744355b 100644 --- a/javatests/com/google/gerrit/acceptance/server/change/GetRelatedIT.java +++ b/javatests/com/google/gerrit/acceptance/server/change/GetRelatedIT.java @@ -31,6 +31,7 @@ import com.google.gerrit.acceptance.UseClockStep; import com.google.gerrit.acceptance.UseTimezone; import com.google.gerrit.acceptance.config.GerritConfig; import com.google.gerrit.acceptance.testsuite.account.AccountOperations; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.group.GroupOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations; @@ -82,6 +83,7 @@ public class GetRelatedIT extends AbstractDaemonTest { @Inject private GroupOperations groupOperations; @Inject private ProjectOperations projectOperations; @Inject private RequestScopeOperations requestScopeOperations; + @Inject private IndexOperations.Change changeIndexOperations; @Inject private IndexConfig indexConfig; @Inject private ChangesCollection changes; @@ -545,11 +547,8 @@ public class GetRelatedIT extends AbstractDaemonTest { RevCommit c2_2 = testRepo.amend(c2_1).add("b.txt", "2").create(); testRepo.reset(c2_2); - disableChangeIndexWrites(); - try { + try (AutoCloseable ignored = changeIndexOperations.disableWrites()) { pushHead(testRepo, "refs/for/master", false); - } finally { - enableChangeIndexWrites(); } PatchSet.Id psId1_1 = getPatchSetId(c1_1); diff --git a/javatests/com/google/gerrit/acceptance/server/rules/RulesIT.java b/javatests/com/google/gerrit/acceptance/server/rules/RulesIT.java index 3ba7829968..4f93dd6946 100644 --- a/javatests/com/google/gerrit/acceptance/server/rules/RulesIT.java +++ b/javatests/com/google/gerrit/acceptance/server/rules/RulesIT.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableMap; import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.PushOneCommit; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.entities.RefNames; import com.google.gerrit.entities.SubmitRecord; @@ -43,6 +44,8 @@ import org.junit.Test; public class RulesIT extends AbstractDaemonTest { @Inject private ProjectOperations projectOperations; @Inject private SubmitRuleEvaluator.Factory evaluatorFactory; + @Inject private IndexOperations.Change changeIndexOperations; + @Inject private IndexOperations.Account accountIndexOperations; @Test public void testUnresolvedCommentsCountPredicate() throws Exception { @@ -240,8 +243,8 @@ public class RulesIT extends AbstractDaemonTest { ChangeData cd = result.getChange(); Collection<SubmitRecord> records; - try (AutoCloseable ignored1 = disableChangeIndex(); - AutoCloseable ignored2 = disableAccountIndex()) { + try (AutoCloseable ignored1 = changeIndexOperations.disableReadsAndWrites(); + AutoCloseable ignored2 = accountIndexOperations.disableReadsAndWrites()) { SubmitRuleEvaluator ruleEvaluator = evaluatorFactory.create(SubmitRuleOptions.defaults()); records = ruleEvaluator.evaluate(cd); } diff --git a/javatests/com/google/gerrit/acceptance/ssh/AbstractIndexTests.java b/javatests/com/google/gerrit/acceptance/ssh/AbstractIndexTests.java index 18c4952ea9..2a0690048e 100644 --- a/javatests/com/google/gerrit/acceptance/ssh/AbstractIndexTests.java +++ b/javatests/com/google/gerrit/acceptance/ssh/AbstractIndexTests.java @@ -26,6 +26,7 @@ import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.UseSsh; import com.google.gerrit.acceptance.config.GerritConfig; +import com.google.gerrit.acceptance.testsuite.change.IndexOperations; import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.server.query.change.ChangeData; import com.google.inject.Inject; @@ -36,6 +37,7 @@ import org.junit.Test; @UseSsh public abstract class AbstractIndexTests extends AbstractDaemonTest { @Inject private ExtensionRegistry extensionRegistry; + @Inject private IndexOperations.Change changeIndexOperations; @Test @GerritConfig(name = "index.autoReindexIfStale", value = "false") @@ -49,11 +51,10 @@ public abstract class AbstractIndexTests extends AbstractDaemonTest { String changeLegacyId = change.getChange().getId().toString(); ChangeInfo changeInfo = gApi.changes().id(changeId).get(); - disableChangeIndexWrites(); - amendChange(changeId, "second test", "test2.txt", "test2"); - - assertChangeQuery(change.getChange(), false); - enableChangeIndexWrites(); + try (AutoCloseable ignored = changeIndexOperations.disableWrites()) { + amendChange(changeId, "second test", "test2.txt", "test2"); + assertChangeQuery(change.getChange(), false); + } changeIndexedCounter.clear(); String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId); @@ -77,11 +78,10 @@ public abstract class AbstractIndexTests extends AbstractDaemonTest { String changeId = change.getChangeId(); ChangeInfo changeInfo = gApi.changes().id(changeId).get(); - disableChangeIndexWrites(); - amendChange(changeId, "second test", "test2.txt", "test2"); - - assertChangeQuery(change.getChange(), false); - enableChangeIndexWrites(); + try (AutoCloseable ignored = changeIndexOperations.disableWrites()) { + amendChange(changeId, "second test", "test2.txt", "test2"); + assertChangeQuery(change.getChange(), false); + } changeIndexedCounter.clear(); String cmd = Joiner.on(" ").join("gerrit", "index", "changes-in-project", project.get()); |