You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2012/06/14 15:18:58 UTC

svn commit: r1350226 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java

Author: reschke
Date: Thu Jun 14 13:18:57 2012
New Revision: 1350226

URL: http://svn.apache.org/viewvc?rev=1350226&view=rev
Log:
JCR-3342: add additional entry collector tests that run concurrently with a few read-only threads (work-in-progress)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java?rev=1350226&r1=1350225&r2=1350226&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java Thu Jun 14 13:18:57 2012
@@ -16,19 +16,16 @@
  */
 package org.apache.jackrabbit.core.security.authorization.acl;
 
-import org.apache.jackrabbit.api.JackrabbitSession;
-import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
-import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
-import org.apache.jackrabbit.api.security.user.Group;
-import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.core.security.TestPrincipal;
-import org.apache.jackrabbit.test.NotExecutableException;
-import org.apache.jackrabbit.test.api.security.AbstractAccessControlTest;
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Node;
-import javax.jcr.Property;
+import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.security.AccessControlEntry;
@@ -37,12 +34,16 @@ import javax.jcr.security.AccessControlM
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.AccessControlPolicyIterator;
 import javax.jcr.security.Privilege;
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.UUID;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.core.security.TestPrincipal;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.security.AbstractAccessControlTest;
 
 /**
  * <code>EntryCollectorTest</code>...
@@ -362,6 +363,120 @@ public class EntryCollectorTest extends 
         } finally {
             superuser2.logout();
         }
-        
     }
+
+    static interface TestInvokation {
+        public void runTest() throws Exception;
+    }
+
+    private void runTestUnderLoad(TestInvokation ti) throws Exception {
+
+        JcrTestThread t[] = new JcrTestThread[4];
+
+        for (int i = 0; i < t.length; i++) {
+            t[i] = new JcrTestThread();
+        }
+
+        try {
+            for (int i = 0; i < t.length; i++) {
+                t[i].start();
+            }
+            ti.runTest();
+        }
+        finally {
+            for (int i = 0; i < t.length; i++) {
+                t[i].stopMe();
+                t[i].join();
+                Throwable th = t[i].getLastExc();
+                if (th != null) {
+                    fail("failure in load thread: " + th);
+                }
+            }
+        }
+    }
+
+    public void testCacheUnderLoad() throws Exception {
+        runTestUnderLoad(new TestInvokation() {
+            public void runTest() throws Exception {
+                testCache();
+            }
+        });
+    }
+
+    public void testEntriesAreCachedUnderLoad() throws Exception {
+        runTestUnderLoad(new TestInvokation() {
+            public void runTest() throws Exception {
+                testEntriesAreCached();
+            }
+        });
+    }
+
+    public void testPermissionsUnderLoad() throws Exception {
+        runTestUnderLoad(new TestInvokation() {
+            public void runTest() throws Exception {
+                testPermissions();
+            }
+        });
+    }
+
+    /**
+     * Test code that that walks the repository.
+     */
+    private class JcrTestThread extends Thread {
+
+        private boolean stopme = false;
+        private Throwable lastErr;
+
+        @Override
+        public void run() {
+            while (!this.stopme) {
+                Session session = null;
+                try {
+                    session = getHelper().getReadOnlySession();
+                    walk(session.getRootNode());
+                }
+                catch (RepositoryException ex) {
+                    // ignored
+                } catch (Throwable ex) {
+                    lastErr = ex;
+                }
+                finally {
+                    if (session != null) {
+                        session.logout();
+                        session = null;
+                    }
+                }
+            }
+        }
+
+        public void stopMe() {
+            this.stopme = true;
+        }
+
+        public Throwable getLastExc() {
+            return lastErr;
+        }
+
+        private void walk(Node node) {
+            if (stopme) {
+                return;
+            }
+
+            try {
+                if ("/jcr:system".equals(node.getPath())) {
+                    // do not descend into an non-interesting subtree
+                    return;
+                }
+
+                NodeIterator ni = node.getNodes();
+                while (ni.hasNext()) {
+                    walk(ni.nextNode());
+                }
+            } catch (RepositoryException ex) {
+                // ignore
+            } catch (Throwable ex) {
+                lastErr = ex;
+            }
+        }
+   }
 }
\ No newline at end of file



Re: svn commit: r1350226 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EntryCollectorTest.java

Posted by Julian Reschke <ju...@gmx.de>.
On 2012-06-14 15:18, reschke@apache.org wrote:
> Author: reschke
> Date: Thu Jun 14 13:18:57 2012
> New Revision: 1350226
>
> URL: http://svn.apache.org/viewvc?rev=1350226&view=rev
> Log:
> JCR-3342: add additional entry collector tests that run concurrently with a few read-only threads (work-in-progress)
> ...

This commit adds tests that are known to occasionally fail on at least 
one machine (not mine); apologies if it happens elsewhere. If it does, 
by all means please capture the Junit log and attach it to JCR-3342!

Best regards, Julian