Search in sources :

Example 11 with TurboFilter

use of ch.qos.logback.classic.turbo.TurboFilter in project sling by apache.

the class ITFilterSupport method testTurboFilter.

@Test
public void testTurboFilter() throws Exception {
    TestAppender ta = registerAppender("turbofilter", "TestAppender");
    org.slf4j.Logger bar = LoggerFactory.getLogger("turbofilter.foo.bar");
    assertTrue(bar.isDebugEnabled());
    bar.debug("Test");
    assertEquals(1, ta.events.size());
    SimpleTurboFilter stf = new SimpleTurboFilter();
    ServiceRegistration sr = bundleContext.registerService(TurboFilter.class.getName(), stf, null);
    delay();
    assertNotNull("Filter should have context set", stf.getContext());
    assertTrue("Filter should be started", stf.isStarted());
    ta.events.clear();
    //Filter would reject calls for this logger hence it should not be false
    assertFalse(bar.isDebugEnabled());
    //No events should be logged as filter would have rejected that
    bar.debug("Test");
    assertTrue(ta.events.isEmpty());
    //Now unregister and earlier asserts should work
    sr.unregister();
    delay();
    ta.events.clear();
    assertTrue(bar.isDebugEnabled());
    bar.debug("Test");
    assertEquals(1, ta.events.size());
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter) Test(org.junit.Test)

Aggregations

TurboFilter (ch.qos.logback.classic.turbo.TurboFilter)11 Test (org.junit.Test)5 FilterChain (javax.servlet.FilterChain)4 ServletRequest (javax.servlet.ServletRequest)4 ServletResponse (javax.servlet.ServletResponse)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)4 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)4 LoggerContext (ch.qos.logback.classic.LoggerContext)3 TurboFilterList (ch.qos.logback.classic.spi.TurboFilterList)3 ReconfigureOnChangeFilter (ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter)3 Filter (javax.servlet.Filter)3 Logger (org.slf4j.Logger)2 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 ReconfigureOnChangeTask (ch.qos.logback.classic.joran.ReconfigureOnChangeTask)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 JsonObject (javax.json.JsonObject)1