jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1310228 - in /jackrabbit/oak/trunk: oak-core/src/test/java/org/apache/jackrabbit/mk/ oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/ oak-core/src/test/java/org/apache/jackrabbit/oak/query/ oak-core/src/test/java/org/apache/jackrab...
Date Fri, 06 Apr 2012 08:39:01 GMT
Author: jukka
Date: Fri Apr  6 08:39:00 2012
New Revision: 1310228

URL: http://svn.apache.org/viewvc?rev=1310228&view=rev
Log:
OAK-31: In-memory MicroKernel for testing

Simplify test setup in many places.
Remove assumptions about child node or query result ordering in test cases.

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorFuzzTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
Fri Apr  6 08:39:00 2012
@@ -19,32 +19,21 @@ package org.apache.jackrabbit.mk;
 import java.util.Random;
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 
 public class ConcurrentWriteTest extends TestCase {
 
     protected static final String TEST_PATH = "/" + ConcurrentWriteTest.class.getName();
 
-    private static final String URL = "fs:{homeDir}/target;clean";
-    // private static final String URL = "fs:{homeDir}/target";
-    // private static final String URL = "simple:";
-    //private static final String URL = "simple:fs:target/temp;clean";
-
     private static final int NUM_THREADS = 20;
     private static final int NUM_CHILDNODES = 1000;
 
-    MicroKernel mk;
+    final MicroKernel mk = new MicroKernelImpl();
 
     public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
         mk.commit("/", "+ \"" + TEST_PATH.substring(1) + "\": {\"jcr:primaryType\":\"nt:unstructured\"}",
mk.getHeadRevision(), null);
     }
 
-    public void tearDown() throws InterruptedException {
-        String head = mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(),
null);
-        //System.out.println("new HEAD: " + head);
-        mk.dispose();
-    }
-
     /**
      * Runs the test.
      */

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorFuzzTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorFuzzTest.java?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorFuzzTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorFuzzTest.java
Fri Apr  6 08:39:00 2012
@@ -25,7 +25,6 @@ import org.apache.jackrabbit.mk.model.Sc
 import org.apache.jackrabbit.mk.model.ScalarImpl;
 import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
 import org.apache.jackrabbit.mk.util.PathUtils;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -56,8 +55,8 @@ public class KernelNodeStateEditorFuzzTe
 
     private final Random random;
 
