diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java index 5a0f7a5bb4..f4b82fb61c 100644 --- a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java +++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureRepositoryLockTest.java @@ -24,7 +24,9 @@ import com.microsoft.azure.storage.blob.CloudBlockBlob; import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock; import org.junit.Before; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Test; +import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,4 +83,29 @@ public class AzureRepositoryLockTest { new AzureRepositoryLock(blob, () -> {}, 10).lock(); } + @Ignore + @Test + public void testLeaseRefreshUnsuccessful() throws URISyntaxException, StorageException, IOException, InterruptedException { + CloudBlockBlob blob = container.getBlockBlobReference("oak/repo.lock"); + + CloudBlockBlob blobMocked = Mockito.spy(blob); + + // instrument the mock to throw the exception when renewing the lease + Mockito.doThrow(new StorageException("test_case", "test_case", null)).when(blobMocked).renewLease(Mockito.any()); + + new AzureRepositoryLock(blobMocked, () -> {}, 0).lock(); + + // wait till lease expires + Thread.sleep(70000); + + // reset the mock to default behaviour + Mockito.doCallRealMethod().when(blobMocked).renewLease(Mockito.any()); + + try { + new AzureRepositoryLock(blobMocked, () -> {}, 0).lock(); + fail("The second lock should fail."); + } catch (IOException e) { + // it's fine + } + } } diff --git a/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000..ca6ee9cea8 --- /dev/null +++ b/oak-segment-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file