Search in sources :

Example 6 with ConfigurationScheduler

use of org.apache.logging.log4j.core.config.ConfigurationScheduler in project logging-log4j2 by apache.

the class WatchHttpTest method testWatchManager.

@Test
public void testWatchManager() throws Exception {
    BlockingQueue<String> queue = new LinkedBlockingQueue<>();
    List<ConfigurationListener> listeners = new ArrayList<>();
    listeners.add(new TestConfigurationListener(queue, "log4j-test1.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-test1.xml");
    StubMapping stubMapping = stubFor(get(urlPathEqualTo("/log4j-test1.xml")).willReturn(aResponse().withBodyFile(file).withStatus(200).withHeader("Last-Modified", formatter.format(previous) + " 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);
        assertNotNull("File change not detected", str);
    } finally {
        removeStub(stubMapping);
        watchManager.stop();
        scheduler.stop();
    }
}
Also used : HttpWatcher(org.apache.logging.log4j.core.config.HttpWatcher) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ConfigurationScheduler(org.apache.logging.log4j.core.config.ConfigurationScheduler) URL(java.net.URL) ConfigurationListener(org.apache.logging.log4j.core.config.ConfigurationListener) TimeZone(java.util.TimeZone) Test(org.junit.Test)

Aggregations

ConfigurationScheduler (org.apache.logging.log4j.core.config.ConfigurationScheduler)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 Path (java.nio.file.Path)3 Test (org.junit.jupiter.api.Test)3 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 TimeZone (java.util.TimeZone)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 ConfigurationListener (org.apache.logging.log4j.core.config.ConfigurationListener)2 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)2 HttpWatcher (org.apache.logging.log4j.core.config.HttpWatcher)2 Test (org.junit.Test)2 Date (java.util.Date)1