Split up LocationTests that use StoreConnection.

By splitting LocationTests into those on the machinary and those related
to StoreConnection, the StoreConnection tests can be put in the
tdb/store package.  This breaks the package dependency on tdb/base/file
on tdb/store,.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/a6b5b55e
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/a6b5b55e
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/a6b5b55e

Branch: refs/heads/hadoop-rdf
Commit: a6b5b55e97f9b08a76f474c91acd5fe4a1168a60
Parents: 2e4c6c7
Author: Andy Seaborne <[email protected]>
Authored: Fri Jan 9 15:43:09 2015 +0000
Committer: Andy Seaborne <[email protected]>
Committed: Fri Jan 9 15:43:09 2015 +0000

----------------------------------------------------------------------
 .../jena/tdb/base/file/TestLocationLock.java    | 47 ----------
 .../com/hp/hpl/jena/tdb/store/TS_Store.java     |  1 +
 .../store/TestLocationLockStoreConnection.java  | 98 ++++++++++++++++++++
 3 files changed, 99 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/a6b5b55e/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/base/file/TestLocationLock.java
----------------------------------------------------------------------
diff --git 
a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/base/file/TestLocationLock.java 
b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/base/file/TestLocationLock.java
index 1ad2a6f..27e51d7 100644
--- a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/base/file/TestLocationLock.java
+++ b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/base/file/TestLocationLock.java
@@ -29,7 +29,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
-import com.hp.hpl.jena.tdb.StoreConnection;
 import com.hp.hpl.jena.tdb.TDBException;
 import com.hp.hpl.jena.tdb.sys.ProcessUtils;
 
@@ -98,28 +97,6 @@ public class TestLocationLock {
         Assert.assertFalse(lock.canObtain());
     }
 
-    @Test
-    public void location_lock_dir_03() {
-        Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
-        LocationLock lock = dir.getLock();
-        Assert.assertTrue(lock.canLock());
-        Assert.assertFalse(lock.isLocked());
-        Assert.assertFalse(lock.isOwned());
-        Assert.assertTrue(lock.canObtain());
-
-        // Creating a StoreConnection on the location will obtain the lock
-        StoreConnection.make(dir);
-        Assert.assertTrue(lock.isLocked());
-        Assert.assertTrue(lock.isOwned());
-        Assert.assertTrue(lock.canObtain());
-
-        // Releasing the connection releases the lock
-        StoreConnection.release(dir);
-        Assert.assertFalse(lock.isLocked());
-        Assert.assertFalse(lock.isOwned());
-        Assert.assertTrue(lock.canObtain());
-    }
-
     @Test(expected = TDBException.class)
     public void location_lock_dir_error_01() throws IOException {
         Assume.assumeTrue(negativePidsTreatedAsAlive);
@@ -168,28 +145,4 @@ public class TestLocationLock {
         Assert.assertFalse(lock.canObtain());
         lock.release();
     }
-
-    @Test(expected = TDBException.class)
-    public void location_lock_dir_error_03() throws IOException {
-        Assume.assumeTrue(negativePidsTreatedAsAlive);
-        
-        Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
-        LocationLock lock = dir.getLock();
-        Assert.assertTrue(lock.canLock());
-        Assert.assertFalse(lock.isLocked());
-        Assert.assertFalse(lock.isOwned());
-        Assert.assertTrue(lock.canObtain());
-
-        // Write a fake PID to the lock file
-        try(BufferedWriter writer = 
-            new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
-            // Fake PID that would never be valid
-            writer.write(Integer.toString(-1234)); 
-        }
-        Assert.assertTrue(lock.isLocked());
-        Assert.assertFalse(lock.isOwned());
-
-        // Attempting to create a connection on this location should error
-        StoreConnection.make(dir);
-    }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/a6b5b55e/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TS_Store.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TS_Store.java 
b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TS_Store.java
index 916f88b..4c6abc5 100644
--- a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TS_Store.java
+++ b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TS_Store.java
@@ -43,6 +43,7 @@ import com.hp.hpl.jena.tdb.sys.TestOps ;
     , TestDynamicDatasetTDB.class
     , TestStoreConnectionsDirect.class
     , TestStoreConnectionsMapped.class
+    , TestLocationLockStoreConnection.class
 } )
 public class TS_Store
 { 

http://git-wip-us.apache.org/repos/asf/jena/blob/a6b5b55e/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLocationLockStoreConnection.java
----------------------------------------------------------------------
diff --git 
a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLocationLockStoreConnection.java
 
b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLocationLockStoreConnection.java
new file mode 100644
index 0000000..0c3cc94
--- /dev/null
+++ 
b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestLocationLockStoreConnection.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hp.hpl.jena.tdb.store;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import com.hp.hpl.jena.tdb.StoreConnection;
+import com.hp.hpl.jena.tdb.TDBException;
+import com.hp.hpl.jena.tdb.base.file.Location ;
+import com.hp.hpl.jena.tdb.base.file.LocationLock ;
+import com.hp.hpl.jena.tdb.sys.ProcessUtils;
+
+/**
+ * Tests for {@link LocationLock} inconjucntion with {@link StoreConnection}s 
+ */
+public class TestLocationLockStoreConnection {
+
+    private static boolean negativePidsTreatedAsAlive = false;
+    
+    @Rule
+    public TemporaryFolder tempDir = new TemporaryFolder();
+    
+    @BeforeClass
+    public static void setup() {
+        negativePidsTreatedAsAlive = ProcessUtils.negativePidsTreatedAsAlive();
+    }
+    
+    @Test
+    public void location_lock_store_connection_01() {
+        Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
+        LocationLock lock = dir.getLock();
+        Assert.assertTrue(lock.canLock());
+        Assert.assertFalse(lock.isLocked());
+        Assert.assertFalse(lock.isOwned());
+        Assert.assertTrue(lock.canObtain());
+
+        // Creating a StoreConnection on the location will obtain the lock
+        StoreConnection.make(dir);
+        Assert.assertTrue(lock.isLocked());
+        Assert.assertTrue(lock.isOwned());
+        Assert.assertTrue(lock.canObtain());
+
+        // Releasing the connection releases the lock
+        StoreConnection.release(dir);
+        Assert.assertFalse(lock.isLocked());
+        Assert.assertFalse(lock.isOwned());
+        Assert.assertTrue(lock.canObtain());
+    }
+
+    @Test(expected = TDBException.class)
+    public void location_lock_store_connection_02() throws IOException {
+        Assume.assumeTrue(negativePidsTreatedAsAlive);
+        
+        Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
+        LocationLock lock = dir.getLock();
+        Assert.assertTrue(lock.canLock());
+        Assert.assertFalse(lock.isLocked());
+        Assert.assertFalse(lock.isOwned());
+        Assert.assertTrue(lock.canObtain());
+
+        // Write a fake PID to the lock file
+        try(BufferedWriter writer = 
+            new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) {
+            // Fake PID that would never be valid
+            writer.write(Integer.toString(-1234)); 
+        }
+        Assert.assertTrue(lock.isLocked());
+        Assert.assertFalse(lock.isOwned());
+
+        // Attempting to create a connection on this location should error
+        StoreConnection.make(dir);
+    }
+}

Reply via email to