Author: chetanm
Date: Fri Jan 15 06:21:00 2016
New Revision: 1724732

URL: http://svn.apache.org/viewvc?rev=1724732&view=rev
Log:
OAK-3819 - Collect and expose statistics related to Segment FileStore operations

Add a method to determine if given id belongs to previous document or not

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java?rev=1724732&r1=1724731&r2=1724732&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
 Fri Jan 15 06:21:00 2016
@@ -339,6 +339,20 @@ public class Utils {
     }
 
     /**
+     * Determines if the passed id belongs to a previous doc
+     *
+     * @param id id to check
+     * @return true if the id belongs to a previous doc
+     */
+    public static boolean isPreviousDocId(String id){
+        int indexOfColon = id.indexOf(':');
+        if (indexOfColon > 0 && indexOfColon < id.length() - 1){
+            return id.charAt(indexOfColon + 1) == 'p';
+        }
+        return false;
+    }
+
+    /**
      * Deep copy of a map that may contain map values.
      *
      * @param source the source map

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java?rev=1724732&r1=1724731&r2=1724732&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
 Fri Jan 15 06:21:00 2016
@@ -35,6 +35,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
@@ -56,6 +57,16 @@ public class UtilsTest {
     }
 
     @Test
+    public void previousDoc() throws Exception{
+        Revision r = new Revision(System.currentTimeMillis(), 0, 0);
+        assertTrue(Utils.isPreviousDocId(Utils.getPreviousIdFor("/", r, 0)));
+        
assertTrue(Utils.isPreviousDocId(Utils.getPreviousIdFor("/a/b/c/d/e/f/g/h/i/j/k/l/m",
 r, 3)));
+        assertFalse(Utils.isPreviousDocId(Utils.getIdFromPath("/a/b")));
+        assertFalse(Utils.isPreviousDocId("foo"));
+        assertFalse(Utils.isPreviousDocId("0:"));
+    }
+
+    @Test
     public void getParentIdFromLowerLimit() throws Exception{
         
assertEquals("1:/foo",Utils.getParentIdFromLowerLimit(Utils.getKeyLowerLimit("/foo")));
         assertEquals("1:/foo",Utils.getParentIdFromLowerLimit("2:/foo/bar"));


Reply via email to