jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1162162 - /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
Date Fri, 26 Aug 2011 16:43:44 GMT
Author: thomasm
Date: Fri Aug 26 16:43:44 2011
New Revision: 1162162

URL: http://svn.apache.org/viewvc?rev=1162162&view=rev
Log:
Non-unique indexes (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java?rev=1162162&r1=1162161&r2=1162162&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
Fri Aug 26 16:43:44 2011
@@ -22,6 +22,7 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.json.JsopTest;
 import org.apache.jackrabbit.mk.mem.NodeImpl;
 
+import java.util.Iterator;
 import java.util.Random;
 import java.util.TreeMap;
 
@@ -35,10 +36,36 @@ public class IndexTest extends TestCase 
     // private static final String URL = "mem:";
 
     public void test() {
+        testNonUnique(URL);
         testAscending(URL);
         testRandom(URL);
         testDuplicateKey(URL, true);
         testDuplicateKey(URL, false);
+        testNestedAddNode(URL);
+    }
+
+    private void testNonUnique(String url) {
+        MicroKernel mk = MicroKernelFactory.getInstance(url);
+        Indexer indexer = new Indexer(mk);
+        Index index = indexer.createNonUniqueIndex("id");
+        mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 1 }, \"id\": 1 }", mk.getHeadRevision(),
"");
+        Iterator<String> it = index.getPaths("1", mk.getHeadRevision());
+        assertTrue(it.hasNext());
+        assertEquals("/test", it.next());
+        assertTrue(it.hasNext());
+        assertEquals("/test/test2", it.next());
+        assertFalse(it.hasNext());
+        mk.dispose();
+    }
+
+    private void testNestedAddNode(String url) {
+        MicroKernel mk = MicroKernelFactory.getInstance(url);
+        Indexer indexer = new Indexer(mk);
+        Index index = indexer.createUniqueIndex("id");
+        mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(),
"");
+        assertEquals("/test", index.getPath("1", mk.getHeadRevision()));
+        assertEquals("/test/test2", index.getPath("2", mk.getHeadRevision()));
+        mk.dispose();
     }
 
     private void testAscending(String url) {
@@ -110,12 +137,14 @@ public class IndexTest extends TestCase 
 
         // search
         Cursor c = index.findFirst("1");
-        if (!unique) {
+        assertEquals("1", c.next());
+        assertEquals("p1", c.getPath());
+        if (unique) {
+            assertFalse(c.hasNext());
+        } else {
             assertEquals("1", c.next());
             assertEquals("p1b", c.getPath());
         }
-        assertEquals("1", c.next());
-        assertEquals("p1", c.getPath());
         try {
             c.remove();
             fail();



Mime
View raw message