activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq git commit: AMQ-5709 Fixing tests
Date Wed, 08 Apr 2015 14:38:06 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 89c75ca28 -> f2837bac0


AMQ-5709 Fixing tests

https://issues.apache.org/jira/browse/AMQ-5709

This is just fixing a test properly


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

Branch: refs/heads/master
Commit: 0a161380f8e171b386b30960d274b4ba21439599
Parents: 89c75ca
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Wed Apr 8 10:28:40 2015 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Wed Apr 8 10:28:42 2015 -0400

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


http://git-wip-us.apache.org/repos/asf/activemq/blob/0a161380/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 a5432aa..66c70e2 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
@@ -55,7 +55,6 @@ public class SharedFileLocker extends AbstractLocker {
                     try {
                         lockFile.lock();
                         locked = keepAlive();
-                        LOG.info("locked " + locked);
                         break;
                     } catch (IOException e) {
                         if (!warned)

http://git-wip-us.apache.org/repos/asf/activemq/blob/0a161380/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 d8700c0..623443f 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
@@ -20,6 +20,10 @@ package org.apache.activemq.store;
 import java.io.File;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.activemq.util.DefaultTestAppender;
+import org.apache.activemq.util.IOHelper;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggingEvent;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
@@ -28,11 +32,32 @@ import org.junit.rules.TemporaryFolder;
 public class SharedFileLockerTest
 {
    @Rule
-   public TemporaryFolder testFolder = new TemporaryFolder();
+   public TemporaryFolder testFolder;
+
+
+   public SharedFileLockerTest()
+   {
+      File file = new File(IOHelper.getDefaultDataDirectory());
+      file.mkdir();
+
+      // TemporaryFolder will make sure the files are removed after the test is done
+      testFolder = new TemporaryFolder(file);
+
+   }
 
    @Test
-   public void testLock() throws Exception
+   public void testLogging() throws Exception
    {
+      final AtomicInteger logCounts = new AtomicInteger(0);
+      DefaultTestAppender appender = new DefaultTestAppender() {
+         @Override
+         public void doAppend(LoggingEvent event) {
+            logCounts.incrementAndGet();
+         }
+      };
+
+      Logger.getRootLogger().addAppender(appender);
+
       final AtomicInteger errors = new AtomicInteger(0);
 
       Thread thread = null;
@@ -80,6 +105,8 @@ public class SharedFileLockerTest
          // 10 seconds here is an eternity, but it should only take milliseconds
          thread.join(5000);
 
+         Assert.assertEquals("Extra logs in place", 1, logCounts.get());
+
          long timeout = System.currentTimeMillis() + 5000;
 
          while (timeout > System.currentTimeMillis() && !locker2.keepAlive())
@@ -91,9 +118,15 @@ public class SharedFileLockerTest
 
          locker2.stop();
 
+         Assert.assertEquals(0, errors.get());
+
       }
       finally
       {
+
+
+         Logger.getRootLogger().removeAppender(appender);
+
          // to make sure we won't leak threads if the test ever failed for any reason
          thread.join(1000);
          if (thread.isAlive())


Mime
View raw message