Search in sources :

Example 6 with LifecycleEvent

use of org.apache.catalina.LifecycleEvent in project sonarqube by SonarSource.

the class TomcatAccessLogTest method log_when_started_and_stopped.

@Test
public void log_when_started_and_stopped() {
    Logger logger = mock(Logger.class);
    TomcatAccessLog.LifecycleLogger listener = new TomcatAccessLog.LifecycleLogger(logger);
    LifecycleEvent event = new LifecycleEvent(mock(Lifecycle.class), "before_init", null);
    listener.lifecycleEvent(event);
    verifyZeroInteractions(logger);
    event = new LifecycleEvent(mock(Lifecycle.class), "after_start", null);
    listener.lifecycleEvent(event);
    verify(logger).debug("Tomcat is started");
    event = new LifecycleEvent(mock(Lifecycle.class), "after_destroy", null);
    listener.lifecycleEvent(event);
    verify(logger).debug("Tomcat is stopped");
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) LifecycleEvent(org.apache.catalina.LifecycleEvent) Logger(org.sonar.api.utils.log.Logger) Test(org.junit.Test)

Example 7 with LifecycleEvent

use of org.apache.catalina.LifecycleEvent in project tomee by apache.

the class TomEEUndeployTest method tomcatLifecycle.

@Test
public void tomcatLifecycle() throws Exception {
    container.start();
    assertEquals(0, webapps().length);
    final StandardHost standardHost = StandardHost.class.cast(TomcatHelper.getServer().findService("Tomcat").getContainer().findChild("localhost"));
    // not done in embedded but that's the way autodeploy works in normal tomcat
    final HostConfig listener = new HostConfig();
    standardHost.addLifecycleListener(listener);
    createWebapp(new File(WORK_DIR, "tomee/webapps/my-webapp"));
    listener.lifecycleEvent(new LifecycleEvent(standardHost, Lifecycle.START_EVENT, standardHost));
    assertEquals(1, webapps().length);
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) HostConfig(org.apache.catalina.startup.HostConfig) LifecycleEvent(org.apache.catalina.LifecycleEvent) File(java.io.File) Test(org.junit.Test)

Example 8 with LifecycleEvent

use of org.apache.catalina.LifecycleEvent in project Payara by payara.

the class LifecycleSupport method fireLifecycleEvent.

/**
 * Notify all lifecycle event listeners that a particular event has
 * occurred for this Container.  The default implementation performs
 * this notification synchronously using the calling thread.
 *
 * @param type Event type
 * @param data Event data
 */
public void fireLifecycleEvent(String type, Object data) throws LifecycleException {
    LifecycleListener[] listenersArray = null;
    synchronized (listeners) {
        if (listeners.isEmpty()) {
            return;
        }
        listenersArray = listeners.toArray(new LifecycleListener[listeners.size()]);
    }
    LifecycleEvent event = new LifecycleEvent(lifecycle, type, data);
    for (LifecycleListener listenersArray1 : listenersArray) {
        listenersArray1.lifecycleEvent(event);
    }
}
Also used : LifecycleEvent(org.apache.catalina.LifecycleEvent) LifecycleListener(org.apache.catalina.LifecycleListener)

Aggregations

LifecycleEvent (org.apache.catalina.LifecycleEvent)8 LifecycleListener (org.apache.catalina.LifecycleListener)5 Test (org.junit.Test)4 File (java.io.File)3 AprLifecycleListener (org.apache.catalina.core.AprLifecycleListener)2 StandardHost (org.apache.catalina.core.StandardHost)2 HostConfig (org.apache.catalina.startup.HostConfig)2 Test (org.junit.jupiter.api.Test)2 InOrder (org.mockito.InOrder)2 URL (java.net.URL)1 Lifecycle (org.apache.catalina.Lifecycle)1 WebXml (org.apache.catalina.deploy.WebXml)1 ContextConfig (org.apache.catalina.startup.ContextConfig)1 Tomcat (org.apache.catalina.startup.Tomcat)1 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)1 Logger (org.sonar.api.utils.log.Logger)1