From 0a161380f8e171b386b30960d274b4ba21439599 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Wed, 8 Apr 2015 10:28:40 -0400 Subject: [PATCH] AMQ-5709 Fixing tests https://issues.apache.org/jira/browse/AMQ-5709 This is just fixing a test properly --- .../activemq/store/SharedFileLocker.java | 1 - .../activemq/store/SharedFileLockerTest.java | 37 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) 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 a5432aa02d..66c70e2096 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) 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 d8700c0b43..623443fbbc 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())