activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject activemq git commit: fixing a race on SharedLockFile
Date Wed, 08 Apr 2015 15:57:25 GMT
Repository: activemq
Updated Branches:
  refs/heads/master f2837bac0 -> ab8f54b06


fixing a race on SharedLockFile


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

Branch: refs/heads/master
Commit: ab8f54b0661755a3b5d8afbd18341e15ab4fe38c
Parents: f2837ba
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Wed Apr 8 11:14:21 2015 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Wed Apr 8 11:17:00 2015 -0400

----------------------------------------------------------------------
 .../apache/activemq/store/SharedFileLocker.java |  2 +-
 .../activemq/store/SharedFileLockerTest.java    | 38 +++++++++++++++++---
 2 files changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/ab8f54b0/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java
b/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java
index 66c70e2..36ebe62 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/store/SharedFileLocker.java
@@ -44,7 +44,7 @@ public class SharedFileLocker extends AbstractLocker {
     public void doStart() throws Exception {
         if (lockFile == null) {
             File lockFileName = new File(directory, "lock");
-            lockFile = new LockFile(lockFileName, true);
+            lockFile = new LockFile(lockFileName, false);
             if (failIfLocked) {
                 lockFile.lock();
             } else {

http://git-wip-us.apache.org/repos/asf/activemq/blob/ab8f54b0/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java
index 623443f..ba768c0 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/SharedFileLockerTest.java
@@ -46,8 +46,27 @@ public class SharedFileLockerTest
    }
 
    @Test
+   public void testLoop() throws Exception
+   {
+      // Increase the number of iterations if you are debugging races
+      for (int i = 0 ; i < 100; i++)
+      {
+         internalLoop(5);
+      }
+
+   }
+
+
+   @Test
    public void testLogging() throws Exception
    {
+      // using a bigger wait here
+      // to make sure we won't log any extra info
+      internalLoop(100);
+   }
+
+   private void internalLoop(long timewait) throws Exception
+   {
       final AtomicInteger logCounts = new AtomicInteger(0);
       DefaultTestAppender appender = new DefaultTestAppender() {
          @Override
@@ -76,8 +95,6 @@ public class SharedFileLockerTest
 
          Assert.assertTrue(locker1.keepAlive());
 
-         Thread.sleep(10);
-
          thread = new Thread("Locker Thread")
          {
             public void run()
@@ -95,8 +112,21 @@ public class SharedFileLockerTest
 
          thread.start();
 
-         // Waiting some small time here, you shouldn't see many messages
-         Thread.sleep(100);
+         // I need to make sure the info was already logged
+         // but I don't want to have an unecessary wait here,
+         // as I want the test to run as fast as possible
+         {
+            long timeout = System.currentTimeMillis() + 5000;
+            while (logCounts.get() < 1 && System.currentTimeMillis() < timeout)
+            {
+               Thread.sleep(1);
+            }
+         }
+
+         if (timewait > 0)
+         {
+            Thread.sleep(timewait);
+         }
 
          Assert.assertTrue(thread.isAlive());
 


Mime
View raw message