jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1401635 - /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Date Wed, 24 Oct 2012 11:51:45 GMT
Author: thomasm
Date: Wed Oct 24 11:51:44 2012
New Revision: 1401635

URL: http://svn.apache.org/viewvc?rev=1401635&view=rev
Log:
OAK-308 NodeIterator limit and offset don't work as expected

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java?rev=1401635&r1=1401634&r2=1401635&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Wed Oct 24 11:51:44 2012
@@ -101,7 +101,12 @@ public class QueryTest extends AbstractR
         Node hello1 = session.getRootNode().addNode("hello1");
         hello1.setProperty("id",  "1");
         hello1.setProperty("data",  "x");
-        Node hello2 = session.getRootNode().addNode("hello2");
+        session.save();
+        Node hello3 = hello1.addNode("hello3");
+        hello3.setProperty("id",  "3");
+        hello3.setProperty("data",  "z");
+        session.save();
+        Node hello2 = hello3.addNode("hello2");
         hello2.setProperty("id",  "2");
         hello2.setProperty("data",  "y");
         session.save();
@@ -109,15 +114,15 @@ public class QueryTest extends AbstractR
         QueryManager qm = session.getWorkspace().getQueryManager();
         Query q = qm.createQuery("select id from [nt:base] where data >= $data order by
id", Query.JCR_SQL2);
         q.bindValue("data", vf.createValue("x"));
-        for (int i = -1; i < 4; i++) {
+        for (int i = -1; i < 5; i++) {
             QueryResult r = q.execute();
             RowIterator it = r.getRows();
-            assertEquals(2, r.getRows().getSize());
-            assertEquals(2, r.getNodes().getSize());
+            assertEquals(3, r.getRows().getSize());
+            assertEquals(3, r.getNodes().getSize());
             Row row;
             try {
                 it.skip(i);
-                assertTrue(i >= 0 && i <= 2);
+                assertTrue(i >= 0 && i <= 3);
             } catch (IllegalArgumentException e) {
                 assertEquals(-1, i);
             } catch (NoSuchElementException e) {
@@ -133,8 +138,53 @@ public class QueryTest extends AbstractR
                 row = it.nextRow();
                 assertEquals("2", row.getValue("id").getString());
             }
+            if (i <= 2) {
+                assertTrue(it.hasNext());
+                row = it.nextRow();
+                assertEquals("3", row.getValue("id").getString());
+            }
             assertFalse(it.hasNext());
         }
     }
+    
+    @Test
+    public void limit() throws RepositoryException {
+        Session session = getAdminSession();
+        Node hello1 = session.getRootNode().addNode("hello1");
+        hello1.setProperty("id",  "1");
+        hello1.setProperty("data",  "x");
+        session.save();
+        Node hello3 = session.getRootNode().addNode("hello3");
+        hello3.setProperty("id",  "3");
+        hello3.setProperty("data",  "z");
+        session.save();
+        Node hello2 = session.getRootNode().addNode("hello2");
+        hello2.setProperty("id",  "2");
+        hello2.setProperty("data",  "y");
+        session.save();
+        ValueFactory vf = session.getValueFactory();
+        QueryManager qm = session.getWorkspace().getQueryManager();
+        Query q = qm.createQuery("select id from [nt:base] where data >= $data order by
id", Query.JCR_SQL2);
+        q.bindValue("data", vf.createValue("x"));
+        for (int limit = 0; limit < 5; limit++) {
+            q.setLimit(limit);
+            for (int offset = 0; offset < 3; offset++) {
+                q.setOffset(offset);
+                QueryResult r = q.execute();
+                RowIterator it = r.getRows();
+                int l = Math.min(Math.max(0, 3 - offset), limit);
+                assertEquals(l, r.getRows().getSize());
+                assertEquals(l, r.getNodes().getSize());
+                Row row;
+                
+                for (int x = offset + 1, i = 0; i < limit && x < 4; i++, x++)
{
+                    assertTrue(it.hasNext());
+                    row = it.nextRow();
+                    assertEquals("" + x, row.getValue("id").getString());
+                }
+                assertFalse(it.hasNext());
+            }
+        }
+    }
 
 }



Mime
View raw message