jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1213255 - /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
Date Mon, 12 Dec 2011 14:33:10 GMT
Author: thomasm
Date: Mon Dec 12 14:33:10 2011
New Revision: 1213255

URL: http://svn.apache.org/viewvc?rev=1213255&view=rev
Log:
Test.

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

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java?rev=1213255&r1=1213254&r2=1213255&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
Mon Dec 12 14:33:10 2011
@@ -25,14 +25,19 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.mk.mem.NodeImpl;
+import org.apache.jackrabbit.mk.mem.NodeMap;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.runners.Parameterized.Parameters;
 
 public class MultiMkTestBase {
 
+    private static final boolean PROFILE = false;
+
     public MicroKernel mk;
     protected String url;
+    private Profiler prof;
 
     public MultiMkTestBase(String url) {
         this.url = url;
@@ -50,34 +55,25 @@ public class MultiMkTestBase {
 
     @Before
     public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(url + ";clean");
-        // clean all existing content
-        String result = mk.getNodes("/", mk.getHeadRevision(), 0, 0, -1);
-        List<String> names = new ArrayList<String>();
-        JsopReader t = new JsopTokenizer(result);
-        t.read('{');
-        if (!t.matches('}')) {
-            do {
-                String key = t.readString();
-                if (key.charAt(0) != ':') {
-                    names.add(key);
-                }
-                t.read(':');
-                t.readRawValue();
-            } while (t.matches(','));
-            t.read('}');
+        mk = MicroKernelFactory.getInstance(url);
+        cleanRepository(mk);
+
+        String root = mk.getNodes("/", mk.getHeadRevision());
+        if (!root.equals("{\":childNodeCount\":0}")) {
+            System.out.println("Last mk not disposed: " + root);
         }
-        if (!names.isEmpty()) {
-            StringBuilder buf = new StringBuilder();
-            for (String name : names) {
-                buf.append("- \"").append(name).append("\"\n");
-            }
-            mk.commit("/", buf.toString(), mk.getHeadRevision(), null);
+        if (PROFILE) {
+            prof = new Profiler();
+            prof.interval = 1;
+            prof.startCollecting();
         }
     }
 
     @After
     public void tearDown() throws InterruptedException {
+        if (prof != null) {
+            System.out.println(prof.getTop(5));
+        }
         mk.dispose();
     }
 
@@ -97,4 +93,42 @@ public class MultiMkTestBase {
         return mk.nodeExists("/:info", mk.getHeadRevision());
     }
 
+    private static void cleanRepository(MicroKernel mk) {
+        String result = mk.getNodes("/", mk.getHeadRevision(), 0, 0, -1);
+        List<String> names = new ArrayList<String>();
+        List<String> properties = new ArrayList<String>();
+        JsopReader t = new JsopTokenizer(result);
+        t.read('{');
+        if (!t.matches('}')) {
+            do {
+                String key = t.readString();
+                t.read(':');
+                if (t.matches('{')) {
+                    names.add(key);
+                    NodeImpl.parse(new NodeMap(), t, 0);
+                } else {
+                    if (!key.equals(":childNodeCount")) {
+                        properties.add(key);
+                    }
+                    t.readRawValue();
+                }
+            } while (t.matches(','));
+            t.read('}');
+        }
+        if (!names.isEmpty()) {
+            JsopBuilder buff = new JsopBuilder();
+            for (String name : names) {
+                buff.tag('-').value(name).newline();
+            }
+            mk.commit("/", buff.toString(), mk.getHeadRevision(), null);
+        }
+        if (!properties.isEmpty()) {
+            JsopBuilder buff = new JsopBuilder();
+            for (String property : properties) {
+                buff.tag('^').key(property).value(null).newline();
+            }
+            mk.commit("/", buff.toString(), mk.getHeadRevision(), null);
+        }
+    }
+
 }



Mime
View raw message