You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2011/06/16 20:14:37 UTC

svn commit: r1136580 - /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ClockTest.java

Author: thomasm
Date: Thu Jun 16 18:14:37 2011
New Revision: 1136580

URL: http://svn.apache.org/viewvc?rev=1136580&view=rev
Log:
A non-descending clock implementation.

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ClockTest.java

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ClockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ClockTest.java?rev=1136580&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ClockTest.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ClockTest.java Thu Jun 16 18:14:37 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.mk;
+
+import org.apache.jackrabbit.mk.util.NonDescendingClock;
+import junit.framework.TestCase;
+
+public class ClockTest extends TestCase {
+
+    public void test() throws InterruptedException {
+        long last = System.currentTimeMillis() + 10000;
+        NonDescendingClock c = new NonDescendingClock(last);
+        for (int i = 0; i < 1000; i++) {
+            long n = c.time();
+            assertEquals(last + 1, n);
+        }
+        for (int i = 0; i < 1000; i++) {
+            long n = c.time();
+            assertEquals(last + 2, n);
+        }
+        long now = System.currentTimeMillis();
+        c = new NonDescendingClock(now);
+        for (int i = 0; i < 10; i++) {
+            Thread.sleep(10);
+            long x = c.time();
+            assertTrue(x > now);
+            now = x;
+        }
+    }
+
+}