jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r809527 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
Date Mon, 31 Aug 2009 10:12:09 GMT
Author: tripod
Date: Mon Aug 31 10:12:09 2009
New Revision: 809527

URL: http://svn.apache.org/viewvc?rev=809527&view=rev
Log:
Improving test case

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java?rev=809527&r1=809526&r2=809527&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentImportTest.java
Mon Aug 31 10:12:09 2009
@@ -17,11 +17,14 @@
 package org.apache.jackrabbit.core;
 
 import java.util.UUID;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Node;
 import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.InvalidItemStateException;
 
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -50,29 +53,55 @@
     private static final int NUM_NODES = 10;
 
     public void testConcurrentImport() throws RepositoryException {
-        concurrentImport(new String[]{JcrConstants.MIX_REFERENCEABLE});
+        concurrentImport(new String[]{JcrConstants.MIX_REFERENCEABLE}, false);
+    }
+
+    public void testConcurrentImportSynced() throws RepositoryException {
+        concurrentImport(new String[]{JcrConstants.MIX_REFERENCEABLE}, true);
     }
 
     public void testConcurrentImportVersionable() throws RepositoryException {
-        concurrentImport(new String[]{JcrConstants.MIX_VERSIONABLE});
+        concurrentImport(new String[]{JcrConstants.MIX_VERSIONABLE}, false);
+    }
+
+    public void testConcurrentImportVersionableSynced() throws RepositoryException {
+        concurrentImport(new String[]{JcrConstants.MIX_VERSIONABLE}, true);
     }
 
-    private void concurrentImport(final String[] mixins) throws RepositoryException {
+    private void concurrentImport(final String[] mixins, final boolean sync) throws RepositoryException
{
         final String[] uuids = new String[NUM_NODES];
         for (int i=0; i<uuids.length; i++) {
             uuids[i] = UUID.randomUUID().toString();
         }
         log.println("concurrentImport: c=" + CONCURRENCY + ", n=" + NUM_NODES);
         log.flush();
+
+        final Lock lock = new ReentrantLock();
         runTask(new Task() {
             public void execute(Session session, Node test) throws RepositoryException {
                 try {
                     // add versionable nodes
                     for (String uuid : uuids) {
-                        Node n = addNode(test, uuid, JcrConstants.NT_UNSTRUCTURED, uuid,
mixins);
-                        session.save();
-                        log.println("Added " + n.getPath());
-                        log.flush();
+                        if (sync) {
+                            lock.lock();
+                        }
+                        try {
+                            session.refresh(false);
+                            addNode(test, uuid, JcrConstants.NT_UNSTRUCTURED, uuid, mixins);
+                            try {
+                                session.save();
+                                log.println("Added " + test.getPath() + "/" + uuid);
+                                log.flush();
+                            } catch (InvalidItemStateException e) {
+                                log.println("Ignoring expected error: " + e.toString());
+                                log.flush();
+                                session.refresh(false);
+                            }
+                        } finally {
+                            if (sync) {
+                                lock.unlock();
+                            }
+                        }
                         try {
                             Thread.sleep(1);
                         } catch (InterruptedException e) {



Mime
View raw message