Hi,

On 5/18/06, Alexandru Popescu <[EMAIL PROTECTED]> wrote:
Unfortunately there is no attachment :-)

It must have gotten lost along the way. Here's the
ConcurrentQueryTest.java file inline:

----------
import java.io.*;
import java.util.*;
import javax.jcr.*;
import javax.jcr.query.*;
import org.apache.jackrabbit.core.TestRepository;
import junit.framework.TestCase;

public class ConcurrentQueryTest extends TestCase {

   private class QueryRunner implements Runnable {

       private final Session session;

       public QueryRunner(Session session) {
           this.session = session;
       }

       public void run() {
           try {
               for (int i = 0; i < 1000; i++) {
                   QueryManager manager =
                       session.getWorkspace().getQueryManager();
                   Query query = manager.createQuery(
                       "//*[jcr:contains(.,'void')]", Query.XPATH);
                   query.execute().getNodes();
               }
           } catch (Exception e) {
               exception = e;
           } finally {
               session.logout();
           }
       }

   }

   private Exception exception;

   private Session session;

   private Thread a;

   private Thread b;

   protected void setUp() throws Exception {
       Repository repository = TestRepository.getInstance();
       session = repository.login();
       Node n = session.getRootNode().addNode("test");
       for (int i = 0; i < 1000; i++) {
           Node f = n.addNode("node" + i, "nt:file");
           Node r = f.addNode("jcr:content", "nt:resource");
           r.setProperty("jcr:mimeType", "text/plain");
           r.setProperty("jcr:lastModified", Calendar.getInstance());
           InputStream is = new FileInputStream("ConcurrentQueryTest.java");
           try {
               r.setProperty("jcr:data", is);
           } finally {
               is.close();
           }
       }
       session.save();

       exception = null;
       a = new Thread(new QueryRunner(repository.login()));
       b = new Thread(new QueryRunner(repository.login()));
   }

   protected void tearDown() throws Exception {
       session.getItem("/test").remove();
       session.save();
       session.logout();
   }

   public void testConcurrentQuery() throws Exception {
       a.start();
       b.start();
       a.join();
       b.join();
       if (exception != null) {
           fail("Got exception: " + exception.getMessage());
       }
   }

}
----------

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - [EMAIL PROTECTED]
Software craftsmanship, JCR consulting, and Java development

Reply via email to