コード例 #1
0
 /** Test ensureValid returns true after acquire */
 public void testValidAfterAcquire() throws IOException {
   Path tempPath = createTempDir();
   Directory dir = getDirectory(tempPath);
   Lock l = dir.obtainLock("commit");
   l.ensureValid(); // no exception
   l.close();
   dir.close();
 }
コード例 #2
0
  /** Test closing locks twice */
  public void testDoubleClose() throws IOException {
    Path tempPath = createTempDir();
    Directory dir = getDirectory(tempPath);

    Lock l = dir.obtainLock("commit");
    l.close();
    l.close(); // close again, should be no exception

    dir.close();
  }
コード例 #3
0
  /** Test obtaining and releasing locks, checking validity */
  public void testBasics() throws IOException {
    Path tempPath = createTempDir();
    Directory dir = getDirectory(tempPath);

    Lock l = dir.obtainLock("commit");
    // shouldn't be able to get the lock twice
    expectThrows(
        LockObtainFailedException.class,
        () -> {
          dir.obtainLock("commit");
        });
    l.close();

    // Make sure we can obtain first one again:
    l = dir.obtainLock("commit");
    l.close();

    dir.close();
  }
コード例 #4
0
 @Override
 public void close() {
   if (closed.compareAndSet(false, true) && locks != null) {
     for (Lock lock : locks) {
       try {
         logger.trace("releasing lock [{}]", lock);
         lock.close();
       } catch (IOException e) {
         logger.trace("failed to release lock [{}]", e, lock);
       }
     }
   }
 }
コード例 #5
0
  /** Test ensureValid throws exception after close */
  public void testInvalidAfterClose() throws IOException {
    Path tempPath = createTempDir();
    Directory dir = getDirectory(tempPath);

    Lock l = dir.obtainLock("commit");
    l.close();

    expectThrows(
        AlreadyClosedException.class,
        () -> {
          l.ensureValid();
        });

    dir.close();
  }