Merge branch 'stable-2.16'

* stable-2.16:
  Do not use QueryProcessor multiple times

Change-Id: I41b06d20e484f6b61e1bd226571cac9abb078340
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 ab2ad91..277c11f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckSubsystemsModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckSubsystemsModule.java
@@ -21,13 +21,11 @@
 import com.googlesource.gerrit.plugins.healthcheck.check.JGitHealthCheck;
 import com.googlesource.gerrit.plugins.healthcheck.check.ProjectsListHealthCheck;
 import com.googlesource.gerrit.plugins.healthcheck.check.QueryChangesHealthCheck;
-import com.googlesource.gerrit.plugins.healthcheck.check.ReviewDbHealthCheck;
 
 public class HealthCheckSubsystemsModule extends AbstractModule {
 
   @Override
   protected void configure() {
-    bindChecker(ReviewDbHealthCheck.class);
     bindChecker(JGitHealthCheck.class);
     bindChecker(ProjectsListHealthCheck.class);
     bindChecker(QueryChangesHealthCheck.class);
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 402fa35..670e1b4 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
@@ -15,7 +15,6 @@
 package com.googlesource.gerrit.plugins.healthcheck.check;
 
 public interface HealthCheckNames {
-  String REVIEWDB = "reviewdb";
   String JGIT = "jgit";
   String PROJECTSLIST = "projectslist";
   String QUERYCHANGES = "querychanges";
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ReviewDbHealthCheck.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ReviewDbHealthCheck.java
deleted file mode 100644
index 2a184c8..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ReviewDbHealthCheck.java
+++ /dev/null
@@ -1,47 +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.googlesource.gerrit.plugins.healthcheck.check;
-
-import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.REVIEWDB;
-
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.gerrit.reviewdb.client.CurrentSchemaVersion;
-import com.google.gerrit.reviewdb.server.ReviewDb;
-import com.google.gwtorm.server.SchemaFactory;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.googlesource.gerrit.plugins.healthcheck.HealthCheckConfig;
-
-@Singleton
-public class ReviewDbHealthCheck extends AbstractHealthCheck {
-  private final SchemaFactory<ReviewDb> reviewDb;
-
-  @Inject
-  public ReviewDbHealthCheck(
-      ListeningExecutorService executor,
-      HealthCheckConfig config,
-      SchemaFactory<ReviewDb> reviewDb) {
-    super(executor, config, REVIEWDB);
-    this.reviewDb = reviewDb;
-  }
-
-  @Override
-  protected Result doCheck() throws Exception {
-    try (ReviewDb db = reviewDb.open()) {
-      db.schemaVersion().get(new CurrentSchemaVersion.Key());
-      return Result.PASSED;
-    }
-  }
-}
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 ed1d3d4..331c784 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
@@ -18,7 +18,6 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.JGIT;
 import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.QUERYCHANGES;
-import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.REVIEWDB;
 
 import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
 import com.google.gerrit.acceptance.RestResponse;
@@ -72,16 +71,6 @@
   }
 
   @Test
-  public void shouldReturnReviewDbCheck() throws Exception {
-    RestResponse resp = getHealthCheckStatus();
-    resp.assertOK();
-
-    JsonObject respPayload = gson.fromJson(resp.getReader(), JsonObject.class);
-
-    assertCheckResult(respPayload, REVIEWDB, "passed");
-  }
-
-  @Test
   public void shouldReturnJGitCheck() throws Exception {
     RestResponse resp = getHealthCheckStatus();
     resp.assertOK();
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ReviewDbHealthCheckTest.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ReviewDbHealthCheckTest.java
deleted file mode 100644
index 5c85f42..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ReviewDbHealthCheckTest.java
+++ /dev/null
@@ -1,68 +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.googlesource.gerrit.plugins.healthcheck;
-
-import static com.google.common.truth.Truth.assertThat;
-import static com.googlesource.gerrit.plugins.healthcheck.HealthCheckConfig.DEFAULT_CONFIG;
-
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.gerrit.lifecycle.LifecycleManager;
-import com.google.gerrit.reviewdb.server.ReviewDb;
-import com.google.gerrit.testing.DisabledReviewDb;
-import com.google.gerrit.testing.InMemoryDatabase;
-import com.google.gwtorm.server.SchemaFactory;
-import com.google.inject.Guice;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.googlesource.gerrit.plugins.healthcheck.check.HealthCheck;
-import com.googlesource.gerrit.plugins.healthcheck.check.ReviewDbHealthCheck;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ReviewDbHealthCheckTest {
-  private SchemaFactory<ReviewDb> workingReviewDbFactory;
-  @Inject private ListeningExecutorService executor;
-
-  @Before
-  public void setUp() throws Exception {
-    Injector testInjector = Guice.createInjector(new HealthCheckModule());
-    testInjector.injectMembers(this);
-
-    workingReviewDbFactory = InMemoryDatabase.newDatabase(new LifecycleManager()).create();
-  }
-
-  @Test
-  public void shouldBeHealthyWhenReviewDbIsWorking() {
-    ReviewDbHealthCheck reviewDbCheck =
-        new ReviewDbHealthCheck(executor, DEFAULT_CONFIG, workingReviewDbFactory);
-    assertThat(reviewDbCheck.run().result).isEqualTo(HealthCheck.Result.PASSED);
-  }
-
-  @Test
-  public void shouldBeUnhealthyWhenReviewDbIsFailing() {
-    ReviewDbHealthCheck reviewDbCheck =
-        new ReviewDbHealthCheck(executor, DEFAULT_CONFIG, getFailingReviewDbProvider());
-    assertThat(reviewDbCheck.run().result).isEqualTo(HealthCheck.Result.FAILED);
-  }
-
-  private SchemaFactory<ReviewDb> getFailingReviewDbProvider() {
-    return new SchemaFactory<ReviewDb>() {
-      @Override
-      public ReviewDb open() {
-        return new DisabledReviewDb();
-      }
-    };
-  }
-}