コード例 #1
0
  @Test
  public void testDeleteOnUnlockIfLocked() throws Exception {

    File lockFile = new File(IOHelper.getDefaultDataDirectory(), "lockToTest2");
    IOHelper.mkdirs(lockFile.getParentFile());
    lockFile.createNewFile();

    LockFile underTest = new LockFile(lockFile, true);

    underTest.lock();

    assertTrue("valid", underTest.keepAlive());

    underTest.unlock();

    assertFalse("file deleted on unlock", lockFile.exists());
  }
コード例 #2
0
  @Test
  public void testNoDeleteOnUnlockIfNotLocked() throws Exception {

    File lockFile = new File(IOHelper.getDefaultDataDirectory(), "lockToTest1");
    IOHelper.mkdirs(lockFile.getParentFile());
    lockFile.createNewFile();

    LockFile underTest = new LockFile(lockFile, true);

    underTest.lock();

    lockFile.delete();

    assertFalse("no longer valid", underTest.keepAlive());

    // a slave gets in
    lockFile.createNewFile();

    underTest.unlock();

    assertTrue("file still exists after unlock when not locked", lockFile.exists());
  }