5 Replies Latest reply on May 29, 2012 11:10 AM by duncanmcintyre

    orderBefore causes infinite loop hang

    duncanmcintyre

      Running Modeshape 3.0-Alpha4 with this code causes an infinite loop in  org.modeshape.jcr.cache.document.AbstractChildReferences from lines 119 - 128.

       

      The code runs fine on Jackrabbit 1.6, which is what I think it should do.

       

      Interestingly, it also fails on Modeshape 2.7 ("No item exists at path {}Child 0 in workspace "workspace1"").

       

      package com.mom.jcrperf.tests;
      
      import javax.jcr.Node;
      import javax.jcr.NodeIterator;
      import javax.jcr.RepositoryException;
      import javax.jcr.Session;
      
      /**
       * Measure the speed of reordering child nodes.
       * 
       * Create 10 parents Give each one 100 children Reorder the children in reverse
       * order
       */
      public class ReorderChildNodesTest extends PerformanceTest {
      
           private static final int PARENT_COUNT = 10;
           private static final int CHILD_COUNT = 100;
      
           private Session session;
      
           private Node node;
      
           private String bigProperty = "this is a nice big string";
      
           public void beforeSuite() throws RepositoryException {
      
                for (int i = 0; i < 8; i++) {
                     bigProperty = bigProperty + bigProperty + i;
                }
      
                session = getRepository().login(getCredentials());
                node = session.getRootNode().addNode("testnode", "nt:unstructured");
                for (int i = 0; i < PARENT_COUNT; i++) {
      
                     Node parent = node.addNode("node" + i, "nt:unstructured");
                     parent.addMixin("mix:versionable");
                     parent.setProperty("prop_" + i, bigProperty + i);
                     
                     session.save();
                     
                     parent.checkout();
      
                     for (int j = 0; j < CHILD_COUNT; j++) {
                          Node child = parent.addNode("Child " + j, "nt:unstructured");
                          child.addMixin("mix:versionable");
                          child.setProperty("prop_" + j, bigProperty + j);
                     }
                     parent.save();
                     parent.checkin();
                }
                session.save();
           }
      
           public void beforeTest() throws RepositoryException {
                //
           }
      
           public void runTest() throws Exception {
      
                for (NodeIterator i = node.getNodes(); i.hasNext();) {
      
                     Node parent = i.nextNode();
                     parent.checkout();
                     
                     int kid = 0;
      
                     for (NodeIterator j = parent.getNodes(); j.hasNext();) {
                          Node child = j.nextNode();
                          parent.orderBefore("Child " + kid, "Child 0");
                          kid++;
                     }
                     parent.save(); // !!!! Moving this code up into the loop eliminates the problem !!!!
                     parent.checkin();
                }
                session.save();
           }
      
           public void afterTest() throws RepositoryException {
                session.save();
           }
      
           public void afterSuite() throws RepositoryException {
                session.getRootNode().getNode("testnode").remove();
                session.save();
                session.logout();
           }
      
      }