Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2641

Lock.getSecondsRemaining() does not provide actual time-to-live

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 5.3.0.Final
    • 5.2.0.Final
    • JCR
    • Hide
          @Test
          public void shouldProvideActualSecondsRemaining() throws Exception {
              // Create a new lockable node
              Node node = session.getRootNode().addNode("test");
              node.addMixin("mix:lockable");
              session.save();
              String path = node.getPath();
      
              // Lock the node
              int timeout = 4;
              JcrLockManager lockManager = session.getWorkspace().getLockManager();
              Lock lock = lockManager.lock(node.getPath(), false, false, timeout, null);
              assertTrue(node.isLocked());
              assertNotEquals(Long.MAX_VALUE, lock.getSecondsRemaining());
              assertTrue(lock.getSecondsRemaining() <= timeout);
      
              // Wait enough time to see the change in seconds remaining
              Thread.sleep(TimeUnit.SECONDS.toMillis(timeout / 2));
              assertTrue(lock.getSecondsRemaining() <= timeout / 2);
      
              // Look at the same lock from another session
              session.logout();
              session = repository.login();
              lockManager = session.getWorkspace().getLockManager();
              lock = lockManager.getLock(path);
              assertTrue(lock.getSecondsRemaining() > 0);
              assertNotEquals(Long.MAX_VALUE, lock.getSecondsRemaining());
              assertTrue(lock.getSecondsRemaining() <= timeout);
      
          }
      
      Show
      @Test public void shouldProvideActualSecondsRemaining() throws Exception { // Create a new lockable node Node node = session.getRootNode().addNode( "test" ); node.addMixin( "mix:lockable" ); session.save(); String path = node.getPath(); // Lock the node int timeout = 4; JcrLockManager lockManager = session.getWorkspace().getLockManager(); Lock lock = lockManager.lock(node.getPath(), false , false , timeout, null ); assertTrue(node.isLocked()); assertNotEquals( Long .MAX_VALUE, lock.getSecondsRemaining()); assertTrue(lock.getSecondsRemaining() <= timeout); // Wait enough time to see the change in seconds remaining Thread .sleep(TimeUnit.SECONDS.toMillis(timeout / 2)); assertTrue(lock.getSecondsRemaining() <= timeout / 2); // Look at the same lock from another session session.logout(); session = repository.login(); lockManager = session.getWorkspace().getLockManager(); lock = lockManager.getLock(path); assertTrue(lock.getSecondsRemaining() > 0); assertNotEquals( Long .MAX_VALUE, lock.getSecondsRemaining()); assertTrue(lock.getSecondsRemaining() <= timeout); }

    Description

      For an open-scoped lock which is created with timeout hint less than Long.MAX_VALUE Lock.getSecondsRemaining() returns Long.MAX_VALUE (for a Lock object obtained via the session that created the lock) or negative value (for a Lock object obtained via another session).

      Attachments

        Activity

          People

            hchiorean Horia Chiorean (Inactive)
            zcc39r Rustam Usmanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: