OAK-9300 : DocumentNodeStore should refuse checkpoint calls after disposal. Patch provided by José Andrés Cordero Benítez

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1886122 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
index 4cc51be..a19c55d 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
@@ -2018,12 +2018,14 @@
     @NotNull
     @Override
     public String checkpoint(long lifetime, @NotNull Map<String, String> properties) {
+        checkOpen();
         return checkpoints.create(lifetime, properties).toString();
     }
 
     @NotNull
     @Override
     public String checkpoint(long lifetime) {
+        checkOpen();
         Map<String, String> empty = Collections.emptyMap();
         return checkpoint(lifetime, empty);
     }
@@ -2031,6 +2033,7 @@
     @NotNull
     @Override
     public Map<String, String> checkpointInfo(@NotNull String checkpoint) {
+        checkOpen();
         Revision r = Revision.fromString(checkpoint);
         Checkpoints.Info info = checkpoints.getCheckpoints().get(r);
         if (info == null) {
@@ -2044,6 +2047,7 @@
     @NotNull
     @Override
     public Iterable<String> checkpoints() {
+        checkOpen();
         final long now = clock.getTime();
         return Iterables.transform(Iterables.filter(checkpoints.getCheckpoints().entrySet(),
                 new Predicate<Map.Entry<Revision,Checkpoints.Info>>() {
@@ -2062,6 +2066,7 @@
     @Nullable
     @Override
     public NodeState retrieve(@NotNull String checkpoint) {
+        checkOpen();
         RevisionVector rv = getCheckpoints().retrieve(checkpoint);
         if (rv == null) {
             return null;
@@ -2073,6 +2078,7 @@
 
     @Override
     public boolean release(@NotNull String checkpoint) {
+        checkOpen();
         checkpoints.release(checkpoint);
         return true;
     }
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
index e2a382c..2c4129f 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
@@ -122,11 +122,7 @@
 import org.hamcrest.number.OrderingComparison;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -4043,6 +4039,54 @@
         }
     }
 
+    // Tests for OAK-9300
+    @Test
+    public void createCheckpointAfterDispose() {
+        DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
+        store.dispose();
+        Assert.assertThrows(IllegalStateException.class, () -> store.checkpoint(60000));
+    }
+
+    @Test
+    public void createCheckpointWithPropertiesAfterDispose() {
+        DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
+        store.dispose();
+        Assert.assertThrows(IllegalStateException.class, () -> store.checkpoint(60000, Collections.emptyMap()));
+    }
+
+    @Test
+    public void retrieveCheckpointInfoAfterDispose() {
+        DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
+        String ref = store.checkpoint(60000);
+        store.dispose();
+        Assert.assertThrows(IllegalStateException.class, () -> store.checkpointInfo(ref));
+    }
+
+    @Test
+    public void getCheckpointsAfterDispose() {
+        DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
+        String ref = store.checkpoint(60000);
+        store.dispose();
+        Assert.assertThrows(IllegalStateException.class, () -> store.checkpoints());
+    }
+
+    @Test
+    public void retrieveCheckpointAfterDispose() {
+        DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
+        String ref = store.checkpoint(60000);
+        store.dispose();
+        Assert.assertThrows(IllegalStateException.class, () -> store.retrieve(ref));
+    }
+
+    @Test
+    public void releaseCheckpointAfterDispose() {
+        DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
+        String ref = store.checkpoint(60000);
+        store.dispose();
+        Assert.assertThrows(IllegalStateException.class, () -> store.release(ref));
+    }
+    // End of tests for OAK-9300
+
     private void getChildNodeCountTest(int numChildren,
                                        Iterable<Long> maxValues,
                                        Iterable<Long> expectedValues)