You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2015/03/05 14:26:41 UTC
[1/2] activemq git commit:
https://issues.apache.org/jira/browse/AMQ-5568 - fix and test - only delete
lock file if lock was held on stop
Repository: activemq
Updated Branches:
refs/heads/master 00e4b2535 -> 8c66fba0a
https://issues.apache.org/jira/browse/AMQ-5568 - fix and test - only delete lock file if lock was held on stop
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/8c66fba0
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/8c66fba0
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/8c66fba0
Branch: refs/heads/master
Commit: 8c66fba0aab96a5f842b52b634690a8bff0b03b3
Parents: 113a381
Author: gtully <ga...@gmail.com>
Authored: Thu Mar 5 13:22:58 2015 +0000
Committer: gtully <ga...@gmail.com>
Committed: Thu Mar 5 13:27:40 2015 +0000
----------------------------------------------------------------------
.../java/org/apache/activemq/util/LockFile.java | 7 +-
.../org/apache/activemq/util/LockFileTest.java | 67 ++++++++++++++++++++
2 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/8c66fba0/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java b/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java
index 7fc4648..299fb4b 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java
@@ -37,6 +37,7 @@ public class LockFile {
private RandomAccessFile readFile;
private int lockCounter;
private final boolean deleteOnUnlock;
+ private volatile boolean locked;
public LockFile(File file, boolean deleteOnUnlock) {
this.file = file;
@@ -76,6 +77,7 @@ public class LockFile {
if (lock != null) {
lockCounter++;
System.setProperty(getVmLockKey(), new Date().toString());
+ locked = true;
} else {
// new read file for next attempt
closeReadFile();
@@ -118,7 +120,7 @@ public class LockFile {
}
closeReadFile();
- if (deleteOnUnlock) {
+ if (locked && deleteOnUnlock) {
file.delete();
}
}
@@ -140,7 +142,8 @@ public class LockFile {
}
public boolean keepAlive() {
- return lock != null && lock.isValid() && file.exists();
+ locked = locked && lock != null && lock.isValid() && file.exists();
+ return locked;
}
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/8c66fba0/activemq-broker/src/test/java/org/apache/activemq/util/LockFileTest.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/test/java/org/apache/activemq/util/LockFileTest.java b/activemq-broker/src/test/java/org/apache/activemq/util/LockFileTest.java
new file mode 100644
index 0000000..d377ae1
--- /dev/null
+++ b/activemq-broker/src/test/java/org/apache/activemq/util/LockFileTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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 org.apache.activemq.util;
+
+import java.io.File;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class LockFileTest {
+
+ @Test
+ public void testNoDeleteOnUnlockIfNotLocked() throws Exception {
+
+ File lockFile = new File(IOHelper.getDefaultDataDirectory(), "lockToTest1");
+ lockFile.createNewFile();
+
+ LockFile underTest = new LockFile(lockFile, true);
+
+ underTest.lock();
+
+ lockFile.delete();
+
+ assertFalse("no longer valid", underTest.keepAlive());
+
+ // a slave gets in
+ lockFile.createNewFile();
+
+ underTest.unlock();
+
+ assertTrue("file still exists after unlock when not locked", lockFile.exists());
+
+ }
+
+ @Test
+ public void testDeleteOnUnlockIfLocked() throws Exception {
+
+ File lockFile = new File(IOHelper.getDefaultDataDirectory(), "lockToTest2");
+ lockFile.createNewFile();
+
+ LockFile underTest = new LockFile(lockFile, true);
+
+ underTest.lock();
+
+ assertTrue("valid", underTest.keepAlive());
+
+ underTest.unlock();
+
+ assertFalse("file deleted on unlock", lockFile.exists());
+
+ }
+}
[2/2] activemq git commit: remove deprecated usage of junit framework
Posted by gt...@apache.org.
remove deprecated usage of junit framework
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/113a3815
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/113a3815
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/113a3815
Branch: refs/heads/master
Commit: 113a3815b0fef93ccf9b2dcf7ccf9f196e182f0d
Parents: 00e4b25
Author: gtully <ga...@gmail.com>
Authored: Thu Mar 5 13:21:22 2015 +0000
Committer: gtully <ga...@gmail.com>
Committed: Thu Mar 5 13:27:40 2015 +0000
----------------------------------------------------------------------
.../apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/113a3815/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
index e95bcbd..6ad2f03 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
@@ -37,8 +37,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Test to see if the JDBCExceptionIOHandler will restart the transport connectors correctly after