Example usage for org.apache.lucene.store Lock ensureValid

List of usage examples for org.apache.lucene.store Lock ensureValid

Introduction

In this page you can find the example usage for org.apache.lucene.store Lock ensureValid.

Prototype

public abstract void ensureValid() throws IOException;

Source Link

Document

Best effort check that this lock is still valid.

Usage

From source file:com.github.lucene.store.jdbc.JdbcDirectoryLockITest.java

License:Apache License

@Test
public void testLocks() throws Exception {
    try {// w ww  .  j  a v a2 s. c o  m
        final Connection con1 = DataSourceUtils.getConnection(dataSource);
        final Lock lock1 = dir1.obtainLock(IndexWriter.WRITE_LOCK_NAME);
        lock1.ensureValid();

        try {
            dir2.obtainLock(IndexWriter.WRITE_LOCK_NAME);
            Assert.fail("lock2 should not have valid lock");
        } catch (final IOException e) {
        }

        lock1.close();

        DataSourceUtils.commitConnectionIfPossible(con1);
        DataSourceUtils.releaseConnection(con1);

        final Connection con2 = DataSourceUtils.getConnection(dataSource);
        final Lock lock2 = dir2.obtainLock(IndexWriter.WRITE_LOCK_NAME);
        lock2.ensureValid();
        lock2.close();

        DataSourceUtils.commitConnectionIfPossible(con2);
        DataSourceUtils.releaseConnection(con2);

    } finally {
        dir1.delete();
    }
}