Search in sources :

Example 1 with ManagerBase

use of org.apache.catalina.session.ManagerBase in project micrometer by micrometer-metrics.

the class TomcatMetricsTest method managerBasedMetrics.

@Test
void managerBasedMetrics() {
    Context context = new StandardContext();
    ManagerBase manager = new ManagerBase() {

        @Override
        public void load() {
        }

        @Override
        public void unload() {
        }

        @Override
        public Context getContext() {
            return context;
        }
    };
    manager.setMaxActiveSessions(3);
    manager.createSession("first");
    manager.createSession("second");
    manager.createSession("third");
    try {
        manager.createSession("fourth");
        fail("TooManyActiveSessionsException expected.");
    } catch (TooManyActiveSessionsException exception) {
    // ignore error, testing rejection
    }
    StandardSession expiredSession = new StandardSession(manager);
    expiredSession.setId("third");
    expiredSession.setCreationTime(System.currentTimeMillis() - 10_000);
    manager.remove(expiredSession, true);
    Iterable<Tag> tags = Tags.of("metricTag", "val1");
    TomcatMetrics.monitor(registry, manager, tags);
    assertThat(registry.get("tomcat.sessions.active.max").tags(tags).gauge().value()).isEqualTo(3.0);
    assertThat(registry.get("tomcat.sessions.active.current").tags(tags).gauge().value()).isEqualTo(2.0);
    assertThat(registry.get("tomcat.sessions.expired").tags(tags).functionCounter().count()).isEqualTo(1.0);
    assertThat(registry.get("tomcat.sessions.rejected").tags(tags).functionCounter().count()).isEqualTo(1.0);
    assertThat(registry.get("tomcat.sessions.created").tags(tags).functionCounter().count()).isEqualTo(3.0);
    assertThat(registry.get("tomcat.sessions.alive.max").tags(tags).timeGauge().value()).isGreaterThan(1.0);
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) TooManyActiveSessionsException(org.apache.catalina.session.TooManyActiveSessionsException) ManagerBase(org.apache.catalina.session.ManagerBase) StandardSession(org.apache.catalina.session.StandardSession) StandardContext(org.apache.catalina.core.StandardContext) Tag(io.micrometer.core.instrument.Tag) Test(org.junit.jupiter.api.Test)

Example 2 with ManagerBase

use of org.apache.catalina.session.ManagerBase in project tomcat70 by apache.

the class TestSSOnonLoginAndBasicAuthenticator method doImminentSessionTimeout.

/*
     * Force faster timeout for an active Container than can
     * be defined in web.xml. By getting to the active Session we
     * can choose seconds instead of minutes.
     * Note: shamelessly cloned from ManagerBase - beware of synch issues
     *       on the underlying sessions.
     */
private void doImminentSessionTimeout(Context activeContext) {
    ManagerBase manager = (ManagerBase) activeContext.getManager();
    Session[] sessions = manager.findSessions();
    for (int i = 0; i < sessions.length; i++) {
        if (sessions[i] != null && sessions[i].isValid()) {
            sessions[i].setMaxInactiveInterval(EXTRA_DELAY_SECS);
        // leave it to be expired by the manager
        }
    }
    try {
        Thread.sleep(EXTRA_DELAY_SECS * 1000);
    } catch (InterruptedException ie) {
    // ignored
    }
    // Paranoid verification that active sessions have now gone
    int count = 0;
    sessions = manager.findSessions();
    while (sessions.length != 0 && count < TIMEOUT_WAIT_SECS) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // Ignore
        }
        sessions = manager.findSessions();
        count++;
    }
    sessions = manager.findSessions();
    Assert.assertTrue(sessions.length == 0);
}
Also used : ManagerBase(org.apache.catalina.session.ManagerBase) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint) Session(org.apache.catalina.Session)

Example 3 with ManagerBase

use of org.apache.catalina.session.ManagerBase in project geode by apache.

the class SessionExpirationCacheListener method afterDestroy.

public void afterDestroy(EntryEvent<String, HttpSession> event) {
    // A Session expired. If it was destroyed by GemFire expiration, process it.
    // If it was destroyed via Session.invalidate, ignore it since it has
    // already been processed.
    DeltaSessionInterface session = null;
    if (event.getOperation() == Operation.EXPIRE_DESTROY) {
        session = (DeltaSessionInterface) event.getOldValue();
    } else {
        /*
       * This comes into play when we're dealing with an empty client proxy. We need the actual
       * destroyed object to come back from the server so that any associated listeners can fire
       * correctly. Having the destroyed object come back as the callback arg depends on setting the
       * property gemfire.EXPIRE_SENDS_ENTRY_AS_CALLBACK.
       */
        Object callback = event.getCallbackArgument();
        if (callback != null && callback instanceof DeltaSessionInterface) {
            session = (DeltaSessionInterface) callback;
            ManagerBase m = ContextMapper.getContext(session.getContextName());
            if (m != null) {
                session.setOwner(m);
            }
        }
    }
    if (session != null) {
        session.processExpired();
    }
}
Also used : DeltaSessionInterface(org.apache.geode.modules.session.catalina.DeltaSessionInterface) ManagerBase(org.apache.catalina.session.ManagerBase)

Example 4 with ManagerBase

use of org.apache.catalina.session.ManagerBase in project tomcat by apache.

the class TestSSOnonLoginAndBasicAuthenticator method doImminentSessionTimeout.

/*
     * Force faster timeout for an active Container than can
     * be defined in web.xml. By getting to the active Session we
     * can choose seconds instead of minutes.
     * Note: shamelessly cloned from ManagerBase - beware of synch issues
     *       on the underlying sessions.
     */
private void doImminentSessionTimeout(Context activeContext) {
    ManagerBase manager = (ManagerBase) activeContext.getManager();
    Session[] sessions = manager.findSessions();
    for (Session session : sessions) {
        if (session != null && session.isValid()) {
            session.setMaxInactiveInterval(EXTRA_DELAY_SECS);
        // leave it to be expired by the manager
        }
    }
    try {
        Thread.sleep(EXTRA_DELAY_SECS * 1000);
    } catch (InterruptedException ie) {
    // ignored
    }
    // Paranoid verification that active sessions have now gone
    int count = 0;
    sessions = manager.findSessions();
    while (sessions.length != 0 && count < TIMEOUT_WAIT_SECS) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // Ignore
        }
        sessions = manager.findSessions();
        count++;
    }
    sessions = manager.findSessions();
    Assert.assertTrue(sessions.length == 0);
}
Also used : ManagerBase(org.apache.catalina.session.ManagerBase) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) Session(org.apache.catalina.Session)

Aggregations

ManagerBase (org.apache.catalina.session.ManagerBase)4 Session (org.apache.catalina.Session)2 Tag (io.micrometer.core.instrument.Tag)1 Context (org.apache.catalina.Context)1 StandardContext (org.apache.catalina.core.StandardContext)1 SecurityConstraint (org.apache.catalina.deploy.SecurityConstraint)1 StandardSession (org.apache.catalina.session.StandardSession)1 TooManyActiveSessionsException (org.apache.catalina.session.TooManyActiveSessionsException)1 DeltaSessionInterface (org.apache.geode.modules.session.catalina.DeltaSessionInterface)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 Test (org.junit.jupiter.api.Test)1