You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2017/10/27 19:42:09 UTC
[01/10] jena git commit: JENA-1406 use JUnit temp folder rule to
create DB dir
Repository: jena
Updated Branches:
refs/heads/master 48e0521c5 -> 92c793b67
JENA-1406 use JUnit temp folder rule to create DB dir
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8587fb58
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8587fb58
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8587fb58
Branch: refs/heads/master
Commit: 8587fb58a5d22c0b081eb5a167f06945c2d194ed
Parents: 8b9f587
Author: Bruno P. Kinoshita <br...@yahoo.com.br>
Authored: Thu Oct 26 21:22:54 2017 +1300
Committer: Bruno P. Kinoshita <br...@yahoo.com.br>
Committed: Thu Oct 26 21:22:54 2017 +1300
----------------------------------------------------------------------
.../apache/jena/tdb2/sys/TestDatabaseOps.java | 24 ++++++++++++--------
1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/8587fb58/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseOps.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseOps.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseOps.java
index 9956257..56a3fb0 100644
--- a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseOps.java
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseOps.java
@@ -33,7 +33,6 @@ import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.sparql.core.DatasetGraph ;
import org.apache.jena.sparql.core.Quad ;
import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.tdb2.ConfigTest;
import org.apache.jena.tdb2.DatabaseMgr;
import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
import org.apache.jena.tdb2.store.DatasetGraphTDB;
@@ -42,12 +41,16 @@ import org.apache.jena.tdb2.sys.StoreConnection;
import org.apache.jena.tdb2.sys.TDBInternal;
import org.junit.After ;
import org.junit.Before ;
+import org.junit.Rule;
import org.junit.Test ;
+import org.junit.rules.TemporaryFolder;
public class TestDatabaseOps
{
- static String DIRx = ConfigTest.getCleanDir() ;
- static Location DIR = Location.create(DIRx);
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ private Location dir = null;
static Quad quad1 = SSE.parseQuad("(_ <s> <p> 1)") ;
static Quad quad2 = SSE.parseQuad("(_ _:a <p> 2)") ;
@@ -57,18 +60,19 @@ public class TestDatabaseOps
@Before
public void before() {
- FileUtils.deleteQuietly(IOX.asFile(DIR));
- FileOps.ensureDir(DIR.getDirectoryPath());
+ dir = Location.create(tempFolder.toString());
+ FileUtils.deleteQuietly(IOX.asFile(dir));
+ FileOps.ensureDir(dir.getDirectoryPath());
}
@After
public void after() {
TDBInternal.reset();
- FileUtils.deleteQuietly(IOX.asFile(DIR));
+ FileUtils.deleteQuietly(IOX.asFile(dir));
}
@Test public void compact_dsg_1() {
- DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(DIR);
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable)dsg;
DatasetGraph dsg1 = dsgs.get();
Location loc1 = ((DatasetGraphTDB)dsg1).getLocation();
@@ -102,7 +106,7 @@ public class TestDatabaseOps
@Test public void compact_graph_2() {
// graphs across compaction.
- DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(DIR);
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
Graph g = dsg.getDefaultGraph();
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable)dsg;
@@ -131,7 +135,7 @@ public class TestDatabaseOps
@Test public void compact_prefixes_3() {
// prefixes axcross compaction.
- DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(DIR);
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
Graph g = dsg.getDefaultGraph();
Txn.executeWrite(dsg, ()-> g.getPrefixMapping().setNsPrefix("ex", "http://example/") );
@@ -157,7 +161,7 @@ public class TestDatabaseOps
}
@Test public void backup_1() {
- DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(DIR);
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
Txn.executeWrite(dsg, ()-> {
dsg.add(quad2) ;
dsg.add(quad1) ;
[02/10] jena git commit: Make surefire run TC_*
Posted by an...@apache.org.
Make surefire run TC_*
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e68daeab
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e68daeab
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e68daeab
Branch: refs/heads/master
Commit: e68daeab353c7a60ac4adba7416aeb2722c317e7
Parents: 8b9f587
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Oct 26 13:15:07 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Oct 26 13:15:07 2017 +0100
----------------------------------------------------------------------
jena-db/jena-dboe-base/pom.xml | 12 ++++++++++++
jena-db/jena-dboe-trans-data/pom.xml | 15 ++++++++++++++-
jena-db/jena-tdb2/pom.xml | 15 +++++++++++++++
3 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/e68daeab/jena-db/jena-dboe-base/pom.xml
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/pom.xml b/jena-db/jena-dboe-base/pom.xml
index 9204635..e97d171 100644
--- a/jena-db/jena-dboe-base/pom.xml
+++ b/jena-db/jena-dboe-base/pom.xml
@@ -50,6 +50,17 @@
<build>
<plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/TC_*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -61,6 +72,7 @@
</execution>
</executions>
</plugin>
+
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/jena/blob/e68daeab/jena-db/jena-dboe-trans-data/pom.xml
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/pom.xml b/jena-db/jena-dboe-trans-data/pom.xml
index f38c489..21dd7be 100644
--- a/jena-db/jena-dboe-trans-data/pom.xml
+++ b/jena-db/jena-dboe-trans-data/pom.xml
@@ -57,8 +57,21 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
-
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/TC_*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/e68daeab/jena-db/jena-tdb2/pom.xml
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/pom.xml b/jena-db/jena-tdb2/pom.xml
index 833702c..f996db6 100644
--- a/jena-db/jena-tdb2/pom.xml
+++ b/jena-db/jena-tdb2/pom.xml
@@ -65,4 +65,19 @@
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/TC_*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
</project>
[10/10] jena git commit: JENA-1407: Execute tests with multiple
threads.
Posted by an...@apache.org.
JENA-1407: Execute tests with multiple threads.
Changes taken from PR#297.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/92c793b6
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/92c793b6
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/92c793b6
Branch: refs/heads/master
Commit: 92c793b67dbb4138858106774d57b23418dd4ae5
Parents: 87977a9
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 20:41:20 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 20:41:43 2017 +0100
----------------------------------------------------------------------
jena-elephas/jena-elephas-io/pom.xml | 10 +++++++++-
.../jena/hadoop/rdf/io/input/turtle/TurtleInputTest.java | 3 ++-
2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/92c793b6/jena-elephas/jena-elephas-io/pom.xml
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/pom.xml b/jena-elephas/jena-elephas-io/pom.xml
index 9553f02..85d9937 100644
--- a/jena-elephas/jena-elephas-io/pom.xml
+++ b/jena-elephas/jena-elephas-io/pom.xml
@@ -67,7 +67,7 @@
</dependency>
</dependencies>
- <build>
+ <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -87,6 +87,14 @@
</links>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <parallel>classes</parallel>
+ <threadCount>2</threadCount>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/92c793b6/jena-elephas/jena-elephas-io/src/test/java/org/apache/jena/hadoop/rdf/io/input/turtle/TurtleInputTest.java
----------------------------------------------------------------------
diff --git a/jena-elephas/jena-elephas-io/src/test/java/org/apache/jena/hadoop/rdf/io/input/turtle/TurtleInputTest.java b/jena-elephas/jena-elephas-io/src/test/java/org/apache/jena/hadoop/rdf/io/input/turtle/TurtleInputTest.java
index b8a9462..231e459 100644
--- a/jena-elephas/jena-elephas-io/src/test/java/org/apache/jena/hadoop/rdf/io/input/turtle/TurtleInputTest.java
+++ b/jena-elephas/jena-elephas-io/src/test/java/org/apache/jena/hadoop/rdf/io/input/turtle/TurtleInputTest.java
@@ -61,7 +61,8 @@ public class TurtleInputTest extends AbstractWholeFileTripleInputFormatTests {
// Try to reproduce JENA-1075
// Create test data
- File f = new File("target/prefixes.ttl");
+ File f = folder.newFile("prefixes.ttl");
+
try (FileWriter writer = new FileWriter(f)) {
//@formatter:off
writer.write(StrUtils.strjoinNL("@prefix : <http://test/ns#> .",
[06/10] jena git commit: JENA-1406: Merge commit 'refs/pull/295/head'
of github.com:apache/jena
Posted by an...@apache.org.
JENA-1406: Merge commit 'refs/pull/295/head' of github.com:apache/jena
This closes #296.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e823da61
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e823da61
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e823da61
Branch: refs/heads/master
Commit: e823da618945583153a661ae9dcc114e8f360994
Parents: 48e0521 8587fb5
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 15:53:07 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 15:53:07 2017 +0100
----------------------------------------------------------------------
.../apache/jena/tdb2/sys/TestDatabaseOps.java | 24 ++++++++++++--------
1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
[08/10] jena git commit: Revert "Check .delete() in beforeTest"
Posted by an...@apache.org.
Revert "Check .delete() in beforeTest"
This reverts commit 10441d7f819f9dc9b4ed5191e28821e04a1e0cb1.
PR#298 has a better solution.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8f9f0c9a
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8f9f0c9a
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8f9f0c9a
Branch: refs/heads/master
Commit: 8f9f0c9a3ffaa0aa3910391c910a97feb461364a
Parents: 40eb4df
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 15:59:33 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 15:59:33 2017 +0100
----------------------------------------------------------------------
.../jena/dboe/base/file/TestProcessFileLock.java | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/8f9f0c9a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java b/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
index d434a89..9c72c71 100644
--- a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
+++ b/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
@@ -18,18 +18,17 @@
package org.apache.jena.dboe.base.file;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
-import org.apache.jena.atlas.RuntimeIOException;
-import org.apache.jena.atlas.io.IO;
import org.apache.jena.atlas.lib.FileOps;
+import org.apache.jena.dboe.base.file.AlreadyLocked;
+import org.apache.jena.dboe.base.file.ProcessFileLock;
import org.apache.jena.dboe.sys.Names;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -41,6 +40,7 @@ public class TestProcessFileLock {
private static final String DIR = "target/locktest";
private static final String lockfile = DIR+"/"+Names.TDB_LOCK_FILE;
+
@BeforeClass public static void beforeClass() {
FileOps.ensureDir(DIR);
}
@@ -48,14 +48,12 @@ public class TestProcessFileLock {
@Before public void beforeTest() {
File f = new File(lockfile);
try {
- if ( FileOps.exists(lockfile) ) {
- boolean b = f.delete();
- if ( !b )
- throw new RuntimeIOException("Failed to delete "+lockfile);
- }
+ f.delete();
f.createNewFile();
}
- catch (IOException e) { IO.exception(e); }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
}
@Test public void process_lock_1() {
[09/10] jena git commit: JENA-1409: Merge commit 'refs/pull/298/head'
of github.com:apache/jena
Posted by an...@apache.org.
JENA-1409: Merge commit 'refs/pull/298/head' of github.com:apache/jena
cc: JENA-1406
This closes #298.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/87977a97
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/87977a97
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/87977a97
Branch: refs/heads/master
Commit: 87977a977fa31f270288e138650e19e570b53143
Parents: 8f9f0c9 fc2a7457
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 16:11:29 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 16:11:29 2017 +0100
----------------------------------------------------------------------
.../jena/dboe/base/file/ProcessFileLock.java | 86 +++++++++++++++-----
.../dboe/base/file/TestProcessFileLock.java | 30 +++----
2 files changed, 78 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
[04/10] jena git commit: Close files when a lock is released.
Posted by an...@apache.org.
Close files when a lock is released.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/057ed908
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/057ed908
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/057ed908
Branch: refs/heads/master
Commit: 057ed9084a47900cd2c8f20571aa7f0216c05c9a
Parents: 48e0521
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 12:53:41 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 12:53:41 2017 +0100
----------------------------------------------------------------------
.../jena/dboe/base/file/ProcessFileLock.java | 86 +++++++++++++++-----
1 file changed, 65 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/057ed908/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/base/file/ProcessFileLock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/base/file/ProcessFileLock.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/base/file/ProcessFileLock.java
index e945df0..97feb14 100644
--- a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/base/file/ProcessFileLock.java
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/base/file/ProcessFileLock.java
@@ -40,16 +40,30 @@ import org.apache.jena.atlas.logging.Log;
import org.apache.jena.dboe.DBOpEnvException;
import org.apache.jena.dboe.sys.ProcessUtils;
-/** A simple packaging around a {@link java.nio.channels.FileLock}.
- * {@code ProcessFileLock} are not reentrant.
+/** A simple packaging around a {@link java.nio.channels.FileLock}.
+ * <p>
+ * {@code ProcessFileLock}s are not reentrant locks.
+ * <p>
+ * See {@link #create} and {@link #release} to obtain and stop using a {@code ProcessFileLock}.
*/
public class ProcessFileLock {
-
// Static (process-wide) sync.
private static Object sync = new Object();
// Map from path of the file to a ProcessFileLock
private static ConcurrentHashMap<Path, ProcessFileLock> locks = new ConcurrentHashMap<>();
+ /*package-testing*/ static void clearLocksProcessState() {
+ synchronized(sync) {
+ try {
+ locks.forEach((path,lock)->lock.free());
+ locks.clear();
+ }
+ catch (Exception ex) {
+ // Shouldn't happen - trace and then ignore.
+ ex.printStackTrace();
+ }
+ }
+ }
private final Path filepath;
private final FileChannel fileChannel;
@@ -73,10 +87,10 @@ public class ProcessFileLock {
public static void release(ProcessFileLock lockFile) {
if ( lockFile == null )
return ;
- if ( lockFile.isLockedHere() )
- lockFile.unlock();
locks.remove(lockFile.getPath());
+ lockFile.free();
}
+
/** Create the structure for a ProcessFileLock on file {@code filename}.
* This does not take the lock
*
@@ -92,7 +106,7 @@ public class ProcessFileLock {
// fileChannel = randomAccessFile.getChannel();
// Quite heavy weight but only used to lock long-term objects.
this.fileChannel = FileChannel.open(filename, CREATE, WRITE, READ, DSYNC);
- fileLock = null;
+ this.fileLock = null;
}
catch (NoSuchFileException | FileNotFoundException ex) {
// The path does not name a possible file in an exists directory.
@@ -103,24 +117,37 @@ public class ProcessFileLock {
}
}
- /** Lock the file or throw {@link DBOpEnvException} */
+ /** Lock the file or throw {@link DBOpEnvException}.
+ *
+ * @throws AlreadyLocked if the lock is already held by this process.
+ */
public void lockEx() {
lockOperation(NoLockAction.EXCEPTION);
}
- /** Lock the file or wait. */
+ /** Lock the file or wait.
+ *
+ * @throws AlreadyLocked if the lock is already held by this process.
+ */
public void lockWait() {
- lockOperation(NoLockAction.EXCEPTION);
+ lockOperation(NoLockAction.WAIT);
}
- /** Lock a file, return true on success else false. */
+ /** Lock a file, return true on success else false.
+ *
+ * @throws AlreadyLocked if the lock is already held by this process.
+ */
public boolean tryLock() {
return lockOperation(NoLockAction.RETURN);
}
- /** Release the lock - this must be paired with a "lock" operation. */
+ /** Release the lock - this must be paired with a "lock" operation.
+ * @throws IllegalStateException if the lock is not held by this process.
+ */
public void unlock() {
synchronized(sync) {
+ if ( fileLock == null )
+ throw new IllegalStateException("unlock not paired with a lock call");
try {
fileLock.release();
} catch (IOException ex) { throw new RuntimeIOException("Failed to unlock '"+filepath+"'", ex); }
@@ -138,6 +165,16 @@ public class ProcessFileLock {
return filepath;
}
+ // Release ProcessFileLock. Applications use ProcessFileLock.release(lock)
+ private void free() {
+ try {
+ if ( fileLock != null )
+ fileLock.release();
+ fileChannel.close();
+ fileLock = null;
+ } catch (IOException ex) { IO.exception(ex); }
+ }
+
/** Take the lock.
* <p>
* Write our PID into the file and return true if it succeeds.
@@ -150,16 +187,23 @@ public class ProcessFileLock {
throw new AlreadyLocked("Failed to get a lock: file='"+filepath+"': Lock already held");
try {
- fileLock = (action == NoLockAction.WAIT) ? fileChannel.lock() : fileChannel.tryLock();
+ fileLock = (action != NoLockAction.WAIT) ? fileChannel.tryLock() : fileChannel.lock();
if ( fileLock == null ) {
- if ( action == NoLockAction.RETURN )
- return false ;
- // Read without the lock.
- // This isn't perfect but it is only providing helpful information.
- int pid = readProcessId(-99);
- if ( pid >= 0 )
- throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"': held by process "+pid);
- throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"': failed to get the holder's process id");
+ switch(action) {
+ case EXCEPTION: {
+ // Read without the lock.
+ // This isn't perfect (synchronization issues across multiple processes)
+ // but it is only providing helpful information.
+ int pid = readProcessId(-99);
+ if ( pid >= 0 )
+ throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"': held by process "+pid);
+ throw new DBOpEnvException("Failed to get a lock: file='"+filepath+"': failed to get the holder's process id");
+ }
+ case RETURN:
+ return false ;
+ case WAIT:
+ throw new InternalError("FileChannel.lock returned null");
+ }
}
// Got the lock. Record our process id.
int pid = ProcessUtils.getPid(-1);
@@ -192,7 +236,7 @@ public class ProcessFileLock {
bb.get(b);
String pidStr = StrUtils.fromUTF8bytes(b);
- // Remove all leadign and trailing (vertical and horizontal) whitespace.
+ // Remove all leading and trailing (vertical and horizontal) whitespace.
pidStr = pidStr.replaceAll("[\\s\\t\\n\\r]+$", "");
pidStr = pidStr.replaceAll("^[\\s\\t\\n\\r]+", "");
try {
[03/10] jena git commit: Check .delete() in beforeTest
Posted by an...@apache.org.
Check .delete() in beforeTest
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/10441d7f
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/10441d7f
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/10441d7f
Branch: refs/heads/master
Commit: 10441d7f819f9dc9b4ed5191e28821e04a1e0cb1
Parents: e68daea
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Oct 26 13:15:10 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Oct 26 13:15:46 2017 +0100
----------------------------------------------------------------------
.../jena/dboe/base/file/TestProcessFileLock.java | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/10441d7f/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java b/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
index 9c72c71..d434a89 100644
--- a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
+++ b/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
@@ -18,17 +18,18 @@
package org.apache.jena.dboe.base.file;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
+import org.apache.jena.atlas.RuntimeIOException;
+import org.apache.jena.atlas.io.IO;
import org.apache.jena.atlas.lib.FileOps;
-import org.apache.jena.dboe.base.file.AlreadyLocked;
-import org.apache.jena.dboe.base.file.ProcessFileLock;
import org.apache.jena.dboe.sys.Names;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -40,7 +41,6 @@ public class TestProcessFileLock {
private static final String DIR = "target/locktest";
private static final String lockfile = DIR+"/"+Names.TDB_LOCK_FILE;
-
@BeforeClass public static void beforeClass() {
FileOps.ensureDir(DIR);
}
@@ -48,12 +48,14 @@ public class TestProcessFileLock {
@Before public void beforeTest() {
File f = new File(lockfile);
try {
- f.delete();
+ if ( FileOps.exists(lockfile) ) {
+ boolean b = f.delete();
+ if ( !b )
+ throw new RuntimeIOException("Failed to delete "+lockfile);
+ }
f.createNewFile();
}
- catch (IOException e) {
- e.printStackTrace();
- }
+ catch (IOException e) { IO.exception(e); }
}
@Test public void process_lock_1() {
[07/10] jena git commit: JENA-1409: Merge commit 'refs/pull/296/head'
of github.com:apache/jena
Posted by an...@apache.org.
JENA-1409: Merge commit 'refs/pull/296/head' of github.com:apache/jena
cc JENA-1406
This closes #296.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/40eb4df3
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/40eb4df3
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/40eb4df3
Branch: refs/heads/master
Commit: 40eb4df3f1b08d30764e6a5e921bfec54d514149
Parents: e823da6 10441d7
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 15:54:54 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 15:54:54 2017 +0100
----------------------------------------------------------------------
jena-db/jena-dboe-base/pom.xml | 12 ++++++++++++
.../jena/dboe/base/file/TestProcessFileLock.java | 18 ++++++++++--------
jena-db/jena-dboe-trans-data/pom.xml | 15 ++++++++++++++-
jena-db/jena-tdb2/pom.xml | 15 +++++++++++++++
4 files changed, 51 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
[05/10] jena git commit: Isolate tests after observed problems on
MSWindows.
Posted by an...@apache.org.
Isolate tests after observed problems on MSWindows.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/fc2a7457
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/fc2a7457
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/fc2a7457
Branch: refs/heads/master
Commit: fc2a7457f5c22a7a271c605f92d6fa315f3a9d98
Parents: 057ed90
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 27 12:59:17 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 27 13:35:49 2017 +0100
----------------------------------------------------------------------
.../dboe/base/file/TestProcessFileLock.java | 30 +++++++++-----------
1 file changed, 13 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/fc2a7457/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java b/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
index 9c72c71..0f9e24b 100644
--- a/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
+++ b/jena-db/jena-dboe-base/src/test/java/org/apache/jena/dboe/base/file/TestProcessFileLock.java
@@ -18,44 +18,40 @@
package org.apache.jena.dboe.base.file;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
-import org.apache.jena.atlas.lib.FileOps;
-import org.apache.jena.dboe.base.file.AlreadyLocked;
-import org.apache.jena.dboe.base.file.ProcessFileLock;
+import org.apache.jena.atlas.io.IO;
import org.apache.jena.dboe.sys.Names;
import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
public class TestProcessFileLock {
- // TestLocationLockStoreConnection
- private static final String DIR = "target/locktest";
- private static final String lockfile = DIR+"/"+Names.TDB_LOCK_FILE;
+ private String lockfile;
-
- @BeforeClass public static void beforeClass() {
- FileOps.ensureDir(DIR);
- }
+ //Using a per-test rule is "doubly-safe" because we clear the process state.
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
@Before public void beforeTest() {
- File f = new File(lockfile);
try {
- f.delete();
- f.createNewFile();
+ File f = tempFolder.newFile(Names.TDB_LOCK_FILE);
+ lockfile = f.getCanonicalPath();
}
catch (IOException e) {
- e.printStackTrace();
+ IO.exception(e);
}
}
-
+
@Test public void process_lock_1() {
ProcessFileLock lock = ProcessFileLock.create(lockfile);
String fn = new File(lockfile).getAbsolutePath();