Example usage for org.apache.lucene.store RAMDirectory obtainLock

List of usage examples for org.apache.lucene.store RAMDirectory obtainLock

Introduction

In this page you can find the example usage for org.apache.lucene.store RAMDirectory obtainLock.

Prototype

@Override
    public final Lock obtainLock(String name) throws IOException 

Source Link

Usage

From source file:org.apache.maven.index.context.TrackingLockFactoryTest.java

License:Apache License

@Test
public void testLockUnlock() throws IOException {
    final TrackingLockFactory lf = new TrackingLockFactory(new SingleInstanceLockFactory());
    final RAMDirectory ram = new RAMDirectory(lf);
    final Lock foo = ram.obtainLock("foo");
    final Lock bar = ram.obtainLock("bar");
    bar.close();/*w w  w .  j a  v  a2 s .  com*/
    foo.close();
    ram.close();
}

From source file:org.apache.maven.index.context.TrackingLockFactoryTest.java

License:Apache License

@Test
public void testLockLocked() throws IOException {
    final TrackingLockFactory lf = new TrackingLockFactory(new SingleInstanceLockFactory());
    final RAMDirectory ram = new RAMDirectory(lf);
    final Lock foo = ram.obtainLock("foo");
    boolean thrownLOFE = false;
    try {/*from   ww w .  jav  a 2s.c o  m*/
        ram.obtainLock("foo");
    } catch (LockObtainFailedException e) {
        thrownLOFE = true;
    }
    assertTrue(thrownLOFE);
    foo.close();
    final Lock foo2 = ram.obtainLock("foo");
    foo2.close();
    ram.close();
}

From source file:org.apache.maven.index.context.TrackingLockFactoryTest.java

License:Apache License

@Test
public void testEmmittedLocks() throws IOException {
    final TrackingLockFactory lf = new TrackingLockFactory(new SingleInstanceLockFactory());
    final RAMDirectory ram = new RAMDirectory(lf);
    final Lock l1 = ram.obtainLock("l1");
    final Lock l2 = ram.obtainLock("l2");
    final Lock l3 = ram.obtainLock("l3");
    l2.close();// w w w. j  a va  2s  . c om
    Set<? extends Lock> emittedLocks = lf.getEmittedLocks(null);
    assertEquals(2, emittedLocks.size());
    assertTrue(emittedLocks.contains(l1));
    assertTrue(emittedLocks.contains(l3));
    emittedLocks = lf.getEmittedLocks("l3");
    assertEquals(1, emittedLocks.size());
    assertTrue(emittedLocks.contains(l3));
}