You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/05/21 08:17:19 UTC
svn commit: r1596486 -
/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/BurstFilterTest.java
Author: mattsicker
Date: Wed May 21 06:17:18 2014
New Revision: 1596486
URL: http://svn.apache.org/r1596486
Log:
Refactor test to use ILC.
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/BurstFilterTest.java
Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/BurstFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/BurstFilterTest.java?rev=1596486&r1=1596485&r2=1596486&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/BurstFilterTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/BurstFilterTest.java Wed May 21 06:17:18 2014
@@ -18,16 +18,12 @@
package org.apache.logging.log4j.core.filter;
import java.util.List;
-import java.util.Map;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.BeforeClass;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -38,26 +34,20 @@ public class BurstFilterTest {
private static final String CONFIG = "log4j-burst.xml";
- private static Configuration config;
- private static ListAppender app;
- private static BurstFilter filter;
- private static LoggerContext ctx;
-
- @BeforeClass
- public static void setupClass() {
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
- ctx = (LoggerContext) LogManager.getContext(false);
- config = ctx.getConfiguration();
- for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
- if (entry.getKey().equals("ListAppender")) {
- app = (ListAppender) entry.getValue();
- filter = (BurstFilter) app.getFilter();
- break;
- }
- }
+ @ClassRule
+ public static InitialLoggerContext context = new InitialLoggerContext(CONFIG);
+
+ @Before
+ public void setUp() throws Exception {
+ app = context.getListAppender("ListAppender");
+ filter = (BurstFilter) app.getFilter();
+ assertNotNull("No BurstFilter", filter);
}
- private final Logger logger = LogManager.getLogger(BurstFilterTest.class.getName());
+ private ListAppender app;
+ private BurstFilter filter;
+
+ private final Logger logger = context.getLogger();
/**
* Test BurstFilter by surpassing maximum number of log messages allowed by filter and
@@ -66,8 +56,6 @@ public class BurstFilterTest {
*/
@Test
public void test() throws Exception {
- assertNotNull("No ListAppender", app);
- assertNotNull("No BurstFilter", filter);
// exceed the burst limit and make sure no more than 100 errors get logged
final long start = System.nanoTime();
for (int i = 0; i < 110; i++) {
@@ -78,7 +66,7 @@ public class BurstFilterTest {
assertTrue("Incorrect number of available slots", filter.getAvailable() < 100);
}
List<String> msgs = app.getMessages();
- assertTrue("Incorrect message count. Should be 100, actual " + msgs.size(), msgs.size() == 100);
+ assertEquals("Incorrect message count. Should be 100, actual " + msgs.size(), 100, msgs.size());
app.clear();
assertTrue("Incorrect number of available slots", filter.getAvailable() < 100);
@@ -99,7 +87,7 @@ public class BurstFilterTest {
for (int i = 0; i < 110; i++) {
logger.info("Waited 1.5 seconds and trying to log again, should see more than 0 and less than 100" + (i + 1));
}
- assertTrue("", filter.getAvailable() == 0);
+ assertEquals("", 0, filter.getAvailable());
app.clear();
@@ -110,7 +98,7 @@ public class BurstFilterTest {
}
msgs = app.getMessages();
- assertTrue("Incorrect message count. Should be 0, actual " + msgs.size(), msgs.size() == 0);
+ assertTrue("Incorrect message count. Should be 0, actual " + msgs.size(), msgs.isEmpty());
app.clear();
// now log 100 warns, they should all get through because the filter's level is set at info
@@ -119,7 +107,7 @@ public class BurstFilterTest {
}
msgs = app.getMessages();
- assertTrue("Incorrect message count. Should be 110, actual " + msgs.size(), msgs.size() == 110);
+ assertEquals("Incorrect message count. Should be 110, actual " + msgs.size(), 110, msgs.size());
app.clear();
// now log 100 errors, they should all get through because the filter level is set at info
@@ -128,7 +116,7 @@ public class BurstFilterTest {
}
msgs = app.getMessages();
- assertTrue("Incorrect message count. Should be 110, actual " + msgs.size(), msgs.size() == 110);
+ assertEquals("Incorrect message count. Should be 110, actual " + msgs.size(), 110, msgs.size());
app.clear();
// now log 100 fatals, they should all get through because the filter level is set at info
@@ -137,7 +125,7 @@ public class BurstFilterTest {
}
msgs = app.getMessages();
- assertTrue("Incorrect message count. Should be 110, actual " + msgs.size(), msgs.size() == 110);
+ assertEquals("Incorrect message count. Should be 110, actual " + msgs.size(), 110, msgs.size());
app.clear();
// wait and make sure we can log messages again despite the fact we just logged a bunch of warns, errors, fatals
@@ -147,7 +135,7 @@ public class BurstFilterTest {
logger.debug("Waited 3+ seconds, should see 100 logs #" + (i + 1));
}
msgs = app.getMessages();
- assertTrue("Incorrect message count. Should be 100, actual " + msgs.size(), msgs.size() == 100);
+ assertEquals("Incorrect message count. Should be 100, actual " + msgs.size(), 100, msgs.size());
app.clear();
}