You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2015/05/30 09:19:40 UTC
svn commit: r1682585 - in /lucene/dev/branches/lucene6508/lucene:
core/src/java/org/apache/lucene/store/ core/src/test/org/apache/lucene/store/
test-framework/src/java/org/apache/lucene/store/
Author: rmuir
Date: Sat May 30 07:19:39 2015
New Revision: 1682585
URL: http://svn.apache.org/r1682585
Log:
LUCENE-6508: add more tests
Modified:
lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java
lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java
lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java
lucene/dev/branches/lucene6508/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java
Modified: lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=1682585&r1=1682584&r2=1682585&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java Sat May 30 07:19:39 2015
@@ -139,11 +139,11 @@ public final class NativeFSLockFactory e
// FileLock has an accessor, but mockfs doesnt yet mock the locks, too scary atm.
static final class NativeFSLock extends Lock {
- private final FileLock lock;
- private final FileChannel channel;
- private final Path path;
- private final FileTime creationTime;
- private volatile boolean closed;
+ final FileLock lock;
+ final FileChannel channel;
+ final Path path;
+ final FileTime creationTime;
+ volatile boolean closed;
NativeFSLock(FileLock lock, FileChannel channel, Path path, FileTime creationTime) {
this.lock = lock;
Modified: lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java?rev=1682585&r1=1682584&r2=1682585&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java Sat May 30 07:19:39 2015
@@ -21,6 +21,8 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import org.apache.lucene.util.IOUtils;
+
/** Simple tests for NativeFSLockFactory */
public class TestNativeFSLockFactory extends BaseLockFactoryTestCase {
@@ -40,4 +42,63 @@ public class TestNativeFSLockFactory ext
l.close();
dir.close();
}
+
+ /** release the lock and test ensureValid fails */
+ public void testInvalidateLock() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+ NativeFSLockFactory.NativeFSLock lock = (NativeFSLockFactory.NativeFSLock) dir.obtainLock("test.lock");
+ lock.ensureValid();
+ lock.lock.release();
+ try {
+ lock.ensureValid();
+ fail("no exception");
+ } catch (AlreadyClosedException expected) {
+ // ok
+ } finally {
+ IOUtils.closeWhileHandlingException(lock);
+ }
+ dir.close();
+ }
+
+ /** close the channel and test ensureValid fails */
+ public void testInvalidateChannel() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+ NativeFSLockFactory.NativeFSLock lock = (NativeFSLockFactory.NativeFSLock) dir.obtainLock("test.lock");
+ lock.ensureValid();
+ lock.channel.close();
+ try {
+ lock.ensureValid();
+ fail("no exception");
+ } catch (AlreadyClosedException expected) {
+ // ok
+ } finally {
+ IOUtils.closeWhileHandlingException(lock);
+ }
+ dir.close();
+ }
+
+ /** delete the lockfile and test ensureValid fails */
+ public void testDeleteLockFile() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+ Lock lock = dir.obtainLock("test.lock");
+ lock.ensureValid();
+
+ try {
+ dir.deleteFile("test.lock");
+ } catch (Exception e) {
+ // we can't delete a file for some reason, just clean up and assume the test.
+ IOUtils.closeWhileHandlingException(lock);
+ assumeNoException("test requires the ability to delete a locked file", e);
+ }
+
+ try {
+ lock.ensureValid();
+ fail("no exception");
+ } catch (IOException expected) {
+ // ok
+ } finally {
+ IOUtils.closeWhileHandlingException(lock);
+ }
+ dir.close();
+ }
}
Modified: lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java?rev=1682585&r1=1682584&r2=1682585&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java Sat May 30 07:19:39 2015
@@ -20,6 +20,8 @@ package org.apache.lucene.store;
import java.io.IOException;
import java.nio.file.Path;
+import org.apache.lucene.util.IOUtils;
+
/** Simple tests for SimpleFSLockFactory */
public class TestSimpleFSLockFactory extends BaseLockFactoryTestCase {
@@ -28,5 +30,28 @@ public class TestSimpleFSLockFactory ext
return newFSDirectory(path, SimpleFSLockFactory.INSTANCE);
}
- // TODO: specific tests to this impl
+ /** delete the lockfile and test ensureValid fails */
+ public void testDeleteLockFile() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+ Lock lock = dir.obtainLock("test.lock");
+ lock.ensureValid();
+
+ try {
+ dir.deleteFile("test.lock");
+ } catch (Exception e) {
+ // we can't delete a file for some reason, just clean up and assume the test.
+ IOUtils.closeWhileHandlingException(lock);
+ assumeNoException("test requires the ability to delete a locked file", e);
+ }
+
+ try {
+ lock.ensureValid();
+ fail("no exception");
+ } catch (IOException expected) {
+ // ok
+ } finally {
+ IOUtils.closeWhileHandlingException(lock);
+ }
+ dir.close();
+ }
}
Modified: lucene/dev/branches/lucene6508/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java?rev=1682585&r1=1682584&r2=1682585&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java (original)
+++ lucene/dev/branches/lucene6508/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java Sat May 30 07:19:39 2015
@@ -46,11 +46,11 @@ public abstract class BaseLockFactoryTes
* path, else it can ignore it. */
protected abstract Directory getDirectory(Path path) throws IOException;
+ /** Test obtaining and releasing locks, checking validity */
public void testBasics() throws IOException {
Directory dir = getDirectory(createTempDir());
Lock l = dir.obtainLock("commit");
- l.ensureValid();
try {
dir.obtainLock("commit");
fail("succeeded in obtaining lock twice, didn't get exception");
@@ -59,11 +59,47 @@ public abstract class BaseLockFactoryTes
// Make sure we can obtain first one again:
l = dir.obtainLock("commit");
- l.ensureValid();
l.close();
dir.close();
}
+
+ /** Test closing locks twice */
+ public void testDoubleClose() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+
+ Lock l = dir.obtainLock("commit");
+ l.close();
+ l.close(); // close again, should be no exception
+
+ dir.close();
+ }
+
+ /** Test ensureValid returns true after acquire */
+ public void testValidAfterAcquire() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+
+ Lock l = dir.obtainLock("commit");
+ l.ensureValid(); // no exception
+ l.close();
+
+ dir.close();
+ }
+
+ /** Test ensureValid throws exception after close */
+ public void testInvalidAfterClose() throws IOException {
+ Directory dir = getDirectory(createTempDir());
+
+ Lock l = dir.obtainLock("commit");
+ l.close();
+
+ try {
+ l.ensureValid();
+ fail("didn't get exception");
+ } catch (AlreadyClosedException expected) {}
+
+ dir.close();
+ }
public void testObtainConcurrently() throws InterruptedException, IOException {
final Directory directory = getDirectory(createTempDir());