Joscorbe commented on a change in pull request #359:
URL: https://github.com/apache/jackrabbit-oak/pull/359#discussion_r711948344



##########
File path: 
oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfoTest.java
##########
@@ -268,6 +270,113 @@ public void renewLeaseTimedOutWithCheck() throws 
Exception {
         }
     }
 
+    // OAK-9564
+    @Test
+    public void renewLeaseSameRuntimeId() throws Exception {
+        ClusterNodeInfo info = newClusterNodeInfo(1);
+        String runtimeId = info.getRuntimeId();
+        long leaseEnd = info.getLeaseEndTime();
+        waitLeaseUpdateInterval();
+        assertTrue(info.renewLease());
+        assertTrue(info.getLeaseEndTime() > leaseEnd);
+        // The Runtime UUID should remain the same
+        assertEquals(info.getRuntimeId(), runtimeId);
+        assertFalse(handler.isLeaseFailure());
+    }
+
+    // OAK-9564
+    @Test
+    public void renewLeaseDifferentRuntimeId() throws Exception {
+        ClusterNodeInfo info = newClusterNodeInfo(1);
+        waitLeaseUpdateInterval();
+        long leaseEndTimeBeforeRenew = info.getLeaseEndTime();
+
+        // Modify the UUID to mock it belongs to a different node
+        UpdateOp update = new UpdateOp("1", false);
+        update.set(ClusterNodeInfo.RUNTIME_ID_KEY, "different-uuid");
+        store.findAndUpdate(Collection.CLUSTER_NODES, update);
+
+        try {
+            info.renewLease();
+            fail("Could not update lease anymore");
+        } catch(DocumentStoreException e) {
+            // expected
+        }
+
+        // Lease end time shouldn't be different
+        assertEquals(leaseEndTimeBeforeRenew, info.getLeaseEndTime());
+    }
+
+    // OAK-9564
+    @Test
+    public void renewLeaseTakingLongerThanTimeout() throws Exception {
+        ClusterNodeInfo info = newClusterNodeInfo(1);
+        waitLeaseUpdateInterval();
+        final long leaseEndTimeBeforeRenew = info.getLeaseEndTime();
+        final String runtimeId = info.getRuntimeId();
+
+        Map<String, Long> unexpectedLeaseEnd = new HashMap<>();
+        unexpectedLeaseEnd.put(ClusterNodeInfo.LEASE_END_KEY, 
info.getLeaseEndTime() + 133333);
+
+        // The update will fail after 30 seconds. Simulating a Mongo timeout.
+        store.setFailAfterUpdate(1);
+        store.setDelayMillisOnce(30000);
+        store.setDelayMillis(10000);
+        store.setFindShouldAlterReturnDocument(true);
+        // However, the following find after the update will return an
+        // unexpected lease time (but still within a valid time).
+        // This unexpected update could come from a previous but very slow 
update
+        // executed in Mongo. So it's still a valid one, but not the new one
+        // that is expected.
+        store.setMapAlterReturnDocument(unexpectedLeaseEnd);

Review comment:
       It seems like some changes were not committed in this file. I have added 
them and improved a bit this test.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to