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);
}
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);
}
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();
}
}
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);
}
Aggregations