-    private MicroKernel mk1;
-    private MicroKernel mk2;
+    private final MicroKernel mk1 = new SimpleKernelImpl("mem:");
+    private final MicroKernel mk2 = new SimpleKernelImpl("mem:");
 
     @Parameters
     public static List<Object[]> seeds() {
@@ -76,25 +75,16 @@ public class KernelNodeStateEditorFuzzTe
 
     @Before
     public void setup() {
-        mk1 = new SimpleKernelImpl("mem:mk1");
         mk1.commit("", "+\"/root\":{}", mk1.getHeadRevision(), "");
-
-        mk2 = new SimpleKernelImpl("mem:mk2");
         mk2.commit("", "+\"/root\":{}", mk2.getHeadRevision(), "");
     }
 
-    @After
-    public void tearDown() {
-        mk1.dispose();
-        mk2.dispose();
-    }
-
     @Test
     public void fuzzTest() throws Exception {
         KernelNodeState state1 = new KernelNodeState(mk1, "/", mk1.getHeadRevision());
         KernelNodeStateEditor editor1 = new KernelNodeStateEditor(state1);
 
-        KernelNodeState state2 = new KernelNodeState(mk1, "/", mk2.getHeadRevision());
+        KernelNodeState state2 = new KernelNodeState(mk2, "/", mk2.getHeadRevision());
         KernelNodeStateEditor editor2 = new KernelNodeStateEditor(state2);
 
         for (Operation op : operations(OP_COUNT)) {
@@ -107,7 +97,7 @@ public class KernelNodeStateEditorFuzzTe
             editor1 = new KernelNodeStateEditor(state1);
             if (op instanceof Save) {
                 state2 = editor2.mergeInto(mk2, state2);
-                editor2 = new KernelNodeStateEditor(state1);
+                editor2 = new KernelNodeStateEditor(state2);
                 assertEquals(state1, state2);
             }
         }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
Fri Apr  6 08:39:00 2012
@@ -18,13 +18,13 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.model.NodeState;
 import org.apache.jackrabbit.mk.model.PropertyState;
 import org.apache.jackrabbit.mk.model.Scalar;
 import org.apache.jackrabbit.mk.model.Scalar.Type;
 import org.apache.jackrabbit.mk.model.ScalarImpl;
 import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
-import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -42,12 +42,13 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 public class KernelNodeStateEditorTest {
-    private SimpleKernelImpl microkernel;
+
+    private final MicroKernel microkernel = new SimpleKernelImpl("mem:");
+
     private KernelNodeState state;
 
     @Before
     public void setUp() {
-        microkernel = new SimpleKernelImpl("mem:KernelNodeStateTest");
         String jsop =
                 "+\"test\":{\"a\":1,\"b\":2,\"c\":3,"
                         + "\"x\":{},\"y\":{},\"z\":{}}";
@@ -55,11 +56,6 @@ public class KernelNodeStateEditorTest {
                 "/", jsop, microkernel.getHeadRevision(), "test data");
         state = new KernelNodeState(microkernel, "/test", revision);
     }
-    
-    @After
-    public void tearDown() {
-        microkernel.dispose();
-    }
 
     @Test
     public void getNode() {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
Fri Apr  6 08:39:00 2012
@@ -22,12 +22,16 @@ import java.io.LineNumberReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
+import java.util.List;
+
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,22 +40,17 @@ import org.junit.Test;
  */
 public class QueryTest {
 
-    MicroKernel mk;
+    private final MicroKernel mk = new MicroKernelImpl();
+
     String head;
     QueryEngineImpl qe;
 
     @Before
     public void setUp() {
-        mk = MicroKernelFactory.getInstance("simple:/target/temp;clear");
         head = mk.getHeadRevision();
         qe = new QueryEngineImpl(mk);
     }
 
-    @After
-    public void tearDown() {
-        mk.dispose();
-    }
-
     @Test
     public void script() throws Exception {
         test("queryTest.txt");
@@ -122,12 +121,8 @@ public class QueryTest {
                     }
                 } else if (line.startsWith("select") || line.startsWith("explain")) {
                     w.println(line);
-                    Iterator<? extends ResultRow> result = qe.executeQuery(line,
-                            QueryEngineImpl.SQL2, null).getRows().iterator();
                     boolean readEnd = true;
-                    while (result.hasNext()) {
-                        ResultRow row = result.next();
-                        String resultLine = readRow(line, row);
+                    for (String resultLine : executeQuery(line)) {
                         w.println(resultLine);
                         if (readEnd) {
                             line = r.readLine();
@@ -172,21 +167,34 @@ public class QueryTest {
         }
         if (errors) {
             throw new Exception("Results in target/queryTest.txt don't match expected " +
-                    "results in src/test/resources/quersTest.txt; compare the files for details");
+                    "results in src/test/resources/queryTest.txt; compare the files for details");
         }
     }
 
-    private String readRow(String query, ResultRow row) {
-        StringBuilder buff = new StringBuilder();
-        CoreValue[] values = row.getValues();
-        for (int i = 0; i < values.length; i++) {
-            if (i > 0) {
-                buff.append(", ");
+    private List<String> executeQuery(String query) throws ParseException {
+        List<String> lines = new ArrayList<String>();
+
+        Result result = qe.executeQuery(query, QueryEngineImpl.SQL2, null);
+        Iterator<? extends ResultRow> iterator = result.getRows().iterator();
+        while (iterator.hasNext()) {
+            ResultRow row = iterator.next();
+            StringBuilder buff = new StringBuilder();
+            CoreValue[] values = row.getValues();
+            for (int i = 0; i < values.length; i++) {
+                if (i > 0) {
+                    buff.append(", ");
+                }
+                CoreValue v = values[i];
+                buff.append(v == null ? "null" : v.getString());
             }
-            CoreValue v = values[i];
-            buff.append(v == null ? "null" : v.getString());
+            lines.add(buff.toString());
+        }
+
+        if (!query.contains("order by")) {
+            Collections.sort(lines);
         }
-        return buff.toString();
+
+        return lines;
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
Fri Apr  6 08:39:00 2012
@@ -21,9 +21,16 @@ package org.apache.jackrabbit.oak.query.
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.junit.After;
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -32,20 +39,15 @@ import org.junit.Test;
  */
 public class TraversingCursorTest {
 
-    MicroKernel mk;
+    private final MicroKernel mk = new MicroKernelImpl();
+
     String head;
 
     @Before
     public void setUp() {
-        mk = MicroKernelFactory.getInstance("simple:/target/temp;clear");
         head = mk.getHeadRevision();
     }
 
-    @After
-    public void tearDown() {
-        mk.dispose();
-    }
-
     @Test
     public void traverse() throws Exception {
         TraversingIndex t = new TraversingIndex(mk);
@@ -63,17 +65,21 @@ public class TraversingCursorTest {
         head = mk.commit("/", "+ \"parents\": { \"p0\": {\"id\": \"0\"}, \"p1\": {\"id\":
\"1\"}, \"p2\": {\"id\": \"2\"}}", head, "");
         head = mk.commit("/", "+ \"children\": { \"c1\": {\"p\": \"1\"}, \"c2\": {\"p\":
\"1\"}, \"c3\": {\"p\": \"2\"}, \"c4\": {\"p\": \"3\"}}", head, "");
         Filter f = new Filter(null);
-        Cursor c;
+ 
         f.setPath("/");
-        c = t.query(f, head);
-        String[] list = {"/", "/parents", "/parents/p0", "/parents/p1",  "/parents/p2",
-                "/children", "/children/c1", "/children/c2", "/children/c3", "/children/c4"};
-        for (String s : list) {
-            assertTrue(c.next());
-            assertEquals(s, c.currentPath());
+        List<String> paths = new ArrayList<String>();
+        Cursor c = t.query(f, head);
+        while (c.next()) {
+            paths.add(c.currentPath());
         }
+        Collections.sort(paths);
+        assertEquals(Arrays.asList(
+                "/", "/children", "/children/c1", "/children/c2",
+                "/children/c3", "/children/c4", "/parents",
+                "/parents/p0", "/parents/p1",  "/parents/p2"),
+                paths);
         assertFalse(c.next());
-        assertFalse(c.next());
+
         f.setPath("/nowhere");
         c = t.query(f, head);
         assertFalse(c.next());

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
Fri Apr  6 08:39:00 2012
@@ -50,8 +50,8 @@ select * from [nt:base] as p where p.[jc
 /parents
 
 select * from [nt:base] as p inner join [nt:base] as p2 on ischildnode(p2, p) where p.[jcr:path]
= '/'
-/, /parents
 /, /children
+/, /parents
 
 select * from [nt:base] as p inner join [nt:base] as p2 on isdescendantnode(p2, p) where
p.[jcr:path] = '/parents'
 /parents, /parents/p0
@@ -72,10 +72,10 @@ select id from [nt:base] where id is not
 0
 
 select * from [nt:base] as c right outer join [nt:base] as p on p.id = c.p where p.id is
not null
-null, /parents/p0
 /children/c1, /parents/p1
 /children/c2, /parents/p1
 /children/c3, /parents/p2
+null, /parents/p0
 
 select * from [nt:base] as p left outer join [nt:base] as c on p.id = c.p where p.id is not
null
 /parents/p0, null
@@ -180,3 +180,4 @@ select * from [nt:base] where upper(name
 
 select * from [nt:base] where upper(name) like '10\%'
 /test4
+

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java?rev=1310228&r1=1310227&r2=1310228&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
Fri Apr  6 08:39:00 2012
@@ -58,14 +58,17 @@ public class MicroKernelImpl implements 
     public MicroKernelImpl(String homeDir) throws MicroKernelException {
         init(homeDir);
     }
-    
+
     /**
-     * Argument-less constructor, used for in-memory kernel.
+     * Creates a new in-memory kernel instance that doesn't need to be
+     * explicitly closed, i.e. standard Java garbage collection will take
+     * care of releasing any acquired resources when no longer needed.
+     * Useful especially for test cases and other similar scenarios.
      */
     public MicroKernelImpl() {
         this(new Repository());
     }
-    
+
     /**
      * Alternate constructor, used for testing.
      * 



Mime
View raw message