use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class FileOutputTest method testConfig.
@Test
@LoggerContextSource("classpath:log4j-filetest.xml")
public void testConfig() throws IOException {
final Path logFile = Paths.get("target", "status.log");
assertTrue(Files.exists(logFile), "Status output file does not exist");
assertTrue(Files.size(logFile) > 0, "File is empty");
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class StyleConverterTest method testReplacement.
@Test
@LoggerContextSource("log4j-style.xml")
public void testReplacement(final LoggerContext context, @Named("List") final ListAppender app) {
final Logger logger = context.getLogger("LoggerTest");
logger.error(this.getClass().getName());
final List<String> msgs = app.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size(), "Incorrect number of messages. Should be 1 is " + msgs.size());
assertTrue(msgs.get(0).endsWith(EXPECTED), "Replacement failed - expected ending " + EXPECTED + ", actual " + msgs.get(0));
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class ConcurrentLoggingWithGelfLayoutTest method testConcurrentLogging.
@Test
@LoggerContextSource("log4j2-gelf-layout.xml")
public void testConcurrentLogging(final LoggerContext context) throws Throwable {
final Logger log = context.getLogger(ConcurrentLoggingWithGelfLayoutTest.class);
final int threadCount = Runtime.getRuntime().availableProcessors() * 2;
final CountDownLatch latch = new CountDownLatch(threadCount);
final List<Throwable> thrown = Collections.synchronizedList(new ArrayList<>());
for (int x = 0; x < threadCount; x++) {
final Thread t = new Thread(() -> {
log.info(latch.getCount());
try {
for (int i = 0; i < 64; i++) {
log.info("First message.");
log.info("Second message.");
}
} finally {
latch.countDown();
}
});
// Appender is configured with ignoreExceptions="false";
// any exceptions are propagated to the caller, so we can catch them here.
t.setUncaughtExceptionHandler((t1, e) -> thrown.add(e));
t.start();
}
latch.await();
// if any error occurred, fail this test
if (!thrown.isEmpty()) {
throw thrown.get(0);
}
// simple test to ensure content is not corrupted
if (Files.exists(PATH)) {
try (Stream<String> lines = Files.lines(PATH, Charset.defaultCharset())) {
lines.forEach(line -> assertThat(line, both(startsWith("{\"version\":\"1.1\",\"host\":\"myself\",\"timestamp\":")).and(endsWith("\"}"))));
}
}
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class DynamicThresholdFilterTest method testConfig.
@Test
@LoggerContextSource("log4j2-dynamicfilter.xml")
public void testConfig(final Configuration config) {
final Filter filter = config.getFilter();
assertNotNull(filter, "No DynamicThresholdFilter");
assertTrue(filter instanceof DynamicThresholdFilter, "Not a DynamicThresholdFilter");
final DynamicThresholdFilter dynamic = (DynamicThresholdFilter) filter;
final String key = dynamic.getKey();
assertNotNull(key, "Key is null");
assertEquals("loginId", key, "Incorrect key value");
final Map<String, Level> map = dynamic.getLevelMap();
assertNotNull(map, "Map is null");
assertEquals(1, map.size(), "Incorrect number of map elements");
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class StructuredDataFilterTest method testConfig.
@Test
@LoggerContextSource("log4j2-sdfilter.xml")
public void testConfig(final Configuration config) {
final Filter filter = config.getFilter();
assertNotNull(filter, "No StructuredDataFilter");
assertTrue(filter instanceof StructuredDataFilter, "Not a StructuredDataFilter");
final StructuredDataFilter sdFilter = (StructuredDataFilter) filter;
assertFalse(sdFilter.isAnd(), "Should not be And filter");
final IndexedReadOnlyStringMap map = sdFilter.getStringMap();
assertNotNull(map, "No Map");
assertFalse(map.isEmpty(), "No elements in Map");
assertEquals(1, map.size(), "Incorrect number of elements in Map");
assertTrue(map.containsKey("eventId"), "Map does not contain key eventId");
assertEquals(2, map.<Collection<?>>getValue("eventId").size(), "List does not contain 2 elements");
}
Aggregations