Merge branch 'stable-3.9' * stable-3.9: Don't scan gerrit_index.config for current version when no Lucene Listen to OnlineUpgradeListener.onSuccess event Improve visibility of the integration tests Implement changes indexes lock files check Introduce the changes index health check stub Format using google-java-format Change-Id: I601ed267978fd1511fde1dfe5f3cd6d2044ee479
diff --git a/BUILD b/BUILD index 24a2d60..5077015 100644 --- a/BUILD +++ b/BUILD
@@ -20,18 +20,37 @@ junit_tests( name = "healthcheck_tests", - srcs = glob(["src/test/java/**/*.java"]), + srcs = glob( + [ + "src/test/java/**/*Test.java", + ], + exclude = ["src/test/java/**/Abstract*.java"], + ), resources = glob(["src/test/resources/**/*"]), deps = [ ":healthcheck__plugin_test_deps", ], ) +[junit_tests( + name = f[:f.index(".")].replace("/", "_"), + srcs = [f], + tags = ["owners"], + visibility = ["//visibility:public"], + deps = [ + ":healthcheck__plugin_test_deps", + ], +) for f in glob(["src/test/java/**/*IT.java"])] + java_library( name = "healthcheck__plugin_test_deps", testonly = 1, + srcs = glob(["src/test/java/**/Abstract*.java"]), visibility = ["//visibility:public"], exports = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [ ":healthcheck__plugin", ], + deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [ + ":healthcheck__plugin", + ], )
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckSubsystemsModule.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckSubsystemsModule.java index aea007a..bff5c13 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckSubsystemsModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckSubsystemsModule.java
@@ -16,9 +16,11 @@ import com.google.gerrit.extensions.config.FactoryModule; import com.google.gerrit.extensions.registration.DynamicSet; +import com.google.gerrit.server.index.OnlineUpgradeListener; import com.googlesource.gerrit.plugins.healthcheck.check.ActiveWorkersCheck; import com.googlesource.gerrit.plugins.healthcheck.check.AuthHealthCheck; import com.googlesource.gerrit.plugins.healthcheck.check.BlockedThreadsCheck; +import com.googlesource.gerrit.plugins.healthcheck.check.ChangesIndexHealthCheck; import com.googlesource.gerrit.plugins.healthcheck.check.DeadlockCheck; import com.googlesource.gerrit.plugins.healthcheck.check.HealthCheck; import com.googlesource.gerrit.plugins.healthcheck.check.JGitHealthCheck; @@ -36,6 +38,9 @@ bindChecker(ActiveWorkersCheck.class); bindChecker(DeadlockCheck.class); bindChecker(BlockedThreadsCheck.class); + bindChecker(ChangesIndexHealthCheck.class); + + DynamicSet.bind(binder(), OnlineUpgradeListener.class).to(ChangesIndexHealthCheck.class); install(BlockedThreadsCheck.SUB_CHECKS); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java new file mode 100644 index 0000000..fada9aa --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java
@@ -0,0 +1,159 @@ +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.googlesource.gerrit.plugins.healthcheck.check; + +import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.CHANGES_INDEX; + +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.gerrit.index.IndexType; +import com.google.gerrit.metrics.MetricMaker; +import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gerrit.server.config.SitePaths; +import com.google.gerrit.server.index.OnlineUpgradeListener; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.googlesource.gerrit.plugins.healthcheck.HealthCheckConfig; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.util.FS; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Singleton +public class ChangesIndexHealthCheck extends AbstractHealthCheck implements OnlineUpgradeListener { + private static final Logger log = LoggerFactory.getLogger(QueryChangesHealthCheck.class); + private static final String lockFilename = "write.lock"; + + private final SitePaths sitePaths; + private final boolean isLuceneIndex; + private final AtomicReference<Optional<ChangesIndexLockFiles>> changes; + + @Inject + ChangesIndexHealthCheck( + @GerritServerConfig Config cfg, + ListeningExecutorService executor, + HealthCheckConfig config, + MetricMaker metricMaker, + SitePaths sitePaths) { + super(executor, config, CHANGES_INDEX, metricMaker); + this.sitePaths = sitePaths; + this.isLuceneIndex = isIndexTypeLucene(cfg); + this.changes = new AtomicReference<>(getChangesIndexLockFiles(sitePaths.index_dir)); + } + + @Override + protected Result doCheck() throws Exception { + return isLuceneIndex + ? changes + .get() + .map(locks -> locks.valid() ? Result.PASSED : Result.FAILED) + .orElse(Result.FAILED) + : Result.DISABLED; + } + + @Override + public void onStart(String name, int oldVersion, int newVersion) {} + + @Override + public void onSuccess(String name, int oldVersion, int newVersion) { + if (!isLuceneIndex || !name.equals("changes") || oldVersion == newVersion) { + return; + } + + Optional<ChangesIndexLockFiles> newLockFiles = + Optional.of( + getChangesLockFiles(sitePaths.index_dir, String.format("changes_%04d", newVersion))); + if (!changes.compareAndSet(changes.get(), newLockFiles)) { + log.info( + "New version {} of changes index healthcheck lock files was set already by another thread", + newVersion); + } else { + log.info( + "Changes index healthcheck switched from index version {} to {}", oldVersion, newVersion); + } + } + + @Override + public void onFailure(String name, int oldVersion, int newVersion) {} + + private static boolean isIndexTypeLucene(Config cfg) { + IndexType indexType = new IndexType(cfg.getString("index", null, "type")); + boolean isLucene = indexType.isLucene(); + if (!isLucene) { + log.warn( + "Configured index type [{}] is not supported for index health check therefore it is disabled.", + indexType); + } + return isLucene; + } + + private Optional<ChangesIndexLockFiles> getChangesIndexLockFiles(Path indexDir) { + if (!isLuceneIndex) { + Optional.empty(); + } + + FileBasedConfig cfg = + new FileBasedConfig(indexDir.resolve("gerrit_index.config").toFile(), FS.detect()); + try { + cfg.load(); + return getActiveIndexVersion(cfg, "changes") + .map(version -> getChangesLockFiles(indexDir, version)); + } catch (IOException | ConfigInvalidException e) { + log.error("Getting changes index version from configuration failed", e); + } + return Optional.empty(); + } + + private static Optional<String> getActiveIndexVersion(Config cfg, String indexPrefix) { + String section = "index"; + return cfg.getSubsections(section).stream() + .filter( + subsection -> + subsection.startsWith(indexPrefix) + && cfg.getBoolean(section, subsection, "ready", false)) + .findAny(); + } + + private ChangesIndexLockFiles getChangesLockFiles(Path indexDir, String indexVersion) { + Path versionDir = indexDir.resolve(indexVersion); + return new ChangesIndexLockFiles( + versionDir.resolve("open").resolve(lockFilename).toFile(), + versionDir.resolve("closed").resolve(lockFilename).toFile()); + } + + private static class ChangesIndexLockFiles { + private final File openLock; + private final File closedLock; + + private ChangesIndexLockFiles(File openLock, File closedLock) { + this.openLock = openLock; + this.closedLock = closedLock; + } + + private boolean valid() { + return validLock(openLock) && validLock(closedLock); + } + + private static boolean validLock(File writeLock) { + return writeLock.isFile() && writeLock.canWrite(); + } + } +}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/HealthCheckNames.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/HealthCheckNames.java index 4771942..5a4947f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/HealthCheckNames.java +++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/HealthCheckNames.java
@@ -23,4 +23,5 @@ String DEADLOCK = "deadlock"; String BLOCKEDTHREADS = "blockedthreads"; String GLOBAL = "global"; + String CHANGES_INDEX = "changesindex"; }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index 0b4f05f..7f7d549 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -56,6 +56,8 @@ - `activeworkers`: check the number of active worker threads and the ability to create a new one - `deadlock` : check if Java deadlocks are reported by the JVM - `blockedthreads` : check the number of blocked threads +- `changesindex` : check if the lucene based changes indexes (open and closed) are operable + (examines index lock files) Each check name can be disabled by setting the `enabled` parameter to **false**, by default this parameter is set to **true**
diff --git a/src/main/resources/Documentation/metrics.md b/src/main/resources/Documentation/metrics.md index 76e6eb5..f250d1b 100644 --- a/src/main/resources/Documentation/metrics.md +++ b/src/main/resources/Documentation/metrics.md
@@ -52,6 +52,10 @@ # TYPE plugins_healthcheck_blockedthreads_latest_measured_latency gauge plugins_healthcheck_blockedthreads_latest_measured_latency 6.0 +# HELP plugins_healthcheck_changesindex_latest_measured_latency Generated from Dropwizard metric import (metric=plugins/healthcheck/changesindex/latency, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl0$1) +# TYPE plugins_healthcheck_changesindex_latest_measured_latency gauge +plugins_healthcheck_changesindex_latest_measured_latency 3.0 + # HELP plugins_healthcheck_jgit_failure_total Generated from Dropwizard metric import (metric=plugins/healthcheck/jgit/failure, type=com.codahale.metrics.Meter) # TYPE plugins_healthcheck_jgit_failure_total counter plugins_healthcheck_jgit_failure_total 3.0 @@ -63,6 +67,10 @@ # HELP plugins_healthcheck_blockedthreads_failure_total Generated from Dropwizard metric import (metric=plugins/healthcheck/blockedthreads/failure, type=com.codahale.metrics.Meter) # TYPE plugins_healthcheck_blockedthreads_failure_total counter plugins_healthcheck_blockedthreads_failure_total 1.0 + +# HELP plugins_healthcheck_changesindex_failure_total Generated from Dropwizard metric import (metric=plugins/healthcheck/changesindex/failure, type=com.codahale.metrics.Meter) +# TYPE plugins_healthcheck_changesindex_failure_total counter +plugins_healthcheck_changesindex_failure_total 1.0 ``` Note that additionally to the default `blockedthreads` metrics pair failures counter will reported for
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/AbstractHealthCheckIntegrationTest.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/AbstractHealthCheckIntegrationTest.java new file mode 100644 index 0000000..ff924e6 --- /dev/null +++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/AbstractHealthCheckIntegrationTest.java
@@ -0,0 +1,85 @@ +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.googlesource.gerrit.plugins.healthcheck; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.gerrit.acceptance.LightweightPluginDaemonTest; +import com.google.gerrit.acceptance.RestResponse; +import com.google.gerrit.extensions.annotations.PluginName; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.inject.AbstractModule; +import com.google.inject.Key; +import com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames; +import java.io.IOException; +import org.eclipse.jgit.errors.ConfigInvalidException; + +class AbstractHealthCheckIntegrationTest extends LightweightPluginDaemonTest { + public static class TestModule extends AbstractModule { + + @Override + protected void configure() { + install(new HealthCheckExtensionApiModule()); + install(new Module()); + } + } + + protected HealthCheckConfig config; + protected String healthCheckUriPath; + + private final Gson gson = new Gson(); + + @Override + public void setUpTestPlugin() throws Exception { + super.setUpTestPlugin(); + + config = plugin.getSysInjector().getInstance(HealthCheckConfig.class); + + int numChanges = config.getLimit(HealthCheckNames.QUERYCHANGES); + for (int i = 0; i < numChanges; i++) { + createChange("refs/for/master"); + } + accountCreator.create(config.getUsername(HealthCheckNames.AUTH)); + + healthCheckUriPath = + String.format( + "/config/server/%s~status", + plugin.getSysInjector().getInstance(Key.get(String.class, PluginName.class))); + } + + protected RestResponse getHealthCheckStatus() throws IOException { + return adminRestSession.get(healthCheckUriPath); + } + + protected RestResponse getHealthCheckStatusAnonymously() throws IOException { + return anonymousRestSession.get(healthCheckUriPath); + } + + protected void assertCheckResult(JsonObject respPayload, String checkName, String result) { + assertThat(respPayload.has(checkName)).isTrue(); + JsonObject reviewDbStatus = respPayload.get(checkName).getAsJsonObject(); + assertThat(reviewDbStatus.has("result")).isTrue(); + assertThat(reviewDbStatus.get("result").getAsString()).isEqualTo(result); + } + + protected void disableCheck(String check) throws ConfigInvalidException { + config.fromText(String.format("[healthcheck \"%s\"]\n" + "enabled = false", check)); + } + + protected JsonObject getResponseJson(RestResponse resp) throws IOException { + return gson.fromJson(resp.getReader(), JsonObject.class); + } +}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java new file mode 100644 index 0000000..33d3277 --- /dev/null +++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java
@@ -0,0 +1,120 @@ +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.googlesource.gerrit.plugins.healthcheck; + +import static com.google.common.truth.Truth.assertThat; +import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.CHANGES_INDEX; + +import com.google.gerrit.acceptance.RestResponse; +import com.google.gerrit.acceptance.Sandboxed; +import com.google.gerrit.acceptance.TestPlugin; +import com.google.gerrit.acceptance.UseLocalDisk; +import com.google.gerrit.acceptance.config.GerritConfig; +import com.google.gerrit.server.config.SitePaths; +import com.google.inject.Inject; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Iterator; +import javax.servlet.http.HttpServletResponse; +import org.junit.Test; + +@TestPlugin( + name = "healthcheck-test", + sysModule = + "com.googlesource.gerrit.plugins.healthcheck.AbstractHealthCheckIntegrationTest$TestModule", + httpModule = "com.googlesource.gerrit.plugins.healthcheck.HttpModule") +@Sandboxed +public class ChangesIndexHealthCheckIT extends AbstractHealthCheckIntegrationTest { + @Inject SitePaths sitePaths; + + @Test + @UseLocalDisk + @GerritConfig(name = "index.type", value = "lucene") + public void shouldReturnChangesIndexCheck() throws Exception { + RestResponse resp = getHealthCheckStatus(); + resp.assertOK(); + + assertCheckResult(getResponseJson(resp), CHANGES_INDEX, "passed"); + } + + @Test + @UseLocalDisk + @GerritConfig(name = "index.type", value = "lucene") + public void shouldFailWhenOpenChangesIndexWriteLockIsMissing() throws Exception { + shouldFailWhenChangesIndexWriteLockIsMissing("open"); + } + + @Test + @UseLocalDisk + @GerritConfig(name = "index.type", value = "lucene") + public void shouldFailWhenClosedChangesIndexWriteLockIsMissing() throws Exception { + shouldFailWhenChangesIndexWriteLockIsMissing("closed"); + } + + private void shouldFailWhenChangesIndexWriteLockIsMissing(String indexType) throws Exception { + RestResponse resp = getHealthCheckStatus(); + resp.assertOK(); + + assertCheckResult(getResponseJson(resp), CHANGES_INDEX, "passed"); + + Path openChangesIndexLockPath = getIndexLockFile(sitePaths.index_dir, indexType); + assertThat( + openChangesIndexLockPath + .toFile() + .renameTo( + openChangesIndexLockPath + .getParent() + .resolve(openChangesIndexLockPath.getFileName().toString() + ".backup") + .toFile())) + .isTrue(); + + resp = getHealthCheckStatus(); + resp.assertStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + + assertCheckResult(getResponseJson(resp), CHANGES_INDEX, "failed"); + } + + @Test + @GerritConfig(name = "index.type", value = "lucene") + public void shouldReturnChangesIndexCheckAsDisabled() throws Exception { + disableCheck(CHANGES_INDEX); + RestResponse resp = getHealthCheckStatus(); + + resp.assertOK(); + assertCheckResult(getResponseJson(resp), CHANGES_INDEX, "disabled"); + } + + @Test + @GerritConfig(name = "index.type", value = "fake") + public void shouldReturnChangesIndexCheckAsDisabledWhenIndexIsNotLucene() throws Exception { + RestResponse resp = getHealthCheckStatus(); + + resp.assertOK(); + assertCheckResult(getResponseJson(resp), CHANGES_INDEX, "disabled"); + } + + private Path getIndexLockFile(Path indexDir, String indexType) throws IOException { + try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(indexDir, "changes_*")) { + Iterator<Path> changesDir = dirStream.iterator(); + if (changesDir.hasNext()) { + return changesDir.next().resolve(indexType).resolve("write.lock"); + } + throw new RuntimeException( + String.format("there is no `changes_*` dir under [%s] index dir", indexDir)); + } + } +}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java index 17f1e10..a0c9885 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
@@ -18,20 +18,15 @@ import static com.google.common.truth.Truth.assertThat; import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.ACTIVEWORKERS; import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.AUTH; +import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.CHANGES_INDEX; import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.JGIT; import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.QUERYCHANGES; -import com.google.gerrit.acceptance.LightweightPluginDaemonTest; import com.google.gerrit.acceptance.RestResponse; import com.google.gerrit.acceptance.Sandboxed; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.config.GerritConfig; -import com.google.gerrit.extensions.annotations.PluginName; -import com.google.gson.Gson; import com.google.gson.JsonObject; -import com.google.inject.AbstractModule; -import com.google.inject.Key; -import com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames; import java.io.File; import java.io.IOException; import javax.servlet.http.HttpServletResponse; @@ -41,43 +36,24 @@ @TestPlugin( name = "healthcheck-test", - sysModule = "com.googlesource.gerrit.plugins.healthcheck.HealthCheckIT$TestModule", + sysModule = + "com.googlesource.gerrit.plugins.healthcheck.AbstractHealthCheckIntegrationTest$TestModule", httpModule = "com.googlesource.gerrit.plugins.healthcheck.HttpModule") @Sandboxed -public class HealthCheckIT extends LightweightPluginDaemonTest { - Gson gson = new Gson(); - HealthCheckConfig config; - String healthCheckUriPath; - String failFilePath; - - public static class TestModule extends AbstractModule { - - @Override - protected void configure() { - install(new HealthCheckExtensionApiModule()); - install(new Module()); - } - } +public class HealthCheckIT extends AbstractHealthCheckIntegrationTest { + private String failFilePath = "/tmp/fail"; @Override @Before public void setUpTestPlugin() throws Exception { super.setUpTestPlugin(); - config = plugin.getSysInjector().getInstance(HealthCheckConfig.class); - failFilePath = "/tmp/fail"; new File(failFilePath).delete(); - int numChanges = config.getLimit(HealthCheckNames.QUERYCHANGES); - for (int i = 0; i < numChanges; i++) { - createChange("refs/for/master"); - } - accountCreator.create(config.getUsername(HealthCheckNames.AUTH)); - - healthCheckUriPath = - String.format( - "/config/server/%s~status", - plugin.getSysInjector().getInstance(Key.get(String.class, PluginName.class))); + // disable `changesindex` check as it requires @UseLocalDisk annotation (so that all operations + // are persisted to local FS) to be applied and that would degrade this IT performance - see + // ChangesIndexHealthCheckIT for a changes index dedicated integration tests + super.disableCheck(CHANGES_INDEX); } @Test @@ -224,37 +200,23 @@ assertThat(respBody.get("reason").getAsString()).isEqualTo("Fail Flag File exists"); } + @Override + protected void disableCheck(String check) throws ConfigInvalidException { + // additionally disable `changesindex` healthcheck as it requires @UseLocalDisk annotation to + // run properly + config.fromText( + String.format( + "[healthcheck \"%s\"]\n enabled = false\n[healthcheck \"%s\"]\n enabled = false", + check, CHANGES_INDEX)); + } + private void createFailFileFlag(String path) throws IOException { File file = new File(path); file.createNewFile(); file.deleteOnExit(); } - private RestResponse getHealthCheckStatus() throws IOException { - return adminRestSession.get(healthCheckUriPath); - } - - private RestResponse getHealthCheckStatusAnonymously() throws IOException { - return anonymousRestSession.get(healthCheckUriPath); - } - - private void assertCheckResult(JsonObject respPayload, String checkName, String result) { - assertThat(respPayload.has(checkName)).isTrue(); - JsonObject reviewDbStatus = respPayload.get(checkName).getAsJsonObject(); - assertThat(reviewDbStatus.has("result")).isTrue(); - assertThat(reviewDbStatus.get("result").getAsString()).isEqualTo(result); - } - - private void disableCheck(String check) throws ConfigInvalidException { - config.fromText(String.format("[healthcheck \"%s\"]\n" + "enabled = false", check)); - } - private void setFailFlagFilePath(String path) throws ConfigInvalidException { config.fromText(String.format("[healthcheck]\n" + "failFileFlagPath = %s", path)); } - - private JsonObject getResponseJson(RestResponse resp) throws IOException { - JsonObject respPayload = gson.fromJson(resp.getReader(), JsonObject.class); - return respPayload; - } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ProjectsListHealthCheckTest.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ProjectsListHealthCheckTest.java index 610284c..293c596 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ProjectsListHealthCheckTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ProjectsListHealthCheckTest.java
@@ -85,7 +85,8 @@ private Provider<ListProjects> getFailingProjectList() { return Providers.of( - new ListProjectsImpl(null, null, null, null, null, null, null, null, null, gerritConfig, null) { + new ListProjectsImpl( + null, null, null, null, null, null, null, null, null, gerritConfig, null) { @Override public SortedMap<String, ProjectInfo> apply() throws BadRequestException { @@ -96,7 +97,8 @@ private Provider<ListProjects> getWorkingProjectList(long execTime) { return Providers.of( - new ListProjectsImpl(null, null, null, null, null, null, null, null, null, gerritConfig, null) { + new ListProjectsImpl( + null, null, null, null, null, null, null, null, null, gerritConfig, null) { @Override public SortedMap<String, ProjectInfo> apply() throws BadRequestException {