use of org.apache.logging.log4j.core.config.HttpWatcher 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();
}
}
use of org.apache.logging.log4j.core.config.HttpWatcher 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();
}
}
Aggregations