jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r640838 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/ test/java/org/apache/jackrabbit/core/version/
Date Tue, 25 Mar 2008 14:47:32 GMT
Author: mreutegg
Date: Tue Mar 25 07:47:28 2008
New Revision: 640838

URL: http://svn.apache.org/viewvc?rev=640838&view=rev
Log:
JCR-1463: Core: Failing version tests (testRestore....)

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=640838&r1=640837&r2=640838&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
Tue Mar 25 07:47:28 2008
@@ -51,6 +51,11 @@
     private static Logger log = LoggerFactory.getLogger(InternalVersionHistory.class);
 
     /**
+     * The last current time that was returned by {@link #getCurrentTime()}.
+     */
+    private static final Calendar CURRENT_TIME = Calendar.getInstance();
+
+    /**
      * the cache of the version labels
      * key = version label (String)
      * value = version name
@@ -163,7 +168,7 @@
             Iterator iter = nameCache.keySet().iterator();
             while (iter.hasNext()) {
                 Name versionName = (Name) iter.next();
-                InternalVersionImpl v = (InternalVersionImpl) createVersionInstance(versionName);
+                InternalVersionImpl v = createVersionInstance(versionName);
                 v.legacyResolveSuccessors();
             }
         }
@@ -479,7 +484,7 @@
         NodeStateEx vNode = node.addNode(name, NameConstants.NT_VERSION, versionId, true);
 
         // initialize 'created', 'predecessors' and 'successors'
-        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(Calendar.getInstance()));
+        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
         vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, predecessors);
         vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
 
@@ -532,7 +537,7 @@
         NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION,
versionId, true);
 
         // initialize 'created' and 'predecessors'
-        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(Calendar.getInstance()));
+        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
         vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
         vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
 
@@ -556,5 +561,25 @@
 
         parent.store();
         return new InternalVersionHistoryImpl(vMgr, pNode);
+    }
+
+    /**
+     * Returns the current time as a calendar instance and makes sure that no
+     * two Calendar instances represent the exact same time. If this method is
+     * called quickly in succession each Calendar instance returned is at least
+     * one millisecond later than the previous one.
+     *
+     * @return the current time.
+     */
+    static Calendar getCurrentTime() {
+        long time = System.currentTimeMillis();
+        synchronized (CURRENT_TIME) {
+            if (time > CURRENT_TIME.getTimeInMillis()) {
+                CURRENT_TIME.setTimeInMillis(time);
+            } else {
+                CURRENT_TIME.add(Calendar.MILLISECOND, 1);
+            }
+            return (Calendar) CURRENT_TIME.clone();
+        }
     }
 }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java?rev=640838&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
Tue Mar 25 07:47:28 2008
@@ -0,0 +1,42 @@
+/*
+ * 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 junit.framework.TestCase;
+
+import java.util.Calendar;
+
+/**
+ * <code>InternalVersionHistoryImplTest</code> executes tests for
+ * {@link InternalVersionHistoryImpl}.
+ */
+public class InternalVersionHistoryImplTest extends TestCase {
+
+    /**
+     * Checks if {@link InternalVersionHistoryImpl#getCurrentTime()} returns
+     * monotonically increasing Calendar instances.
+     */
+    public void testGetCurrentTime() {
+        Calendar last = InternalVersionHistoryImpl.getCurrentTime();
+        for (int i = 0; i < 100; i++) {
+            Calendar next = InternalVersionHistoryImpl.getCurrentTime();
+            assertTrue("InternalVersionHistoryImpl.getCurrentTime() not monotonically increasing",
+                    last.compareTo(next) < 0);
+            last = next;
+        }
+    }
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java?rev=640838&r1=640837&r2=640838&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
Tue Mar 25 07:47:28 2008
@@ -33,6 +33,7 @@
     public static Test suite() {
         TestSuite suite = new TestSuite("Version tests");
         suite.addTestSuite(CheckinRemoveVersionTest.class);
+        suite.addTestSuite(InternalVersionHistoryImplTest.class);
         suite.addTestSuite(RemoveVersionLabelTest.class);
         suite.addTestSuite(RestoreTest.class);
         suite.addTestSuite(VersionIteratorImplTest.class);



Mime
View raw message