use of org.apache.logging.log4j.core.config.DefaultConfiguration in project logging-log4j2 by apache.
the class LateConfigTest method testReconfiguration.
@Test
public void testReconfiguration() throws Exception {
final Configuration cfg = context.getConfiguration();
assertNotNull(cfg, "No configuration");
assertTrue(cfg instanceof DefaultConfiguration, "Not set to default configuration");
final File file = new File(CONFIG);
final LoggerContext loggerContext = LoggerContext.getContext(null, false, file.toURI());
assertNotNull(loggerContext, "No Logger Context");
final Configuration newConfig = loggerContext.getConfiguration();
assertNotSame(cfg, newConfig, "Configuration not reset");
assertTrue(newConfig instanceof XmlConfiguration, "Reconfiguration failed");
context = LoggerContext.getContext(false);
final Configuration sameConfig = context.getConfiguration();
assertSame(newConfig, sameConfig, "Configuration should not have been reset");
}
use of org.apache.logging.log4j.core.config.DefaultConfiguration in project logging-log4j2 by apache.
the class EncodingPatternConverterTest method testHandlesThrowable.
@Test
public void testHandlesThrowable() {
final Configuration configuration = new DefaultConfiguration();
assertFalse(EncodingPatternConverter.newInstance(configuration, new String[] { "%msg", "XML" }).handlesThrowable());
assertTrue(EncodingPatternConverter.newInstance(configuration, new String[] { "%xThrowable{full}", "JSON" }).handlesThrowable());
assertTrue(EncodingPatternConverter.newInstance(configuration, new String[] { "%ex", "XML" }).handlesThrowable());
}
use of org.apache.logging.log4j.core.config.DefaultConfiguration in project logging-log4j2 by apache.
the class ScriptConditionTest method testSelectFilesToDelete.
@Test
public void testSelectFilesToDelete() {
final Configuration config = new DefaultConfiguration();
// creates the ScriptManager
config.initialize();
// script that returns pathList
final ScriptPlugin script = new ScriptPlugin("test", "javascript", "pathList;");
final ScriptCondition condition = ScriptCondition.createCondition(script, config);
final List<PathWithAttributes> pathList = new ArrayList<>();
final Path base = Paths.get("baseDirectory");
final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList);
assertSame(result, pathList);
}
use of org.apache.logging.log4j.core.config.DefaultConfiguration in project logging-log4j2 by apache.
the class ScriptConditionTest method testSelectFilesToDelete2.
@Test
public void testSelectFilesToDelete2() {
final Configuration config = new DefaultConfiguration();
// creates the ScriptManager
config.initialize();
final List<PathWithAttributes> pathList = new ArrayList<>();
pathList.add(new PathWithAttributes(Paths.get("/path/1"), new DummyFileAttributes()));
pathList.add(new PathWithAttributes(Paths.get("/path/2"), new DummyFileAttributes()));
pathList.add(new PathWithAttributes(Paths.get("/path/3"), new DummyFileAttributes()));
final String scriptText = //
"pathList.remove(1);" + "pathList;";
final ScriptPlugin script = new ScriptPlugin("test", "javascript", scriptText);
final ScriptCondition condition = ScriptCondition.createCondition(script, config);
final Path base = Paths.get("baseDirectory");
final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList);
assertSame(result, pathList);
assertEquals(2, result.size());
assertEquals(Paths.get("/path/1"), result.get(0).getPath());
assertEquals(Paths.get("/path/3"), result.get(1).getPath());
}
use of org.apache.logging.log4j.core.config.DefaultConfiguration in project logging-log4j2 by apache.
the class WatchHttpTest method testNotModified.
@Test
public void testNotModified() throws Exception {
BlockingQueue<String> queue = new LinkedBlockingQueue<>();
List<ConfigurationListener> listeners = new ArrayList<>();
listeners.add(new TestConfigurationListener(queue, "log4j-test2.xml"));
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar now = Calendar.getInstance(timeZone);
Calendar previous = now;
previous.add(Calendar.MINUTE, -5);
Configuration configuration = new DefaultConfiguration();
Assume.assumeTrue(!IS_WINDOWS || Boolean.getBoolean(FORCE_RUN_KEY));
URL url = new URL("http://localhost:" + wireMockRule.port() + "/log4j-test2.xml");
StubMapping stubMapping = stubFor(get(urlPathEqualTo("/log4j-test2.xml")).willReturn(aResponse().withBodyFile(file).withStatus(304).withHeader("Last-Modified", formatter.format(now) + " GMT").withHeader("Content-Type", XML)));
final ConfigurationScheduler scheduler = new ConfigurationScheduler();
scheduler.incrementScheduledItems();
final WatchManager watchManager = new WatchManager(scheduler);
watchManager.setIntervalSeconds(1);
scheduler.start();
watchManager.start();
try {
watchManager.watch(new Source(url.toURI()), new HttpWatcher(configuration, null, listeners, previous.getTimeInMillis()));
final String str = queue.poll(2, TimeUnit.SECONDS);
assertNull("File changed.", str);
} finally {
removeStub(stubMapping);
watchManager.stop();
scheduler.stop();
}
}
Aggregations