Author: reschke
Date: Thu Jan 26 13:34:05 2017
New Revision: 1780388

URL: http://svn.apache.org/viewvc?rev=1780388&view=rev
Log:
OAK-5523: LeaseUpdateRetryLoop: add test coverage

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentLeaseUpdateRetryTest.java
   (with props)

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentLeaseUpdateRetryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentLeaseUpdateRetryTest.java?rev=1780388&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentLeaseUpdateRetryTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentLeaseUpdateRetryTest.java
 Thu Jan 26 13:34:05 2017
@@ -0,0 +1,90 @@
+/*
+ * 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.oak.plugins.document;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.apache.jackrabbit.oak.stats.Clock.Virtual;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import junitx.util.PrivateAccessor;
+
+public class DocumentLeaseUpdateRetryTest {
+
+    private DocumentNodeStore ns;
+    private Virtual clock;
+
+    @Before
+    public void setup() throws Exception {
+        clock = new Clock.Virtual();
+        ClusterNodeInfo.setClock(clock);
+        ns = new DocumentMK.Builder().clock(clock).getNodeStore();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        ClusterNodeInfo.resetClockToDefault();
+    }
+
+    @Test
+    public void testLeaseRetryLoop() throws Exception {
+        ClusterNodeInfo clusterInfo = ns.getClusterInfo();
+        long leaseTime = clusterInfo.getLeaseTime();
+        long leaseEndTime1 = clusterInfo.getLeaseEndTime();
+        // TODO: replace privateAccessor.getField with a test-only
+        // package-protected access
+        Long leaseUpdateInterval = (Long) 
PrivateAccessor.getField(clusterInfo, "leaseUpdateInterval");
+
+        // assert that lease is fine at this point
+        // do this indirectly by trying to invoke some DocumentNodeStore
+        // functionality
+        ns.checkpoint(1);
+
+        // forward the virtual clock by more than the leaseUpdateInterval, to
+        // trigger a lease update
+        clock.waitUntil(clock.getTime() + leaseUpdateInterval + 1000);
+        // but also actually sleep more than 1s to give the background tasks of
+        // DNS a chance to run
+        Thread.sleep(1200);
+
+        // assert leaseEndTime having been updated - ie lease having been
+        // updated
+        long leaseEndTime2 = clusterInfo.getLeaseEndTime();
+        assertTrue(leaseEndTime1 < leaseEndTime2);
+
+        // again assert that lease is fine -> do some dummy ns call
+        ns.checkpoint(2);
+
+        // now forward the virtual clock by more than the lease time - which
+        // should cause lease to time out
+        clock.waitUntil(clock.getTime() + leaseTime + leaseUpdateInterval + 
1000);
+
+        // so the next call to the lease check wrapper should now run into the
+        // retry loop, as the lease has timed out
+        try {
+            ns.checkpoint(3);
+        } catch (Exception e) {
+            // it should not fail however, since we should be able to do the
+            // retry
+            fail("call should not have failed: " + e);
+        }
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentLeaseUpdateRetryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to