jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r558167 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java test/java/org/apache/jackrabbit/core/version/ test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
Date Fri, 20 Jul 2007 22:00:06 GMT
Author: jukka
Date: Fri Jul 20 15:00:05 2007
New Revision: 558167

URL: http://svn.apache.org/viewvc?view=rev&rev=558167
Log:
JCR-1006: Applied patch from Christoph Kiehl

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java?view=diff&rev=558167&r1=558166&r2=558167
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
Fri Jul 20 15:00:05 2007
@@ -66,7 +66,7 @@
         this.session = (SessionImpl) session;
 
         addVersion(rootVersion);
-        // retrieve inital size, since size of the list is not stable
+        // retrieve initial size, since size of the list is not stable
         size = versions.size();
     }
 
@@ -134,19 +134,25 @@
     }
 
     /**
-     * Adds the version 'v' to the list of versions to return and then calls
-     * it self recursively with all the verions prodecessors.
+     * Adds the version 'v' to the list of versions to return and then iterates
+     * over the hierarchy of successors of 'v'.
      *
      * @param v
      */
     private synchronized void addVersion(InternalVersion v) {
-        NodeId id = v.getId();
-        if (!versions.contains(id)) {
-            versions.add(id);
-            InternalVersion[] vs = v.getSuccessors();
-            for (int i = 0; i < vs.length; i++) {
-                addVersion(vs[i]);
+        LinkedList workQueue = new LinkedList();
+        workQueue.add(v);
+        while (!workQueue.isEmpty()) {
+            InternalVersion currentVersion = (InternalVersion) workQueue.removeFirst();
+            NodeId id = currentVersion.getId();
+            if (!versions.contains(id)) {
+                versions.add(id);
+                InternalVersion[] successors = currentVersion.getSuccessors();
+                for (int i = 0; i < successors.length; i++) {
+                    workQueue.add(successors[i]);
+                }
             }
         }
+
     }
 }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java?view=auto&rev=558167
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
Fri Jul 20 15:00:05 2007
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.version;
+
+import java.util.Calendar;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.uuid.UUID;
+
+public class VersionIteratorImplTest extends TestCase {
+
+    private static final int VERSION_COUNT = 10000;
+
+    private final class DummyInternalVersion implements InternalVersion {
+
+        private final InternalVersion[] successors;
+        private NodeId id;
+
+        public DummyInternalVersion(InternalVersion[] successors, NodeId id) {
+            this.successors = successors;
+            this.id = id;
+        }
+
+        public InternalVersion[] getSuccessors() {
+            return successors;
+        }
+
+        public NodeId getId() {
+            return id;
+        }
+
+        public Calendar getCreated() {return null;}
+        public InternalFrozenNode getFrozenNode() {return null;}
+        public QName[] getLabels() {return null;}
+        public QName getName() {return null;}
+        public InternalVersion[] getPredecessors() {return null;}
+        public InternalVersionHistory getVersionHistory() {return null;}
+        public boolean hasLabel(QName label) {return false;}
+        public boolean isMoreRecent(InternalVersion v) {return false;}
+        public boolean isRootVersion() {return false;}
+        public InternalVersionItem getParent() {return null;}
+    }
+
+    public void testVersionIterator() throws Exception {
+
+        InternalVersion version = new DummyInternalVersion(new InternalVersion[] {}, new
NodeId(UUID.randomUUID()));
+        for (int i = 1; i < VERSION_COUNT; i++) {
+            version = new DummyInternalVersion(new InternalVersion[] {version}, new NodeId(UUID.randomUUID()));
+        }
+
+        try {
+            VersionIteratorImpl versionIteratorImpl = new VersionIteratorImpl(null, version);
+            assertEquals(VERSION_COUNT, versionIteratorImpl.getSize());
+        } catch (StackOverflowError e) {
+            fail("Should be able to handle " + VERSION_COUNT + " versions.");
+        }
+
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message