Consolidate GlobalRefDbLockException and SharedLockException

The GlobalRefDbLockException was a RuntimeException that was never
handled. It used the same message as SharedLockException, which was
never thrown, but checked for in a place, where only a
GlobalRefDbLockException could be expected.

This change changes the Exception hierarchy, so that SharedLockException
inherits from LockFailureException, which also inherits from IOException
and is thus not breaking the API. The GlobalRefDbException now inherits
from SharedLockException and is thus not a RuntimeException anymore and
will thus be handed down to the RetryHelper.

The GlobalRefDbException is now only an alias for SharedRefDbException,
but was kept to not break the API.

Change-Id: Ibba1452e8e426b00b45ee3e6ccb4e0b225e81f79
diff --git a/src/main/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDbLockException.java b/src/main/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDbLockException.java
index fa757db..e51e1f3 100644
--- a/src/main/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDbLockException.java
+++ b/src/main/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDbLockException.java
@@ -14,11 +14,13 @@
 
 package com.gerritforge.gerrit.globalrefdb;
 
+import com.gerritforge.gerrit.globalrefdb.validation.dfsrefdb.SharedLockException;
+
 /**
  * {@code GlobalRefDbLockException} is an exception that can be thrown when interacting with the
  * global-refdb to represent the inability to lock or acquire a resource.
  */
-public class GlobalRefDbLockException extends RuntimeException {
+public class GlobalRefDbLockException extends SharedLockException {
   private static final long serialVersionUID = 1L;
 
   /**
@@ -30,6 +32,6 @@
    * @param cause the cause of the locking failure
    */
   public GlobalRefDbLockException(String project, String refName, Exception cause) {
-    super(String.format("Unable to lock ref %s on project %s", refName, project), cause);
+    super(project, refName, cause);
   }
 }
diff --git a/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/SharedLockException.java b/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/SharedLockException.java
index 5963da2..1286ed3 100644
--- a/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/SharedLockException.java
+++ b/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/SharedLockException.java
@@ -14,10 +14,10 @@
 
 package com.gerritforge.gerrit.globalrefdb.validation.dfsrefdb;
 
-import java.io.IOException;
+import com.google.gerrit.git.LockFailureException;
 
 /** Unable to lock a project/ref resource. */
-public class SharedLockException extends IOException {
+public class SharedLockException extends LockFailureException {
   private static final long serialVersionUID = 1L;
 
   /**
@@ -29,6 +29,6 @@
    * @param cause the cause of the failure
    */
   public SharedLockException(String project, String refName, Exception cause) {
-    super(String.format("Unable to lock project %s on ref %s", project, refName), cause);
+    super(String.format("Unable to lock ref %s on project %s", refName, project), cause);
   }
 }
diff --git a/src/test/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDatabaseTest.java b/src/test/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDatabaseTest.java
index 8ed1f4c..6284f42 100644
--- a/src/test/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDatabaseTest.java
+++ b/src/test/java/com/gerritforge/gerrit/globalrefdb/GlobalRefDatabaseTest.java
@@ -95,26 +95,28 @@
   }
 
   @Test
-  public void shouldReturnIsUpToDateWhenProjectDoesNotExistsInTheGlobalRefDB() {
+  public void shouldReturnIsUpToDateWhenProjectDoesNotExistsInTheGlobalRefDB()
+      throws GlobalRefDbLockException {
     assertThat(objectUnderTest.isUpToDate(project, initialRef)).isTrue();
   }
 
   @Test
-  public void shouldReturnIsUpToDate() {
+  public void shouldReturnIsUpToDate() throws GlobalRefDbLockException {
     objectUnderTest.compareAndPut(project, nullRef, objectId1);
 
     assertThat(objectUnderTest.isUpToDate(project, ref1)).isTrue();
   }
 
   @Test
-  public void shouldReturnIsNotUpToDateWhenLocalRepoIsOutdated() {
+  public void shouldReturnIsNotUpToDateWhenLocalRepoIsOutdated() throws GlobalRefDbLockException {
     objectUnderTest.compareAndPut(project, nullRef, objectId1);
 
     assertThat(objectUnderTest.isUpToDate(project, nullRef)).isFalse();
   }
 
   @Test
-  public void shouldReturnIsNotUpToDateWhenLocalRepoIsAheadOfTheGlobalRefDB() {
+  public void shouldReturnIsNotUpToDateWhenLocalRepoIsAheadOfTheGlobalRefDB()
+      throws GlobalRefDbLockException {
     objectUnderTest.compareAndPut(project, nullRef, objectId1);
 
     assertThat(objectUnderTest.isUpToDate(project, ref2)).isFalse();
diff --git a/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapperTest.java b/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapperTest.java
index 884090e..5240f2c 100644
--- a/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapperTest.java
+++ b/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapperTest.java
@@ -17,6 +17,7 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.metrics.Timer0.Context;
 import org.eclipse.jgit.lib.ObjectId;
@@ -58,14 +59,16 @@
   }
 
   @Test
-  public void shouldUpdateLockRefExecutionTimeMetricWhenLockRefIsCalled() {
+  public void shouldUpdateLockRefExecutionTimeMetricWhenLockRefIsCalled()
+      throws GlobalRefDbLockException {
     objectUnderTest.lockRef(projectName, refName);
     verify(metrics).startLockRefExecutionTime();
     verify(context).close();
   }
 
   @Test
-  public void shouldUpdateIsUpToDateExecutionTimeMetricWhenIsUpToDate() {
+  public void shouldUpdateIsUpToDateExecutionTimeMetricWhenIsUpToDate()
+      throws GlobalRefDbLockException {
     objectUnderTest.isUpToDate(projectName, ref);
     verify(metrics).startIsUpToDateExecutionTime();
     verify(context).close();
diff --git a/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/NoopSharedRefDatabaseTest.java b/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/NoopSharedRefDatabaseTest.java
index 8c749ea..eaeb6d4 100644
--- a/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/NoopSharedRefDatabaseTest.java
+++ b/src/test/java/com/gerritforge/gerrit/globalrefdb/validation/dfsrefdb/NoopSharedRefDatabaseTest.java
@@ -16,6 +16,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException;
 import org.eclipse.jgit.lib.Ref;
 import org.junit.Test;
 
@@ -25,7 +26,7 @@
   private NoopSharedRefDatabase objectUnderTest = new NoopSharedRefDatabase();
 
   @Test
-  public void isUpToDateShouldAlwaysReturnTrue() {
+  public void isUpToDateShouldAlwaysReturnTrue() throws GlobalRefDbLockException {
     assertThat(objectUnderTest.isUpToDate(A_TEST_PROJECT_NAME_KEY, sampleRef)).isTrue();
   }