From 387f43371119c8174d3f22663ba12ff61c2bc4bb Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 18 May 2016 09:54:00 +1000 Subject: [PATCH] Refactor names of session impl classes; fix bugs; add some tests --- ...Store.java => GCloudSessionDataStore.java} | 22 +- .../gcloud/session/GCloudSessionTester.java | 6 +- ...e.java => InfinispanSessionDataStore.java} | 20 +- ...=> InfinispanSessionDataStoreFactory.java} | 14 +- ...nStore.java => NoSqlSessionDataStore.java} | 6 +- ...nStore.java => MongoSessionDataStore.java} | 38 +- ...java => MongoSessionDataStoreFactory.java} | 14 +- .../etc/sessions/file/session-store.xml | 2 +- .../etc/sessions/jdbc/session-store.xml | 4 +- .../org/eclipse/jetty/server/Request.java | 19 - .../server/session/AbstractSessionCache.java | 333 +++++++++++------- ...ore.java => AbstractSessionDataStore.java} | 14 +- ...a => AbstractSessionDataStoreFactory.java} | 4 +- .../server/session/CachingSessionStore.java | 106 +++--- .../session/CachingSessionStoreFactory.java | 16 +- .../server/session/DefaultSessionCache.java | 8 +- .../session/DefaultSessionCacheFactory.java | 55 +-- .../session/DefaultSessionIdManager.java | 1 + ...onStore.java => FileSessionDataStore.java} | 16 +- ....java => FileSessionDataStoreFactory.java} | 10 +- ...onStore.java => JDBCSessionDataStore.java} | 18 +- ....java => JDBCSessionDataStoreFactory.java} | 14 +- ...onStore.java => NullSessionDataStore.java} | 18 +- .../eclipse/jetty/server/session/Session.java | 199 +++++------ .../jetty/server/session/SessionCache.java | 45 ++- .../jetty/server/session/SessionData.java | 7 +- .../jetty/server/session/SessionDataMap.java | 67 ++++ ...essionStore.java => SessionDataStore.java} | 49 +-- ...tory.java => SessionDataStoreFactory.java} | 6 +- .../jetty/server/session/SessionHandler.java | 184 +++++++--- .../eclipse/jetty/server/ResponseTest.java | 15 +- .../session/FileSessionManagerTest.java | 18 +- .../server/session/SessionCookieTest.java | 6 +- .../jetty/server/session/FileTestServer.java | 13 +- .../jetty/server/session/IdleSessionTest.java | 7 +- .../server/session/ImmortalSessionTest.java | 4 +- .../jetty/server/session/NewSessionTest.java | 4 +- .../server/session/OrphanedSessionTest.java | 4 +- .../session/ProxySerializationTest.java | 4 +- .../session/ReentrantRequestSessionTest.java | 4 +- .../server/session/RemoveSessionTest.java | 4 +- .../server/session/SessionCookieTest.java | 4 +- .../SessionInvalidateAndCreateTest.java | 4 +- .../server/session/SessionRenewTest.java | 4 +- .../session/SessionValueSharedSaving.java | 4 +- .../session/GCloudSessionTestSupport.java | 8 +- .../gcloud/session/GCloudTestServer.java | 6 +- .../gcloud/session/ImmortalSessionTest.java | 4 +- .../session/InvalidationSessionTest.java | 10 +- .../gcloud/session/LastAccessTimeTest.java | 4 +- .../session/LocalSessionScavengingTest.java | 4 +- .../jetty/gcloud/session/NewSessionTest.java | 4 +- .../gcloud/session/OrphanedSessionTest.java | 4 +- .../session/ReentrantRequestSessionTest.java | 4 +- .../gcloud/session/RemoveSessionTest.java | 4 +- .../gcloud/session/SameNodeLoadTest.java | 4 +- .../gcloud/session/SessionExpiryTest.java | 4 +- .../SessionInvalidateAndCreateTest.java | 4 +- .../gcloud/session/SessionRenewTest.java | 4 +- .../session/SessionValueSavingTest.java | 4 +- .../jetty/server/session/HashTestServer.java | 8 +- .../server/session/ImmortalSessionTest.java | 4 +- .../jetty/server/session/NewSessionTest.java | 4 +- .../session/ReentrantRequestSessionTest.java | 4 +- .../server/session/RemoveSessionTest.java | 4 +- .../server/session/SessionCookieTest.java | 4 +- .../SessionInvalidateAndCreateTest.java | 4 +- .../server/session/SessionRenewTest.java | 4 +- .../session/SessionValueSharedSaving.java | 4 +- .../server/session/ImmortalSessionTest.java | 4 +- .../session/InfinispanTestSessionServer.java | 16 +- .../server/session/LastAccessTimeTest.java | 4 +- .../session/LocalSessionScavengingTest.java | 4 +- .../jetty/server/session/NewSessionTest.java | 4 +- .../session/ReentrantRequestSessionTest.java | 4 +- .../server/session/RemoveSessionTest.java | 4 +- .../server/session/SameNodeLoadTest.java | 4 +- .../server/session/SessionExpiryTest.java | 4 +- .../SessionInvalidateAndCreateTest.java | 4 +- .../server/session/SessionRenewTest.java | 4 +- .../remote/RemoteImmortalSessionTest.java | 4 +- .../remote/RemoteInvalidationSessionTest.java | 4 +- .../remote/RemoteLastAccessTimeTest.java | 4 +- .../RemoteLocalSessionScavengingTest.java | 4 +- .../session/remote/RemoteNewSessionTest.java | 4 +- .../RemoteReentrantRequestSessionTest.java | 4 +- .../remote/RemoteRemoveSessionTest.java | 4 +- .../remote/RemoteSameNodeLoadTest.java | 4 +- .../remote/RemoteSessionExpiryTest.java | 4 +- .../RemoteSessionInvalidateAndCreateTest.java | 4 +- .../remote/RemoteSessionRenewTest.java | 4 +- .../server/session/DirtyAttributeTest.java | 4 +- .../server/session/ImmortalSessionTest.java | 4 +- .../session/InvalidationSessionTest.java | 4 +- .../jetty/server/session/JdbcTestServer.java | 8 +- .../server/session/LastAccessTimeTest.java | 4 +- .../session/LocalSessionScavengingTest.java | 4 +- .../ModifyMaxInactiveIntervalTest.java | 5 +- .../jetty/server/session/NewSessionTest.java | 4 +- .../server/session/OrphanedSessionTest.java | 4 +- .../session/ProxySerializationTest.java | 4 +- .../session/ReentrantRequestSessionTest.java | 4 +- .../server/session/SaveIntervalTest.java | 2 +- .../server/session/SessionExpiryTest.java | 4 +- .../SessionInvalidateAndCreateTest.java | 4 +- .../server/session/SessionRenewTest.java | 4 +- .../session/SessionValueSavingTest.java | 4 +- .../test-mongodb-sessions/pom.xml | 2 +- .../nosql/mongodb/AttributeNameTest.java | 7 +- .../mongodb/CreateAndInvalidateTest.java | 105 ++++++ .../jetty/nosql/mongodb/IdleSessionTest.java | 24 +- .../nosql/mongodb/InvalidateSessionTest.java | 4 +- .../nosql/mongodb/LastAccessTimeTest.java | 4 +- .../mongodb/LocalSessionScavengingTest.java | 4 +- .../jetty/nosql/mongodb/MongoTestServer.java | 5 +- .../jetty/nosql/mongodb/NewSessionTest.java | 4 +- .../nosql/mongodb/OrphanedSessionTest.java | 4 +- .../mongodb/ReentrantRequestSessionTest.java | 4 +- .../nosql/mongodb/RemoveSessionTest.java | 4 +- .../nosql/mongodb/SessionExpiryTest.java | 24 +- .../SessionInvalidateAndCreateTest.java | 4 +- .../jetty/nosql/mongodb/SessionRenewTest.java | 4 +- .../nosql/mongodb/SessionSavingValueTest.java | 4 +- .../AbstractCreateAndInvalidateTest.java | 275 +++++++++++++++ .../session/AbstractIdleSessionTest.java | 27 +- .../session/AbstractImmortalSessionTest.java | 6 +- .../AbstractInvalidationSessionTest.java | 2 +- .../session/AbstractLastAccessTimeTest.java | 12 +- .../AbstractLocalSessionScavengingTest.java | 9 +- .../session/AbstractNewSessionTest.java | 2 +- .../session/AbstractOrphanedSessionTest.java | 4 +- .../AbstractProxySerializationTest.java | 2 +- .../AbstractReentrantRequestSessionTest.java | 28 +- .../session/AbstractRemoveSessionTest.java | 16 +- .../session/AbstractSameNodeLoadTest.java | 2 +- ...AbstractServerCrossContextSessionTest.java | 2 - .../session/AbstractSessionCookieTest.java | 2 +- .../session/AbstractSessionExpiryTest.java | 2 +- ...bstractSessionInvalidateAndCreateTest.java | 20 +- .../session/AbstractSessionRenewTest.java | 6 +- .../AbstractSessionValueSavingTest.java | 6 +- .../server/session/AbstractTestServer.java | 18 +- .../java/org/eclipse/jetty/TestServer.java | 8 +- 143 files changed, 1450 insertions(+), 899 deletions(-) rename jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/{GCloudSessionStore.java => GCloudSessionDataStore.java} (94%) rename jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/{InfinispanSessionStore.java => InfinispanSessionDataStore.java} (92%) rename jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/{InfinispanSessionStoreFactory.java => InfinispanSessionDataStoreFactory.java} (78%) rename jetty-nosql/src/main/java/org/eclipse/jetty/nosql/{NoSqlSessionStore.java => NoSqlSessionDataStore.java} (93%) rename jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/{MongoSessionStore.java => MongoSessionDataStore.java} (94%) rename jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/{MongoSessionStoreFactory.java => MongoSessionDataStoreFactory.java} (78%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{AbstractSessionStore.java => AbstractSessionDataStore.java} (85%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{AbstractSessionStoreFactory.java => AbstractSessionDataStoreFactory.java} (90%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{FileSessionStore.java => FileSessionDataStore.java} (95%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{FileSessionStoreFactory.java => FileSessionDataStoreFactory.java} (82%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{JDBCSessionStore.java => JDBCSessionDataStore.java} (98%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{JDBCSessionStoreFactory.java => JDBCSessionDataStoreFactory.java} (80%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{NullSessionStore.java => NullSessionDataStore.java} (71%) create mode 100644 jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataMap.java rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{SessionStore.java => SessionDataStore.java} (65%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{SessionStoreFactory.java => SessionDataStoreFactory.java} (84%) create mode 100644 tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/CreateAndInvalidateTest.java create mode 100644 tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractCreateAndInvalidateTest.java diff --git a/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionStore.java b/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java similarity index 94% rename from jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionStore.java rename to jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java index e1a62f2a419..8c9598a8aa5 100644 --- a/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionStore.java +++ b/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java @@ -42,7 +42,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import org.eclipse.jetty.server.session.AbstractSessionStore; +import org.eclipse.jetty.server.session.AbstractSessionDataStore; import org.eclipse.jetty.server.session.SessionContext; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.util.ClassLoadingObjectInputStream; @@ -51,11 +51,11 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - * GCloudSessionStore + * GCloudSessionDataStore * * */ -public class GCloudSessionStore extends AbstractSessionStore +public class GCloudSessionDataStore extends AbstractSessionDataStore { private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); @@ -85,7 +85,7 @@ public class GCloudSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStart() + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStart() */ @Override protected void doStart() throws Exception @@ -138,7 +138,7 @@ public class GCloudSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String) */ @Override public SessionData load(String id) throws Exception @@ -159,7 +159,7 @@ public class GCloudSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String) */ @Override public boolean delete(String id) throws Exception @@ -170,7 +170,7 @@ public class GCloudSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set doGetExpired(Set candidates) @@ -221,7 +221,7 @@ public class GCloudSessionStore extends AbstractSessionStore } } - //reconcile against ids that the SessionStore thinks are expired + //reconcile against ids that the SessionDataStore thinks are expired Set tmp = new HashSet(candidates); tmp.removeAll(expired); if (!tmp.isEmpty()) @@ -264,7 +264,7 @@ public class GCloudSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) throws Exception @@ -290,7 +290,7 @@ public class GCloudSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception @@ -431,7 +431,7 @@ public class GCloudSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() diff --git a/jetty-gcloud/jetty-gcloud-session-manager/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTester.java b/jetty-gcloud/jetty-gcloud-session-manager/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTester.java index bcd6103d791..777903ca8bf 100644 --- a/jetty-gcloud/jetty-gcloud-session-manager/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTester.java +++ b/jetty-gcloud/jetty-gcloud-session-manager/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTester.java @@ -59,11 +59,11 @@ public class GCloudSessionTester webapp.setContextPath("/"); webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war"); webapp.addAliasCheck(new AllowSymLinkAliasChecker()); - GCloudSessionStore ds = new GCloudSessionStore(); + GCloudSessionDataStore ds = new GCloudSessionDataStore(); ds.setGCloudConfiguration(config); DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler()); - webapp.getSessionHandler().setSessionStore(ss); - ss.setSessionStore(ds); + webapp.getSessionHandler().setSessionCache(ss); + ss.setSessionDataStore(ds); webapp.getSessionHandler().setSessionIdManager(idmgr); // A WebAppContext is a ContextHandler as well so it needs to be set to diff --git a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionStore.java b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java similarity index 92% rename from jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionStore.java rename to jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java index 08e417854b2..66059bc8c7d 100644 --- a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionStore.java +++ b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java @@ -25,18 +25,18 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.server.SessionIdManager; -import org.eclipse.jetty.server.session.AbstractSessionStore; +import org.eclipse.jetty.server.session.AbstractSessionDataStore; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.infinispan.commons.api.BasicCache; /** - * InfinispanSessionStore + * InfinispanSessionDataStore * * */ -public class InfinispanSessionStore extends AbstractSessionStore +public class InfinispanSessionDataStore extends AbstractSessionDataStore { private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); @@ -76,7 +76,7 @@ public class InfinispanSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#load(String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(String) */ @Override public SessionData load(String id) throws Exception @@ -114,7 +114,7 @@ public class InfinispanSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(String) */ @Override public boolean delete(String id) throws Exception @@ -125,7 +125,7 @@ public class InfinispanSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set doGetExpired(Set candidates) @@ -138,7 +138,7 @@ public class InfinispanSessionStore extends AbstractSessionStore Set expired = new HashSet(); //TODO if there is NOT an idle timeout set on entries in infinispan, need to check other sessions - //that are not currently in the SessionStore (eg they've been passivated) + //that are not currently in the SessionDataStore (eg they've been passivated) for (String candidate:candidates) { @@ -196,7 +196,7 @@ public class InfinispanSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception @@ -224,7 +224,7 @@ public class InfinispanSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() @@ -248,7 +248,7 @@ public class InfinispanSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) throws Exception diff --git a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionStoreFactory.java b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java similarity index 78% rename from jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionStoreFactory.java rename to jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java index 836a111328c..eadbe3cbeec 100644 --- a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionStoreFactory.java +++ b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStoreFactory.java @@ -19,17 +19,17 @@ package org.eclipse.jetty.session.infinispan; -import org.eclipse.jetty.server.session.AbstractSessionStoreFactory; +import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.server.session.SessionHandler; -import org.eclipse.jetty.server.session.SessionStore; +import org.eclipse.jetty.server.session.SessionDataStore; import org.infinispan.commons.api.BasicCache; /** - * InfinispanSessionStoreFactory + * InfinispanSessionDataStoreFactory * * */ -public class InfinispanSessionStoreFactory extends AbstractSessionStoreFactory +public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreFactory { int _infinispanIdleTimeoutSec; BasicCache _cache; @@ -52,12 +52,12 @@ public class InfinispanSessionStoreFactory extends AbstractSessionStoreFactory } /** - * @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler) + * @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override - public SessionStore getSessionStore (SessionHandler handler) throws Exception + public SessionDataStore getSessionDataStore (SessionHandler handler) throws Exception { - InfinispanSessionStore store = new InfinispanSessionStore(); + InfinispanSessionDataStore store = new InfinispanSessionDataStore(); store.setGracePeriodSec(getGracePeriodSec()); store.setInfinispanIdleTimeoutSec(getInfinispanIdleTimeoutSec()); store.setCache(getCache()); diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionStore.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionDataStore.java similarity index 93% rename from jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionStore.java rename to jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionDataStore.java index 22da379c26e..7bdb6281c17 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionStore.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionDataStore.java @@ -22,16 +22,16 @@ package org.eclipse.jetty.nosql; import java.util.HashSet; import java.util.Set; -import org.eclipse.jetty.server.session.AbstractSessionStore; +import org.eclipse.jetty.server.session.AbstractSessionDataStore; import org.eclipse.jetty.server.session.SessionData; /** - * NoSqlSessionStore + * NoSqlSessionDataStore * * */ -public abstract class NoSqlSessionStore extends AbstractSessionStore +public abstract class NoSqlSessionDataStore extends AbstractSessionDataStore { public class NoSqlSessionData extends SessionData diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionStore.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java similarity index 94% rename from jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionStore.java rename to jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java index 4b807a29d09..2c720a1b0b8 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionStore.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java @@ -24,6 +24,7 @@ import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.WriteConcern; +import com.mongodb.WriteResult; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -36,14 +37,14 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import org.eclipse.jetty.nosql.NoSqlSessionStore; +import org.eclipse.jetty.nosql.NoSqlSessionDataStore; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.util.ClassLoadingObjectInputStream; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - * MongoSessionStore + * MongoSessionDataStore * * The document model is an outer object that contains the elements: *
    @@ -88,7 +89,7 @@ import org.eclipse.jetty.util.log.Logger; * "context".unique_context_name.attribute_name * Eg "context"."::/contextA"."A" */ -public class MongoSessionStore extends NoSqlSessionStore +public class MongoSessionDataStore extends NoSqlSessionDataStore { private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); @@ -166,7 +167,7 @@ public class MongoSessionStore extends NoSqlSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#load(String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(String) */ @Override public SessionData load(String id) throws Exception @@ -258,7 +259,7 @@ public class MongoSessionStore extends NoSqlSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(String) */ @Override public boolean delete(String id) throws Exception @@ -272,7 +273,8 @@ public class MongoSessionStore extends NoSqlSessionStore */ BasicDBObject mongoKey = new BasicDBObject(__ID, id); - DBObject sessionDocument = _dbSessions.findOne(mongoKey,_version_1); + //DBObject sessionDocument = _dbSessions.findOne(mongoKey,_version_1); + DBObject sessionDocument = _dbSessions.findOne(new BasicDBObject(__ID, id)); if (sessionDocument != null) { @@ -280,7 +282,7 @@ public class MongoSessionStore extends NoSqlSessionStore if (c == null) { //delete whole doc - _dbSessions.remove(mongoKey); + _dbSessions.remove(mongoKey, WriteConcern.SAFE); return false; } @@ -288,14 +290,14 @@ public class MongoSessionStore extends NoSqlSessionStore if (contexts.isEmpty()) { //delete whole doc - _dbSessions.remove(mongoKey); + _dbSessions.remove(mongoKey, WriteConcern.SAFE); return false; } if (contexts.size() == 1 && contexts.iterator().next().equals(getCanonicalContextId())) { //delete whole doc - _dbSessions.remove(mongoKey); + _dbSessions.remove(new BasicDBObject(__ID, id), WriteConcern.SAFE); return true; } @@ -304,8 +306,7 @@ public class MongoSessionStore extends NoSqlSessionStore BasicDBObject unsets = new BasicDBObject(); unsets.put(getContextField(),1); remove.put("$unset",unsets); - _dbSessions.update(mongoKey,remove,false,false,WriteConcern.SAFE); - + WriteResult result = _dbSessions.update(mongoKey,remove,false,false,WriteConcern.SAFE); return true; } else @@ -318,7 +319,7 @@ public class MongoSessionStore extends NoSqlSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) throws Exception @@ -345,7 +346,7 @@ public class MongoSessionStore extends NoSqlSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set doGetExpired(Set candidates) @@ -409,7 +410,7 @@ public class MongoSessionStore extends NoSqlSessionStore } /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception @@ -492,12 +493,9 @@ public class MongoSessionStore extends NoSqlSessionStore update.put("$set",sets); if (!unsets.isEmpty()) update.put("$unset",unsets); - - _dbSessions.update(key,update,upsert,false,WriteConcern.SAFE); - - + WriteResult res = _dbSessions.update(key,update,upsert,false,WriteConcern.SAFE); if (LOG.isDebugEnabled()) - LOG.debug("Save:db.sessions.update( {}, {} )", key, update); + LOG.debug("Save:db.sessions.update( {}, {},{} )", key, update, res); } @@ -648,7 +646,7 @@ public class MongoSessionStore extends NoSqlSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionStoreFactory.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreFactory.java similarity index 78% rename from jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionStoreFactory.java rename to jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreFactory.java index e1a28afe138..056fd6abdb6 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionStoreFactory.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStoreFactory.java @@ -21,20 +21,20 @@ package org.eclipse.jetty.nosql.mongodb; import java.net.UnknownHostException; -import org.eclipse.jetty.server.session.AbstractSessionStoreFactory; +import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.server.session.SessionHandler; -import org.eclipse.jetty.server.session.SessionStore; +import org.eclipse.jetty.server.session.SessionDataStore; import com.mongodb.Mongo; import com.mongodb.MongoException; /** - * MongoSessionStoreFactory + * MongoSessionDataStoreFactory * * */ -public class MongoSessionStoreFactory extends AbstractSessionStoreFactory +public class MongoSessionDataStoreFactory extends AbstractSessionDataStoreFactory { String _dbName; String _collectionName; @@ -76,12 +76,12 @@ public class MongoSessionStoreFactory extends AbstractSessionStoreFactory /** * @throws MongoException * @throws UnknownHostException - * @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler) + * @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override - public SessionStore getSessionStore(SessionHandler handler) throws Exception + public SessionDataStore getSessionDataStore(SessionHandler handler) throws Exception { - MongoSessionStore store = new MongoSessionStore(); + MongoSessionDataStore store = new MongoSessionDataStore(); store.setGracePeriodSec(getGracePeriodSec()); store.setDBCollection(new Mongo().getDB(getDbName()).getCollection(getCollectionName())); return store; diff --git a/jetty-server/src/main/config/etc/sessions/file/session-store.xml b/jetty-server/src/main/config/etc/sessions/file/session-store.xml index 0f0461e64ab..e6e3c71b78f 100644 --- a/jetty-server/src/main/config/etc/sessions/file/session-store.xml +++ b/jetty-server/src/main/config/etc/sessions/file/session-store.xml @@ -9,7 +9,7 @@ - + diff --git a/jetty-server/src/main/config/etc/sessions/jdbc/session-store.xml b/jetty-server/src/main/config/etc/sessions/jdbc/session-store.xml index 0a212a649c6..238bbad5a96 100644 --- a/jetty-server/src/main/config/etc/sessions/jdbc/session-store.xml +++ b/jetty-server/src/main/config/etc/sessions/jdbc/session-store.xml @@ -9,7 +9,7 @@ - + @@ -18,7 +18,7 @@ + class="org.eclipse.jetty.server.session.JDBCSessionDataStore.SessionTableSchema"> diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index cf5735e3d2c..dcd3aaed957 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -191,7 +191,6 @@ public class Request implements HttpServletRequest private String _readerEncoding; private InetSocketAddress _remote; private String _requestedSessionId; - private Map _savedNewSessions; private UserIdentity.Scope _scope; private HttpSession _session; private SessionHandler _sessionHandler; @@ -1716,13 +1715,6 @@ public class Request implements HttpServletRequest return false; } - /* ------------------------------------------------------------ */ - public HttpSession recoverNewSession(Object key) - { - if (_savedNewSessions == null) - return null; - return _savedNewSessions.get(key); - } /* ------------------------------------------------------------ */ /** @@ -1840,10 +1832,6 @@ public class Request implements HttpServletRequest _parameters = null; _paramsExtracted = false; _inputState = __NONE; - - if (_savedNewSessions != null) - _savedNewSessions.clear(); - _savedNewSessions=null; _multiPartInputStream = null; _remote=null; _input.recycle(); @@ -1875,13 +1863,6 @@ public class Request implements HttpServletRequest _requestAttributeListeners.remove(listener); } - /* ------------------------------------------------------------ */ - public void saveNewSession(Object key, HttpSession session) - { - if (_savedNewSessions == null) - _savedNewSessions = new HashMap<>(); - _savedNewSessions.put(key,session); - } /* ------------------------------------------------------------ */ public void setAsyncSupported(boolean supported,String source) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java index 1c5e03d1f38..8b4b7f1e705 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java @@ -33,19 +33,57 @@ import org.eclipse.jetty.util.thread.Locker.Lock; /** * AbstractSessionCache * - * Basic behaviour for maintaining an in-memory store of Session objects and - * making sure that any backing SessionDataStore is kept in sync. + * A base implementation of the SessionCache interface for managing a set of + * Session objects pertaining to a context in memory. + * + * This implementation ensures that multiple requests for the same session id + * always return the same Session object. + * + * It will delay writing out a session to the SessionDataStore until the + * last request exists the session. If the SessionDataStore supports passivation + * then the session passivation and activation listeners are called appropriately as + * the session is written. Additionally the session can be evicted from the + * AbstractSessionCache after passivation on write. + * + * This implementation also supports evicting idle Session objects. An idle Session + * is one that is still valid, has not expired, but has not been accessed by a + * request for a configurable amount of time. An idle session will be first + * passivated before eviction from the cache. + * */ public abstract class AbstractSessionCache extends AbstractLifeCycle implements SessionCache { final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); - protected SessionStore _sessionStore; - protected final SessionHandler _handler; - protected SessionContext _context; - protected int _idlePassivationTimeoutSec; - private boolean _passivateOnComplete; + /** + * The authoritative source of session data + */ + protected SessionDataStore _sessionDataStore; + /** + * The SessionHandler related to this SessionCache + */ + protected final SessionHandler _handler; + + /** + * Information about the context to which this SessionCache pertains + */ + protected SessionContext _context; + + + /** + * When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs) + */ + protected int _evictionPolicy; + + + /** + * If true, a session that will be evicted from the cache because it has been + * inactive too long will be saved before being evicted. + */ + protected boolean _saveOnInactiveEviction; + + /** * Create a new Session object from pre-existing session data @@ -115,7 +153,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements */ public PlaceHolderSession(SessionData data) { - super(data); + super(null, data); } } @@ -124,9 +162,9 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements /** * */ - public AbstractSessionCache (SessionHandler manager) + public AbstractSessionCache (SessionHandler handler) { - _handler = manager; + _handler = handler; } @@ -157,7 +195,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements @Override protected void doStart() throws Exception { - if (_sessionStore == null) + if (_sessionDataStore == null) throw new IllegalStateException ("No session data store configured"); if (_handler == null) @@ -166,8 +204,8 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements if (_context == null) throw new IllegalStateException ("No ContextId"); - _sessionStore.initialize(_context); - _sessionStore.start(); + _sessionDataStore.initialize(_context); + _sessionDataStore.start(); super.doStart(); @@ -179,50 +217,51 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements @Override protected void doStop() throws Exception { - _sessionStore.stop(); + _sessionDataStore.stop(); super.doStop(); } /** - * @return the SessionStore or null if there isn't one + * @return the SessionDataStore or null if there isn't one */ - public SessionStore getSessionStore() + public SessionDataStore getSessionDataStore() { - return _sessionStore; + return _sessionDataStore; } /** - * @see org.eclipse.jetty.server.session.SessionCache#setSessionStore(org.eclipse.jetty.server.session.SessionStore) + * @see org.eclipse.jetty.server.session.SessionCache#setSessionDataStore(org.eclipse.jetty.server.session.SessionDataStore) */ - public void setSessionStore(SessionStore sessionStore) + public void setSessionDataStore(SessionDataStore sessionStore) { - _sessionStore = sessionStore; + _sessionDataStore = sessionStore; } - - /** - * @see org.eclipse.jetty.server.session.SessionCache#getIdlePassivationTimeoutSec() - */ - public int getIdlePassivationTimeoutSec() - { - return _idlePassivationTimeoutSec; - } + /** - * @see org.eclipse.jetty.server.session.SessionCache#setIdlePassivationTimeoutSec(int) + * @see org.eclipse.jetty.server.session.SessionCache#getEvictionPolicy() */ - public void setIdlePassivationTimeoutSec(int idleTimeoutSec) + public int getEvictionPolicy() { - _idlePassivationTimeoutSec = idleTimeoutSec; - + return _evictionPolicy; } - - + /** + * -1 means we never evict inactive sessions. + * 0 means we evict a session after the last request for it exits + * >0 is the number of seconds after which we evict inactive sessions from the cache + * + * @see org.eclipse.jetty.server.session.SessionCache#setEvictionPolicy(int) + */ + public void setEvictionPolicy(int evictionTimeout) + { + _evictionPolicy = evictionTimeout; + } /** @@ -244,14 +283,14 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements { session = doGet(id); - if (_sessionStore == null) + if (_sessionDataStore == null) break; //can't load any session data so just return null or the session object if (session == null) { if (LOG.isDebugEnabled()) - LOG.debug("Session not found locally, attempting to load"); - + LOG.debug("Session {} not found locally, attempting to load", id); + //didn't get a session, try and create one and put in a placeholder for it PlaceHolderSession phs = new PlaceHolderSession (new SessionData(id, null, null,0,0,0,0)); Lock phsLock = phs.lock(); @@ -286,7 +325,8 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements else { //successfully swapped in the session - session.setTimeout (); //TODO start the session timer + session.setResident(true); + session.updateInactivityTimer(); phsLock.close(); break; } @@ -307,8 +347,8 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements phsLock.close(); try (Lock lock = s.lock()) { - //is it a placeholder? or is it passivated? In both cases, chuck it away and start again - if (s.isPassivated() || s instanceof PlaceHolderSession) + //is it a placeholder? or is a non-resident session? In both cases, chuck it away and start again + if (!s.isResident() || s instanceof PlaceHolderSession) { session = null; continue; @@ -323,14 +363,14 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements { //check the session returned try (Lock lock = session.lock()) - { + { //is it a placeholder? or is it passivated? In both cases, chuck it away and start again - if (session.isPassivated() || session instanceof PlaceHolderSession) + if (!session.isResident()|| session instanceof PlaceHolderSession) { session = null; continue; } - + //got the session break; } @@ -355,24 +395,23 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements SessionData data = null; Session session = null; - if (_sessionStore == null) + if (_sessionDataStore == null) return null; //can't load it try { - data =_sessionStore.load(id); + data =_sessionDataStore.load(id); if (data == null) //session doesn't exist return null; session = newSession(data); - session.setSessionHandler(_handler); return session; } catch (UnreadableSessionDataException e) { //can't load the session, delete it - _sessionStore.delete(id); + _sessionDataStore.delete(id); throw e; } } @@ -380,10 +419,15 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements /** * Put the Session object back into the session store. * - * This should be called by Session.complete when a request exists the session. + * This should be called when a request exists the session. Only when the last + * simultaneous request exists the session will any action be taken. * - * If the session manager supports a session data store, write the - * session data through to the session data store. + * If there is a SessionDataStore write the session data through to it. + * + * If the SessionDataStore supports passivation, call the passivate/active listeners. + * + * If the evictionPolicy == SessionCache.EVICT_ON_SESSION_EXIT then after we have saved + * the session, we evict it from the cache. * * @see org.eclipse.jetty.server.session.SessionCache#put(java.lang.String, org.eclipse.jetty.server.session.Session) */ @@ -393,55 +437,71 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements if (id == null || session == null) throw new IllegalArgumentException ("Put key="+id+" session="+(session==null?"null":session.getId())); - - - //if the session is new or data has changed write it to any backing store try (Lock lock = session.lock()) - { - session.setSessionHandler(_handler); - - if (session.isPassivated()) - throw new IllegalStateException ("Session "+id+" is passivated and cannot be saved"); + { + if (session.getSessionHandler() == null) + throw new IllegalStateException("Session "+id+" is not managed"); if (!session.isValid()) return; - if (_sessionStore == null) + if (_sessionDataStore == null) { - doPutIfAbsent(id, session); //ensure it is in our map + session.setResident(true); + if (doPutIfAbsent(id, session) == null) //ensure it is in our map + session.updateInactivityTimer(); return; - } + } + //don't do anything with the session until the last request for it has finished if ((session.getRequests() <= 0)) - { - //only save if all requests have finished - if (!_sessionStore.isPassivating()) + { + //save the session + if (!_sessionDataStore.isPassivating()) { //if our backing datastore isn't the passivating kind, just save the session - _sessionStore.store(id, session.getSessionData()); + _sessionDataStore.store(id, session.getSessionData()); + //if we evict on session exit, boot it from the cache + if (getEvictionPolicy() == EVICT_ON_SESSION_EXIT) + { + doDelete(session.getId()); + session.setResident(false); + } + else + { + session.setResident(true); + if (doPutIfAbsent(id,session) == null) //ensure it is in our map + session.updateInactivityTimer(); + } } else { - //backing store supports passivation + //backing store supports passivation, call the listeners session.willPassivate(); - _sessionStore.store(id, session.getSessionData()); - session.setPassivated(); - if (isPassivateOnComplete()) + _sessionDataStore.store(id, session.getSessionData()); + + if (getEvictionPolicy() == EVICT_ON_SESSION_EXIT) { //throw out the passivated session object from the map doDelete(id); + session.setResident(false); } else { //reactivate the session - session.setActive(); - session.didActivate(); - + session.didActivate(); + session.setResident(true); + if (doPutIfAbsent(id,session) == null) //ensure it is in our map + session.updateInactivityTimer(); } } } - - doPutIfAbsent(id,session); //ensure it is in our map + else + { + session.setResident(true); + if (doPutIfAbsent(id, session) == null) //ensure it is the map, but don't save it to the backing store until the last request exists + session.updateInactivityTimer(); + } } } @@ -470,7 +530,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements } //not there, so find out if session data exists for it - return _sessionStore.exists (id); + return _sessionDataStore.exists (id); } @@ -486,16 +546,21 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements //get the session, if its not in memory, this will load it Session session = get(id); + //Always delete it from the backing data store - if (_sessionStore != null) + if (_sessionDataStore != null) { - boolean dsdel = _sessionStore.delete(id); + + boolean dsdel = _sessionDataStore.delete(id); if (LOG.isDebugEnabled()) LOG.debug("Session {} deleted in db {}",id, dsdel); } //delete it from the session object store if (session != null) - session.stopTimeout(); + { + session.stopInactivityTimer(); + session.setResident(false); + } return doDelete(id); } @@ -515,70 +580,64 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements return Collections.emptySet(); if (LOG.isDebugEnabled()) - LOG.debug("SessionStore checking expiration on {}", candidates); - return _sessionStore.getExpired(candidates); + LOG.debug("SessionDataStore checking expiration on {}", candidates); + return _sessionDataStore.getExpired(candidates); } - - - - /** - * If the SessionDataStore supports passivation, - * write the session to the backing data store. + * Check a session for being inactive and + * thus being able to be evicted, if eviction + * is enabled. * - * @param id identity of session to passivate + * + * @param session */ - @Override - public void passivateIdleSession(String id) + public void checkInactiveSession (Session session) { - if (!isStarted()) + if (session == null) return; - - if (_sessionStore == null || !_sessionStore.isPassivating()) - return; //no data store to passivate or it doesn't passivate - //get the session locally - Session s = doGet(id); - - if (s == null) + try (Lock s = session.lock()) { - LOG.warn("Session {} not in this session store", s); - return; - } - - - //lock the session during passivation - try (Lock lock = s.lock()) - { - //check the session is still idle and that it doesn't have requests using it - if (s.isValid() && s.isIdleLongerThan(_idlePassivationTimeoutSec) && s.isActive() && (s.getRequests() <= 0)) - { - //TODO - do we need to check that the session exists in the session data store - //before we passivate it? If it doesn't exist, we can assume another node - //invalidated it. If the session was new, it shouldn't have been idle passivated. + if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy()) && session.isValid() && session.isResident() && session.getRequests() <= 0) + { + //Be careful with saveOnInactiveEviction - you may be able to re-animate a session that was + //being managed on another node and has expired. try { if (LOG.isDebugEnabled()) - LOG.debug("Passivating idle session {}", id); - s.willPassivate(); - _sessionStore.store(id, s.getSessionData()); - s.setPassivated(); - s.stopTimeout(); - doDelete(id); //Take the session object of this session store + LOG.debug("Evicting idle session {}", session.getId()); + + //save before evicting + if (isSaveOnInactiveEviction() && _sessionDataStore != null) + { + if (_sessionDataStore.isPassivating()) + session.willPassivate(); + + _sessionDataStore.store(session.getId(), session.getSessionData()); + } + + //evict + // session.stopInactivityTimer(); + + doDelete(session.getId()); //detach from this cache + session.setResident(false); } catch (Exception e) { - LOG.warn("Passivation of idle session {} failed", id, e); - s.setPassivated(); //set it as passivated so it can't be used - doDelete(id); //detach it + LOG.warn("Passivation of idle session {} failed", session.getId(), e); + doDelete(session.getId()); //detach it + session.setResident(false); } } } - } + + + + /** @@ -604,10 +663,10 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements session.getSessionData().setDirty(true); //ensure we will try to write the session out doPutIfAbsent(newId, session); //put the new id into our map doDelete (oldId); //take old out of map - if (_sessionStore != null) + if (_sessionDataStore != null) { - _sessionStore.delete(oldId); //delete the session data with the old id - _sessionStore.store(newId, session.getSessionData()); //save the session data with the new id + _sessionDataStore.delete(oldId); //delete the session data with the old id + _sessionDataStore.store(newId, session.getSessionData()); //save the session data with the new id } LOG.info("Session id {} swapped for new id {}", oldId, newId); return session; @@ -615,25 +674,37 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements } - public void setPassivateOnComplete (boolean passivateOnComplete) + /** + * @see org.eclipse.jetty.server.session.SessionCache#setSaveOnInactiveEviction(boolean) + */ + @Override + public void setSaveOnInactiveEviction (boolean saveOnEvict) { - _passivateOnComplete = passivateOnComplete; + _saveOnInactiveEviction = saveOnEvict; } - public boolean isPassivateOnComplete () + /** + * Whether we should save a session that has been inactive before + * we boot it from the cache. + * + * @return true if an inactive session will be saved before being evicted + */ + @Override + public boolean isSaveOnInactiveEviction () { - return _passivateOnComplete; + return _saveOnInactiveEviction; } - + + /** * @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long) */ @Override public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs) { - Session session = newSession(request, _sessionStore.newSessionData(id, time, time, time, maxInactiveMs)); - session.setSessionHandler(_handler); + if (LOG.isDebugEnabled()) LOG.debug("Creating new session id="+id); + Session session = newSession(request, _sessionDataStore.newSessionData(id, time, time, time, maxInactiveMs)); return session; } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java similarity index 85% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java index 03afdd8fdec..9e4f565130a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java @@ -25,11 +25,11 @@ import java.util.Set; import org.eclipse.jetty.util.component.AbstractLifeCycle; /** - * AbstractSessionStore + * AbstractSessionDataStore * * */ -public abstract class AbstractSessionStore extends AbstractLifeCycle implements SessionStore +public abstract class AbstractSessionDataStore extends AbstractLifeCycle implements SessionDataStore { protected SessionContext _context; //context associated with this session data store protected int _gracePeriodSec = 60 * 60; //default of 1hr @@ -51,14 +51,14 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements * Implemented by subclasses to resolve which sessions this node * should attempt to expire. * - * @param candidates the ids of sessions the SessionStore thinks has expired + * @param candidates the ids of sessions the SessionDataStore thinks has expired * @return the reconciled set of session ids that this node should attempt to expire */ public abstract Set doGetExpired (Set candidates); /** - * @see org.eclipse.jetty.server.session.SessionStore#initialize(org.eclipse.jetty.server.session.SessionContext) + * @see org.eclipse.jetty.server.session.SessionDataStore#initialize(org.eclipse.jetty.server.session.SessionContext) */ public void initialize (SessionContext context) { @@ -68,7 +68,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements } /** - * @see org.eclipse.jetty.server.session.SessionStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData) + * @see org.eclipse.jetty.server.session.SessionDataStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData) */ @Override public void store(String id, SessionData data) throws Exception @@ -94,7 +94,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(java.util.Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set) */ @Override public Set getExpired(Set candidates) @@ -113,7 +113,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements /** - * @see org.eclipse.jetty.server.session.SessionStore#newSessionData(java.lang.String, long, long, long, long) + * @see org.eclipse.jetty.server.session.SessionDataStore#newSessionData(java.lang.String, long, long, long, long) */ @Override public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreFactory.java similarity index 90% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionStoreFactory.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreFactory.java index 359d75c47b9..2db3f6d4a4d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStoreFactory.java @@ -20,11 +20,11 @@ package org.eclipse.jetty.server.session; /** - * AbstractSessionStoreFactory + * AbstractSessionDataStoreFactory * * */ -public abstract class AbstractSessionStoreFactory implements SessionStoreFactory +public abstract class AbstractSessionDataStoreFactory implements SessionDataStoreFactory { int _gracePeriodSec; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java index 68d00f0fbd3..60f609dcb83 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java @@ -26,43 +26,42 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle; /** * CachingSessionStore * - * A SessionStore is a mechanism for (persistently) storing data associated with sessions. - * This implementation delegates to a pluggable SessionStore for actually storing the + * A SessionDataStore is a mechanism for (persistently) storing data associated with sessions. + * This implementation delegates to a pluggable SessionDataStore for actually storing the * session data. It also uses a pluggable cache implementation in front of the - * delegate SessionStore to improve performance: accessing most persistent store + * delegate SessionDataStore to improve performance: accessing most persistent store * technology can be expensive time-wise, so introducing a fronting cache * can increase performance. The cache implementation can either be a local cache, - * a remote cache, or a clustered cache. If the cache is cluster-wide then this can - * help with deployments without a sticky load balancer (but this is not ideal). + * a remote cache, or a clustered cache. + * + * The implementation here will try to read first from the cache and fallback to + * reading from the SessionDataStore if the session key is not found. On writes, the + * session data is written first to the SessionDataStore, and then to the cache. On + * deletes, the data is deleted first from the SessionDataStore, and then from the + * cache. There is no transaction manager ensuring atomic operations, so it is + * possible that failures can result in cache inconsistency. + * */ -public class CachingSessionStore extends AbstractLifeCycle implements SessionStore +public class CachingSessionStore extends AbstractLifeCycle implements SessionDataStore { /** - * Cache - * - * An interface that represents the contract with the particular cache - * implementation, eg memcache, infinispan etc + * The actual store for the session data */ - public interface Cache - { - public SessionData get (String id); //get cached value - public boolean putIfAbsent (String id, SessionData data); //only insert if no mapping for key already - public boolean remove (String id); //remove the mapping for key, returns false if no mapping - public void put (String id, SessionData data); //overwrite or add the mapping - public void initialize(SessionContext context); - } + protected SessionDataStore _store; - protected SessionStore _store; - protected Cache _cache; + /** + * The fronting cache + */ + protected SessionDataMap _cache; /** * @param cache * @param store */ - public CachingSessionStore (Cache cache, SessionStore store) + public CachingSessionStore (SessionDataMap cache, SessionDataStore store) { _cache = cache; _store = store; @@ -70,9 +69,9 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto /** - * @return + * @return the delegate session store */ - public SessionStore getSessionStore() + public SessionDataStore getSessionStore() { return _store; } @@ -80,63 +79,52 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto /** - * @return + * @return the cache */ - public Cache getSessionStoreCache () + public SessionDataMap getCache () { return _cache; } /** - * @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String) */ @Override public SessionData load(String id) throws Exception { + SessionData d = null; + + //check to see if the session data is already in the cache - SessionData d = _cache.get(id); - if (d == null) - { - //not in the cache, go get it from the store - d = _store.load(id); + d = _cache.load(id); - if (d != null) - { - //put it into the cache, unless another thread/node has put it into the cache - boolean inserted = _cache.putIfAbsent(id, d); - if (!inserted) - { - //some other thread/node put this data into the cache, so get it from there - SessionData d2 = _cache.get(id); + if (d != null) + return d; //cache hit + + //cache miss - go get it from the store + d = _store.load(id); - if (d2 != null) - d = d2; - //else: The cache either timed out the entry, or maybe the session data was being removed, and we're about to resurrect it! - } - } - } return d; } /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String) */ @Override public boolean delete(String id) throws Exception { - //delete from the store and from the cache + //delete from the store boolean deleted = _store.delete(id); - - //TODO what to do if couldn't remove from the cache? - _cache.remove(id); + //and from the cache + _cache.delete(id); return deleted; } /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set getExpired(Set candidates) @@ -145,8 +133,10 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto return _store.getExpired(candidates); } + + /** - * @see org.eclipse.jetty.server.session.SessionStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData) + * @see org.eclipse.jetty.server.session.SessionDataStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData) */ @Override public void store(String id, SessionData data) throws Exception @@ -155,7 +145,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto _store.store(id, data); //then update the cache with written data - _cache.put(id,data); + _cache.store(id,data); } @@ -173,7 +163,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto } /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() @@ -182,13 +172,13 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto } /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) throws Exception { //check the cache first - SessionData data = _cache.get(id); + SessionData data = _cache.load(id); if (data != null) return true; @@ -198,7 +188,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto /** - * @see org.eclipse.jetty.server.session.SessionStore#initialize(org.eclipse.jetty.server.session.SessionContext) + * @see org.eclipse.jetty.server.session.SessionDataStore#initialize(org.eclipse.jetty.server.session.SessionContext) */ @Override public void initialize(SessionContext context) @@ -209,7 +199,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto } /** - * @see org.eclipse.jetty.server.session.SessionStore#newSessionData(java.lang.String, long, long, long, long) + * @see org.eclipse.jetty.server.session.SessionDataStore#newSessionData(java.lang.String, long, long, long, long) */ @Override public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStoreFactory.java index c3793c3e858..a7469b13011 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStoreFactory.java @@ -24,34 +24,34 @@ package org.eclipse.jetty.server.session; * * */ -public class CachingSessionStoreFactory extends AbstractSessionStoreFactory +public class CachingSessionStoreFactory extends AbstractSessionDataStoreFactory { /** - * The SessionStore that will store session data. + * The SessionDataStore that will store session data. */ - protected SessionStoreFactory _backingSessionStoreFactory; + protected SessionDataStoreFactory _backingSessionStoreFactory; /** - * @param factory The factory for the actual SessionStore that the + * @param factory The factory for the actual SessionDataStore that the * CachingSessionStore will delegate to */ - public void setBackingSessionStoreFactory (SessionStoreFactory factory) + public void setBackingSessionStoreFactory (SessionDataStoreFactory factory) { _backingSessionStoreFactory = factory; } /** - * @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler) + * @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override - public SessionStore getSessionStore(SessionHandler handler) throws Exception + public SessionDataStore getSessionDataStore(SessionHandler handler) throws Exception { // TODO configure and create a cache! - return new CachingSessionStore(null, _backingSessionStoreFactory.getSessionStore(handler)); + return new CachingSessionStore(null, _backingSessionStoreFactory.getSessionDataStore(handler)); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java index d1d42903d26..27f15e6e99f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java @@ -146,14 +146,14 @@ public class DefaultSessionCache extends AbstractSessionCache for (Session session: _sessions.values()) { //if we have a backing store and the session is dirty make sure it is written out - if (_sessionStore != null) + if (_sessionDataStore != null) { if (session.getSessionData().isDirty()) { session.willPassivate(); try { - _sessionStore.store(session.getId(), session.getSessionData()); + _sessionDataStore.store(session.getId(), session.getSessionData()); } catch (Exception e) { @@ -186,7 +186,7 @@ public class DefaultSessionCache extends AbstractSessionCache @Override public Session newSession(HttpServletRequest request, SessionData data) { - Session s = new Session(request,data); + Session s = new Session(getSessionHandler(),request, data); return s; } @@ -199,7 +199,7 @@ public class DefaultSessionCache extends AbstractSessionCache @Override public Session newSession(SessionData data) { - Session s = new Session (data); + Session s = new Session (getSessionHandler(), data); return s; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCacheFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCacheFactory.java index d8acb5bdfc9..0a38d22a61e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCacheFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCacheFactory.java @@ -26,53 +26,54 @@ package org.eclipse.jetty.server.session; */ public class DefaultSessionCacheFactory implements SessionCacheFactory { - int _idlePassivationTimeoutSec; - boolean _passivateOnComplete; + int _evictionTimeout; + boolean _saveOnInactiveEvict; - /** - * @return the passivateOnComplete - */ - public boolean isPassivateOnComplete() + + + public int getEvictionTimeout() { - return _passivateOnComplete; + return _evictionTimeout; } - /** - * @param passivateOnComplete the passivateOnComplete to set - */ - public void setPassivateOnComplete(boolean passivateOnComplete) - { - _passivateOnComplete = passivateOnComplete; - } - /** - * @return the idlePassivationTimeoutSec - */ - public int getIdlePassivationTimeoutSec() + + public void setEvictionTimeout(int evictionTimeout) { - return _idlePassivationTimeoutSec; + _evictionTimeout = evictionTimeout; } - /** - * @param idlePassivationTimeoutSec the idlePassivationTimeoutSec to set - */ - public void setIdlePassivationTimeoutSec(int idlePassivationTimeoutSec) + + + public boolean isSaveOnInactiveEvict() { - _idlePassivationTimeoutSec = idlePassivationTimeoutSec; + return _saveOnInactiveEvict; } + + + + public void setSaveOnInactiveEvict(boolean saveOnInactiveEvict) + { + _saveOnInactiveEvict = saveOnInactiveEvict; + } + + + + + /** - * @see org.eclipse.jetty.server.session.SessionCacheFactory#getSessionCache(SessionHandler) + * @see org.eclipse.jetty.server.session.SessionCacheFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override public SessionCache getSessionCache (SessionHandler handler) { DefaultSessionCache cache = new DefaultSessionCache(handler); - cache.setIdlePassivationTimeoutSec(_idlePassivationTimeoutSec); - cache.setPassivateOnComplete(_passivateOnComplete); + cache.setEvictionPolicy(_evictionTimeout); + cache.setSaveOnInactiveEviction(_saveOnInactiveEvict); return cache; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java index f54def3911f..a4f88a937c4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java @@ -208,6 +208,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio return cluster_id; } + // Else reuse any new session ID already defined for this request. String new_id=(String)request.getAttribute(__NEW_SESSION_ID); if (new_id!=null&&isIdInUse(new_id)) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java similarity index 95% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java index b094b337033..38c0c003f56 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java @@ -42,11 +42,11 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - * FileSessionStore + * FileSessionDataStore * * A file-based store of session data. */ -public class FileSessionStore extends AbstractSessionStore +public class FileSessionDataStore extends AbstractSessionDataStore { private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); private File _storeDir; @@ -92,7 +92,7 @@ public class FileSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String) */ @Override public boolean delete(String id) throws Exception @@ -112,7 +112,7 @@ public class FileSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set doGetExpired(final Set candidates) @@ -166,7 +166,7 @@ public class FileSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String) */ @Override public SessionData load(String id) throws Exception @@ -220,7 +220,7 @@ public class FileSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception @@ -262,7 +262,7 @@ public class FileSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() @@ -274,7 +274,7 @@ public class FileSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) throws Exception diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStoreFactory.java similarity index 82% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStoreFactory.java index 72efad5be63..3e2424c2755 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStoreFactory.java @@ -22,11 +22,11 @@ package org.eclipse.jetty.server.session; import java.io.File; /** - * FileSessionStoreFactory + * FileSessionDataStoreFactory * * */ -public class FileSessionStoreFactory extends AbstractSessionStoreFactory +public class FileSessionDataStoreFactory extends AbstractSessionDataStoreFactory { boolean _deleteUnrestorableFiles; File _storeDir; @@ -69,12 +69,12 @@ public class FileSessionStoreFactory extends AbstractSessionStoreFactory /** - * @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(SessionHandler) + * @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override - public SessionStore getSessionStore(SessionHandler handler) + public SessionDataStore getSessionDataStore(SessionHandler handler) { - FileSessionStore fsds = new FileSessionStore(); + FileSessionDataStore fsds = new FileSessionDataStore(); fsds.setDeleteUnrestorableFiles(isDeleteUnrestorableFiles()); fsds.setStoreDir(getStoreDir()); fsds.setGracePeriodSec(getGracePeriodSec()); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java similarity index 98% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java index f732dbe7d9a..e55e89f04de 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java @@ -42,11 +42,11 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - * JDBCSessionStore + * JDBCSessionDataStore * * Session data stored in database */ -public class JDBCSessionStore extends AbstractSessionStore +public class JDBCSessionDataStore extends AbstractSessionDataStore { final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); @@ -610,7 +610,7 @@ public class JDBCSessionStore extends AbstractSessionStore - public JDBCSessionStore () + public JDBCSessionDataStore () { super (); } @@ -662,7 +662,7 @@ public class JDBCSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String) */ @Override public SessionData load(String id) throws Exception @@ -758,7 +758,7 @@ public class JDBCSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String) */ @Override public boolean delete(String id) throws Exception @@ -779,7 +779,7 @@ public class JDBCSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception @@ -884,7 +884,7 @@ public class JDBCSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set doGetExpired(Set candidates) @@ -1083,7 +1083,7 @@ public class JDBCSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() @@ -1096,7 +1096,7 @@ public class JDBCSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreFactory.java similarity index 80% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreFactory.java index d820a3167f9..261fec796c4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStoreFactory.java @@ -20,11 +20,11 @@ package org.eclipse.jetty.server.session; /** - * JDBCSessionStoreFactory + * JDBCSessionDataStoreFactory * * */ -public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory +public class JDBCSessionDataStoreFactory extends AbstractSessionDataStoreFactory { /** @@ -34,7 +34,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory /** * */ - JDBCSessionStore.SessionTableSchema _schema; + JDBCSessionDataStore.SessionTableSchema _schema; /** * */ @@ -82,12 +82,12 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory /** - * @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(SessionHandler) + * @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override - public SessionStore getSessionStore(SessionHandler handler) + public SessionDataStore getSessionDataStore(SessionHandler handler) { - JDBCSessionStore ds = new JDBCSessionStore(); + JDBCSessionDataStore ds = new JDBCSessionDataStore(); ds.setDatabaseAdaptor(_adaptor); ds.setSessionTableSchema(_schema); ds.setDeleteUnloadableSessions(_deleteUnloadableSessions); @@ -109,7 +109,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory /** * @param schema */ - public void setSessionTableSchema (JDBCSessionStore.SessionTableSchema schema) + public void setSessionTableSchema (JDBCSessionDataStore.SessionTableSchema schema) { _schema = schema; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java similarity index 71% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java index 573bcc6bd70..2c56d898257 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java @@ -22,15 +22,15 @@ package org.eclipse.jetty.server.session; import java.util.Set; /** - * NullSessionStore + * NullSessionDataStore * * */ -public class NullSessionStore extends AbstractSessionStore +public class NullSessionDataStore extends AbstractSessionDataStore { /** - * @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String) */ @Override public SessionData load(String id) throws Exception @@ -40,7 +40,7 @@ public class NullSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#newSessionData(java.lang.String, long, long, long, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#newSessionData(java.lang.String, long, long, long, long) */ @Override public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs) @@ -49,7 +49,7 @@ public class NullSessionStore extends AbstractSessionStore } /** - * @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String) */ @Override public boolean delete(String id) throws Exception @@ -59,7 +59,7 @@ public class NullSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception @@ -69,7 +69,7 @@ public class NullSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set) + * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set) */ @Override public Set doGetExpired(Set candidates) @@ -79,7 +79,7 @@ public class NullSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#isPassivating() + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() */ @Override public boolean isPassivating() @@ -89,7 +89,7 @@ public class NullSessionStore extends AbstractSessionStore /** - * @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String) + * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/Session.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/Session.java index 1eeeece0361..6b1009147d5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/Session.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/Session.java @@ -68,12 +68,7 @@ public class Session implements SessionHandler.SessionIf public enum State {VALID, INVALID, INVALIDATING}; - /** - * PassivationState - * - * States of a session - either active in memory or passivated to persistent store - */ - public enum PassivationState {PASSIVATED, ACTIVE}; + protected SessionData _sessionData; //the actual data associated with a session @@ -84,22 +79,25 @@ public class Session implements SessionHandler.SessionIf private boolean _newSession; private State _state = State.VALID; //state of the session:valid,invalid or being invalidated private Locker _lock = new Locker(); //sync lock - private PassivationState _passivationState = PassivationState.ACTIVE; //passivated or not - private InspectionTimeout _inspectionTimeout = null; + private boolean _resident = false; + private SessionInactivityTimeout _sessionInactivityTimer = null; /* ------------------------------------------------------------- */ /** - * InspectionTimeout + * SessionInactivityTimeout * * */ - public class InspectionTimeout extends IdleTimeout + public class SessionInactivityTimeout extends IdleTimeout { - public InspectionTimeout() + /** + * + */ + public SessionInactivityTimeout() { super(getSessionHandler().getScheduler()); } @@ -112,7 +110,7 @@ public class Session implements SessionHandler.SessionIf { //called when the timer goes off if (LOG.isDebugEnabled()) LOG.debug("Timer expired for session {}", getId()); - getSessionHandler().inspect(Session.this); + getSessionHandler().sessionInactivityTimerExpired(Session.this); } /** @@ -127,7 +125,7 @@ public class Session implements SessionHandler.SessionIf // BUT if passivated out to disk, do we really want this timer to keep going off? try (Lock lock = _lock.lockIfNotHeld()) { - return isValid() && !isPassivated(); + return isValid() && isResident(); } } @@ -148,12 +146,13 @@ public class Session implements SessionHandler.SessionIf /* ------------------------------------------------------------- */ /** * Create a new session - * + * @param handler TODO * @param request the request the session should be based on * @param data the session data */ - public Session (HttpServletRequest request, SessionData data) + public Session (SessionHandler handler, HttpServletRequest request, SessionData data) { + _handler = handler; _sessionData = data; _newSession = true; _requests = 1; //access will not be called on this new session, but we are obviously in a request @@ -164,10 +163,12 @@ public class Session implements SessionHandler.SessionIf /* ------------------------------------------------------------- */ /** * Re-create an existing session + * @param handler TODO * @param data the session data */ - public Session (SessionData data) + public Session (SessionHandler handler, SessionData data) { + _handler = handler; _sessionData = data; } @@ -189,11 +190,6 @@ public class Session implements SessionHandler.SessionIf - /* ------------------------------------------------------------- */ - public void setSessionHandler (SessionHandler manager) - { - _handler = manager; - } /* ------------------------------------------------------------- */ @@ -455,9 +451,9 @@ public class Session implements SessionHandler.SessionIf try (Lock lock = _lock.lockIfNotHeld()) { _sessionData.setMaxInactiveMs((long)secs*1000L); - _sessionData.setExpiry(_sessionData.calcExpiry()); + _sessionData.calcAndSetExpiry(); _sessionData.setDirty(true); - setTimeout(); + updateInactivityTimer(); if (LOG.isDebugEnabled()) { if (secs <= 0) @@ -470,53 +466,77 @@ public class Session implements SessionHandler.SessionIf /** - * + * Set the inactivity timer to the smaller of the session maxInactivity + * (ie session-timeout from web.xml), or the inactive eviction time. */ - public void setTimeout () + public void updateInactivityTimer () { try (Lock lock = _lock.lockIfNotHeld()) { - if (LOG.isDebugEnabled())LOG.debug("Set timeout called"); - long maxInactive = _sessionData.getMaxInactiveMs(); - long maxIdle = TimeUnit.SECONDS.toMillis(getSessionHandler().getSessionStore().getIdlePassivationTimeoutSec()); + if (LOG.isDebugEnabled())LOG.debug("updateInactivityTimer"); + long maxInactive = _sessionData.getMaxInactiveMs(); + int evictionPolicy = getSessionHandler().getSessionCache().getEvictionPolicy(); - if (maxInactive <= 0 && maxIdle <=0) - { - //session is immortal and idle passivation is not supported - if (_inspectionTimeout != null) - _inspectionTimeout.setIdleTimeout(-1); - - if (LOG.isDebugEnabled()) LOG.debug("Session maxInactive <= 0 && idlePassivation <=0: timer cancelled"); - return; - } - - if (_inspectionTimeout == null) - _inspectionTimeout = new InspectionTimeout(); - - //set the inspection timer to the smaller of the maxIdle interval or the idlePassivation interval - long timeout = 0; if (maxInactive <= 0) - timeout = maxIdle; - else if (maxIdle <= 0) - timeout = maxInactive; + { + //sessions are immortal, they never expire + if (evictionPolicy < SessionCache.EVICT_ON_INACTIVITY) + { + //we do not want to evict inactive sessions + setInactivityTimer(-1L); + if (LOG.isDebugEnabled()) LOG.debug("Session is immortal && never evict: timer cancelled"); + } + else + { + //sessions are immortal but we want to evict after inactivity + setInactivityTimer(TimeUnit.SECONDS.toMillis(evictionPolicy)); + if (LOG.isDebugEnabled()) LOG.debug("Session is immortal; evict after {} sec inactivity", evictionPolicy); + } + } else - timeout = Math.min(maxInactive, maxIdle); - - _inspectionTimeout.setIdleTimeout(timeout); - if (LOG.isDebugEnabled()) LOG.debug("Session timer(ms)={}", timeout); + { + //sessions are not immortal + if (evictionPolicy < SessionCache.EVICT_ON_INACTIVITY) + { + //don't want to evict inactive sessions, set the timer for the session's maxInactive setting + setInactivityTimer(_sessionData.getMaxInactiveMs()); + if (LOG.isDebugEnabled()) LOG.debug("No inactive session eviction"); + } + else + { + //set the time to the lesser of the session's maxInactive and eviction timeout + setInactivityTimer(Math.min(maxInactive, TimeUnit.SECONDS.toMillis(evictionPolicy))); + if (LOG.isDebugEnabled()) LOG.debug("Inactivity timer set to lesser of maxInactive={} and inactivityEvict={}", maxInactive, evictionPolicy); + } + } } } + + /** + * Set the inactivity timer + * + * @param ms value in millisec, -1 disables it + */ + private void setInactivityTimer (long ms) + { + if (_sessionInactivityTimer == null) + _sessionInactivityTimer = new SessionInactivityTimeout(); + _sessionInactivityTimer.setIdleTimeout(ms); + } - public void stopTimeout () + /** + * + */ + public void stopInactivityTimer () { try (Lock lock = _lock.lockIfNotHeld()) { - if (_inspectionTimeout != null) + if (_sessionInactivityTimer != null) { - _inspectionTimeout.setIdleTimeout(-1); - _inspectionTimeout = null; + _sessionInactivityTimer.setIdleTimeout(-1); + _sessionInactivityTimer = null; if (LOG.isDebugEnabled()) LOG.debug("Session timer stopped"); } } @@ -563,8 +583,8 @@ public class Session implements SessionHandler.SessionIf if (_state != State.VALID) throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" created="+_sessionData.getCreated()+" accessed="+_sessionData.getAccessed()+" lastaccessed="+_sessionData.getLastAccessed()+" maxInactiveMs="+_sessionData.getMaxInactiveMs()+" expiry="+_sessionData.getExpiry()); - if (_passivationState == PassivationState.PASSIVATED) - throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" passivated"); + if (!isResident()) + throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" not resident"); } @@ -580,8 +600,8 @@ public class Session implements SessionHandler.SessionIf if (_state == State.INVALID) throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" created="+_sessionData.getCreated()+" accessed="+_sessionData.getAccessed()+" lastaccessed="+_sessionData.getLastAccessed()+" maxInactiveMs="+_sessionData.getMaxInactiveMs()+" expiry="+_sessionData.getExpiry()); - if (_passivationState == PassivationState.PASSIVATED) - throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" passivated"); + if (!isResident()) + throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" not resident"); } @@ -762,32 +782,7 @@ public class Session implements SessionHandler.SessionIf setIdChanged(true); } - - /* ------------------------------------------------------------- */ - /* * Swap the id on a session from old to new, keeping the object - * the same. - * - * @param oldId - * @param oldExtendedId - * @param newId - * @param newExtendedId - */ - /* public void renewId (String oldId, String oldExtendedId, String newId, String newExtendedId) - { - try (Lock lock = _lock.lockIfNotHeld()) - { - checkValidForWrite(); //can't change id on invalid session - - if (!oldId.equals(getId())) - throw new IllegalStateException("Id clash detected on renewal: was "+oldId+" but is "+ getId()); - - _sessionData.setId(newId); - setExtendedId(newExtendedId); - _sessionData.setLastSaved(0); //forces an insert - _sessionData.setDirty(true); //forces an insert - } - }*/ - + /* ------------------------------------------------------------- */ /** Called by users to invalidate a session, or called by the * access method as a request enters the session if the session @@ -934,36 +929,14 @@ public class Session implements SessionHandler.SessionIf } - - + public void setResident (boolean resident) + { + _resident = resident; + } - /** - * - */ - public void setPassivated () + public boolean isResident () { - checkLocked(); - _passivationState = PassivationState.PASSIVATED; - } - - /** - * - */ - public void setActive () - { - checkLocked(); - _passivationState = PassivationState.ACTIVE; - } - - public boolean isActive () - { - checkLocked(); - return _passivationState == PassivationState.ACTIVE; - } - - public boolean isPassivated () - { - checkLocked(); - return _passivationState == PassivationState.PASSIVATED; + return _resident; } + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionCache.java index 1621c180c34..0271f2fea13 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionCache.java @@ -26,16 +26,39 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.util.component.LifeCycle; /** - * SessionStore + * SessionCache * - * A store of Session objects. This store of Session objects can be backed by - * a SessionDataStore to persist/distribute the data contained in the Session objects. + * A set of Session objects for a context that are actively being + * managed by this context instance. * - * This store of Session objects ensures that all threads within the same context on - * the same node with the same session id will share exactly the same Session object. + * Multiple requests for the same session id on the same context should always + * share the same Session object from the SessionCache. + * + * The data for the Session objects is obtained from, and written to a SessionDataStore. + * It is assumed that the SessionDataStore is the authoritative source of session data: + *
      + *
    • if the session data is not present in the SessionDataStore the session does not exist.
    • + *
    • if the session data is present in the SessionDataStore but its expiry time has passed then + * the session is deemed to have expired
    • + *
    + * + * Examples of SessionDataStores are relational or nosql databases, filesystems, or other + * distributed mechanisms. + * + * A SessionCache is optionally able to passivate a managed Session to the SessionDataStore and + * evict it from the cache if it has been in memory, but not accessed for a configurable amount of time. + * + * Implementations of the SessionCache may also implement different strategies for writing out + * Session data to the SessionDataStore. */ public interface SessionCache extends LifeCycle { + public static final int NEVER_EVICT = -1; + public static final int EVICT_ON_SESSION_EXIT = 0; + public static final int EVICT_ON_INACTIVITY = 1; //any number equal or greater is time in seconds + + + void initialize(SessionContext context); SessionHandler getSessionHandler(); Session newSession (HttpServletRequest request, String id, long time, long maxInactiveMs); @@ -47,9 +70,11 @@ public interface SessionCache extends LifeCycle Session delete (String id) throws Exception; void shutdown (); Set checkExpiration (Set candidates); - void setIdlePassivationTimeoutSec(int sec); - int getIdlePassivationTimeoutSec(); - SessionStore getSessionStore(); - void setSessionStore(SessionStore sds); - void passivateIdleSession(String id); + SessionDataStore getSessionDataStore(); + void setSessionDataStore(SessionDataStore sds); + void checkInactiveSession(Session session); + void setEvictionPolicy (int policy); + int getEvictionPolicy (); + void setSaveOnInactiveEviction (boolean saveOnEvict); + boolean isSaveOnInactiveEviction (); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java index 2e5bf37dad5..2b47aaf0d16 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionData.java @@ -66,7 +66,7 @@ public class SessionData implements Serializable _accessed = accessed; _lastAccessed = lastAccessed; _maxInactiveMs = maxInactiveMs; - _expiry = calcExpiry(); + calcAndSetExpiry(); } @@ -250,6 +250,11 @@ public class SessionData implements Serializable { return (getMaxInactiveMs() <= 0 ? 0 : (System.currentTimeMillis() + getMaxInactiveMs())); } + + public void calcAndSetExpiry () + { + setExpiry(calcExpiry()); + } public long getCreated() { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataMap.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataMap.java new file mode 100644 index 00000000000..9fefcbf02e6 --- /dev/null +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataMap.java @@ -0,0 +1,67 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.server.session; + +/** + * SessionDataMap + * + * A map style access to SessionData keyed by the session id. + */ +public interface SessionDataMap +{ + /** + * Initialize this session data store for the + * given context. A SessionDataStore can only + * be used by one context(/session manager). + * + * @param context context associated + */ + void initialize(SessionContext context); + + + /** + * Read in session data from storage + * @param id identity of session to load + * @return the SessionData matching the id + * @throws Exception if unable to load session data + */ + public SessionData load (String id) throws Exception; + + + + /** + * Write out session data to storage + * @param id identity of session to store + * @param data info of session to store + * @throws Exception if unable to write session data + */ + public void store (String id, SessionData data) throws Exception; + + + + /** + * Delete session data from storage + * @param id identity of session to delete + * @return true if the session was deleted from the permanent store + * @throws Exception if unable to delete session data + */ + public boolean delete (String id) throws Exception; + + +} \ No newline at end of file diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java similarity index 65% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java index 93a19fe1758..5e070b34ea6 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java @@ -24,32 +24,13 @@ import java.util.Set; import org.eclipse.jetty.util.component.LifeCycle; /** - * SessionStore + * SessionDataStore * * A store for the data contained in a Session object. The store * would usually be persistent. */ -public interface SessionStore extends LifeCycle -{ - /** - * Initialize this session data store for the - * given context. A SessionDataStore can only - * be used by one context(/session manager). - * - * @param context context associated - */ - void initialize(SessionContext context); - - - - /** - * Read in session data from storage - * @param id identity of session to load - * @return the SessionData matching the id - * @throws Exception if unable to load session data - */ - public SessionData load (String id) throws Exception; - +public interface SessionDataStore extends SessionDataMap, LifeCycle +{ /** * Create a new SessionData @@ -63,35 +44,13 @@ public interface SessionStore extends LifeCycle public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs); - - - /** - * Write out session data to storage - * @param id identity of session to store - * @param data info of session to store - * @throws Exception if unable to write session data - */ - public void store (String id, SessionData data) throws Exception; - - - - /** - * Delete session data from storage - * @param id identity of session to delete - * @return true if the session was deleted from the permanent store - * @throws Exception if unable to delete session data - */ - public boolean delete (String id) throws Exception; - - - /** * Called periodically, this method should search the data store * for sessions that have been expired for a 'reasonable' amount * of time. * @param candidates if provided, these are keys of sessions that - * the SessionStore thinks has expired and should be verified by the + * the SessionDataStore thinks has expired and should be verified by the * SessionDataStore * @return set of session ids */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStoreFactory.java similarity index 84% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionStoreFactory.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStoreFactory.java index 391ad54b8cb..c0a3d509ad7 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStoreFactory.java @@ -20,11 +20,11 @@ package org.eclipse.jetty.server.session; /** - * SessionStoreFactory + * SessionDataStoreFactory * * */ -public interface SessionStoreFactory +public interface SessionDataStoreFactory { - SessionStore getSessionStore (SessionHandler handler) throws Exception; + SessionDataStore getSessionDataStore (SessionHandler handler) throws Exception; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java index ed353b3916f..fd0a14739e0 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java @@ -31,6 +31,8 @@ import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; +import javax.servlet.AsyncEvent; +import javax.servlet.AsyncListener; import javax.servlet.DispatcherType; import javax.servlet.ServletException; import javax.servlet.SessionCookieConfig; @@ -144,6 +146,49 @@ public class SessionHandler extends ScopedHandler * max number of minutes that you can set. */ public final static java.math.BigDecimal MAX_INACTIVE_MINUTES = new java.math.BigDecimal(Integer.MAX_VALUE/60); + + + /** + * SessionAsyncListener + * + * Used to ensure that a request for which async has been started + * has its session completed as the request exits the context. + */ + public class SessionAsyncListener implements AsyncListener + { + private Session _session; + + public SessionAsyncListener(Session session) + { + _session = session; + } + + @Override + public void onComplete(AsyncEvent event) throws IOException + { + //An async request has completed, so we can complete the session + complete(((HttpServletRequest)event.getAsyncContext().getRequest()).getSession(false)); + } + + @Override + public void onTimeout(AsyncEvent event) throws IOException + { + + } + + @Override + public void onError(AsyncEvent event) throws IOException + { + complete(((HttpServletRequest)event.getAsyncContext().getRequest()).getSession(false)); + } + + @Override + public void onStartAsync(AsyncEvent event) throws IOException + { + event.getAsyncContext().addListener(this); + } + + } static final HttpSessionContext __nullSessionContext=new HttpSessionContext() { @@ -161,6 +206,8 @@ public class SessionHandler extends ScopedHandler } }; + + /** * Setting of max inactive interval for new sessions @@ -310,6 +357,9 @@ public class SessionHandler extends ScopedHandler */ public void complete(HttpSession session) { + if (session == null) + return; + Session s = ((SessionIf)session).getSession(); try @@ -322,6 +372,24 @@ public class SessionHandler extends ScopedHandler LOG.warn(e); } } + + + public void complete (Session session, Request request) + { + if (request.isAsyncStarted() && request.getDispatcherType() == DispatcherType.REQUEST) + { + request.getAsyncContext().addListener(new SessionAsyncListener(session)); + } + else + { + complete(session); + } + //if dispatcher type is not async and not request, complete immediately (its a forward or an include) + + //else if dispatcher type is request and not async, complete immediately + + //else register an async callback completion listener that will complete the session + } /* ------------------------------------------------------------ */ @@ -341,7 +409,7 @@ public class SessionHandler extends ScopedHandler synchronized (server) { - //Get a SessionStore and a SessionDataStore, falling back to in-memory sessions only + //Get a SessionDataStore and a SessionDataStore, falling back to in-memory sessions only if (_sessionCache == null) { SessionCacheFactory ssFactory = server.getBean(SessionCacheFactory.class); @@ -350,14 +418,14 @@ public class SessionHandler extends ScopedHandler else _sessionCache = new DefaultSessionCache(this); - SessionStore sds = null; - SessionStoreFactory sdsFactory = server.getBean(SessionStoreFactory.class); + SessionDataStore sds = null; + SessionDataStoreFactory sdsFactory = server.getBean(SessionDataStoreFactory.class); if (sdsFactory != null) - sds = sdsFactory.getSessionStore(this); + sds = sdsFactory.getSessionDataStore(this); else - sds = new NullSessionStore(); + sds = new NullSessionDataStore(); - _sessionCache.setSessionStore(sds); + _sessionCache.setSessionDataStore(sds); } @@ -730,11 +798,12 @@ public class SessionHandler extends ScopedHandler Session session = _sessionCache.newSession(request, id, created, (_dftMaxIdleSecs>0?_dftMaxIdleSecs*1000L:-1)); session.setExtendedId(_sessionIdManager.getExtendedId(id, request)); session.getSessionData().setLastNode(_sessionIdManager.getWorkerName()); - session.setMaxInactiveInterval(_dftMaxIdleSecs>0?_dftMaxIdleSecs:-1); //TODO awkward: needed to kick off timer and calc expiry + if (request.isSecure()) session.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE); try { + _sessionCache.put(id, session); _sessionsCreatedStats.increment(); @@ -934,15 +1003,15 @@ public class SessionHandler extends ScopedHandler /** * @return the session store */ - public SessionCache getSessionStore () + public SessionCache getSessionCache () { return _sessionCache; } - public void setSessionStore (SessionCache store) + public void setSessionCache (SessionCache cache) { - _sessionCache = store; + _sessionCache = cache; } /* ------------------------------------------------------------ */ @@ -1214,7 +1283,18 @@ public class SessionHandler extends ScopedHandler } - public void inspect (Session session) + /** + * Each session has a timer that is configured to go off + * when either the session has not been accessed for a + * configurable amount of time, or the session itself + * has passed its expiry. + *
      + *
    • for being expired
    • + *
    • for being idle
    • + *
    + * @param session + */ + public void sessionInactivityTimerExpired (Session session) { if (session == null) return; @@ -1223,8 +1303,8 @@ public class SessionHandler extends ScopedHandler //check if the session is: //1. valid //2. expired - //3. passivatable - boolean passivate = false; + //3. idle + boolean expired = false; try (Lock lock = session.lock()) { if (LOG.isDebugEnabled()) @@ -1233,22 +1313,24 @@ public class SessionHandler extends ScopedHandler if (!session.isValid()) return; //do nothing, session is no longer valid - if (session.isExpiredAt(System.currentTimeMillis())) - { - _candidateSessionIdsForExpiry.add(session.getId()); - if (LOG.isDebugEnabled())LOG.debug("Session {} is candidate for expiry", session.getId()); - } - else if (_sessionCache.getIdlePassivationTimeoutSec() > 0 && session.isIdleLongerThan(_sessionCache.getIdlePassivationTimeoutSec())) - { - passivate = true; - if (LOG.isDebugEnabled())LOG.debug("Session {} will be passivated", session.getId()); - } + if (session.isExpiredAt(System.currentTimeMillis()) && session.getRequests() <=0) + expired = true; } - - if (passivate) - _sessionCache.passivateIdleSession(session.getId()); //TODO call passivate inside lock - + + if (expired) + { + //instead of expiring the session directly here, accumulate a list of + //session ids that need to be expired. This is an efficiency measure: as + //the expiration involves the SessionDataStore doing a delete, it is + //most efficient if it can be done as a bulk operation to eg reduce + //roundtrips to the persistent store. + _candidateSessionIdsForExpiry.add(session.getId()); + if (LOG.isDebugEnabled())LOG.debug("Session {} is candidate for expiry", session.getId()); + } + else + _sessionCache.checkInactiveSession(session); //if inactivity eviction is enabled the session will be deleted from the cache } + @@ -1449,7 +1531,8 @@ public class SessionHandler extends ScopedHandler { SessionHandler old_session_manager = null; HttpSession old_session = null; - HttpSession access = null; + HttpSession existingSession = null; + try { old_session_manager = baseRequest.getSessionHandler(); @@ -1463,54 +1546,39 @@ public class SessionHandler extends ScopedHandler checkRequestedSessionId(baseRequest,request); } - // access any existing session - HttpSession session = null; - - session = baseRequest.getSession(false); - if (session != null) + // access any existing session for this context + existingSession = baseRequest.getSession(false); + + if ((existingSession != null) && (old_session_manager != this)) { - if ((session != old_session) && (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.REQUEST)) - { - access = session; - HttpCookie cookie = access(session,request.isSecure()); - if (cookie != null) // Handle changed ID or max-age refresh - baseRequest.getResponse().addCookie(cookie); - } - } - else - { - session = baseRequest.recoverNewSession(this); - if (session != null) - baseRequest.setSession(session); + HttpCookie cookie = access(existingSession,request.isSecure()); + // Handle changed ID or max-age refresh, but only if this is not a redispatched request + if ((cookie != null) && (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.REQUEST)) + baseRequest.getResponse().addCookie(cookie); } if (LOG.isDebugEnabled()) { LOG.debug("sessionHandler=" + this); - LOG.debug("session=" + session); + LOG.debug("session=" + existingSession); } - // start manual inline of nextScope(target,baseRequest,request,response); if (_nextScope != null) _nextScope.doScope(target,baseRequest,request,response); else if (_outerScope != null) _outerScope.doHandle(target,baseRequest,request,response); else doHandle(target,baseRequest,request,response); - // end manual inline (pathentic attempt to reduce stack depth) - } finally { - //if we accessed an existing session entering this context, then complete it - if (access != null) - complete(access); - - //if there is a session that was created during handling this context, then complete it - HttpSession session = baseRequest.getSession(false); - if ((session != null && old_session == null && session != access) && (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.REQUEST)) - complete(session); + HttpSession finalSession = baseRequest.getSession(false); + if ((finalSession != null) && (old_session_manager != this)) + { + complete((Session)finalSession, baseRequest); + } + if (old_session_manager != null && old_session_manager != this) { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 80a3207a5fb..b6241886316 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -56,7 +56,7 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ErrorHandler; import org.eclipse.jetty.server.session.DefaultSessionIdManager; import org.eclipse.jetty.server.session.DefaultSessionCache; -import org.eclipse.jetty.server.session.NullSessionStore; +import org.eclipse.jetty.server.session.NullSessionDataStore; import org.eclipse.jetty.server.session.Session; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.server.session.SessionHandler; @@ -514,8 +514,8 @@ public class ResponseTest request.setRequestedSessionIdFromCookie(false); SessionHandler handler = new SessionHandler(); DefaultSessionCache ss = new DefaultSessionCache(handler); - NullSessionStore ds = new NullSessionStore(); - ss.setSessionStore(ds); + NullSessionDataStore ds = new NullSessionDataStore(); + ss.setSessionDataStore(ds); handler.setSessionIdManager(new DefaultSessionIdManager(_server)); request.setSessionHandler(handler); TestSession tsession = new TestSession(handler, "12345"); @@ -594,10 +594,10 @@ public class ResponseTest request.setRequestedSessionIdFromCookie(i>2); SessionHandler handler = new SessionHandler(); - NullSessionStore ds = new NullSessionStore(); + NullSessionDataStore ds = new NullSessionDataStore(); DefaultSessionCache ss = new DefaultSessionCache(handler); - handler.setSessionStore(ss); - ss.setSessionStore(ds); + handler.setSessionCache(ss); + ss.setSessionDataStore(ds); handler.setSessionIdManager(new DefaultSessionIdManager(_server)); request.setSessionHandler(handler); request.setSession(new TestSession(handler, "12345")); @@ -898,8 +898,7 @@ public class ResponseTest { protected TestSession(SessionHandler handler, String id) { - super(new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300)); - setSessionHandler(handler); + super(handler, new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300)); } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java index 9b938c803b8..bc2dfd80d30 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java @@ -65,11 +65,11 @@ public class FileSessionManagerTest idmgr.setServer(server); server.setSessionIdManager(idmgr); - FileSessionStore ds = new FileSessionStore(); + FileSessionDataStore ds = new FileSessionDataStore(); ds.setDeleteUnrestorableFiles(true); DefaultSessionCache ss = new DefaultSessionCache(handler); - handler.setSessionStore(ss); - ss.setSessionStore(ds); + handler.setSessionCache(ss); + ss.setSessionDataStore(ds); //manager.setLazyLoad(true); File testDir = MavenTestingUtils.getTargetTestingDir("hashes"); testDir.mkdirs(); @@ -101,9 +101,9 @@ public class FileSessionManagerTest server.setSessionIdManager(idmgr); DefaultSessionCache ss = new DefaultSessionCache(handler); - FileSessionStore ds = new FileSessionStore(); - ss.setSessionStore(ds); - handler.setSessionStore(ss); + FileSessionDataStore ds = new FileSessionDataStore(); + ss.setSessionDataStore(ds); + handler.setSessionCache(ss); ds.setDeleteUnrestorableFiles(true); handler.setSessionIdManager(idmgr); @@ -136,9 +136,9 @@ public class FileSessionManagerTest handler.setServer(server); DefaultSessionCache ss = new DefaultSessionCache(handler); - FileSessionStore ds = new FileSessionStore(); - ss.setSessionStore(ds); - handler.setSessionStore(ss); + FileSessionDataStore ds = new FileSessionDataStore(); + ss.setSessionDataStore(ds); + handler.setSessionCache(ss); ds.setStoreDir(testDir); handler.setMaxInactiveInterval(5); Assert.assertTrue(testDir.exists()); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java index daee56ed274..8bb74fbad98 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java @@ -165,13 +165,13 @@ public class SessionCookieTest idMgr.setWorkerName("node1"); SessionHandler mgr = new SessionHandler(); MockSessionStore store = new MockSessionStore(mgr); - store.setSessionStore(new NullSessionStore()); - mgr.setSessionStore(store); + store.setSessionDataStore(new NullSessionDataStore()); + mgr.setSessionCache(store); mgr.setSessionIdManager(idMgr); long now = System.currentTimeMillis(); - Session session = new Session(new SessionData("123", "_foo", "0.0.0.0", now, now, now, 30)); + Session session = new Session(null, new SessionData("123", "_foo", "0.0.0.0", now, now, now, 30)); SessionCookieConfig sessionCookieConfig = mgr.getSessionCookieConfig(); sessionCookieConfig.setSecure(true); diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java index b5891a69eeb..d3b80b81779 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java @@ -70,15 +70,16 @@ public class FileTestServer extends AbstractTestServer assertFalse(files.length==0); } } - - + + public static void assertFileExists (String sessionId, boolean exists) { assertNotNull(_tmpDir); assertTrue(_tmpDir.exists()); String[] files = _tmpDir.list(); assertNotNull(files); - assertFalse(files.length == 0); + if (exists) + assertFalse(files.length == 0); boolean found = false; for (String name:files) { @@ -143,10 +144,10 @@ public class FileTestServer extends AbstractTestServer { SessionHandler handler = new SessionHandler(); DefaultSessionCache ss = new DefaultSessionCache(handler); - handler.setSessionStore(ss); - FileSessionStore ds = new FileSessionStore(); + handler.setSessionCache(ss); + FileSessionDataStore ds = new FileSessionDataStore(); ds.setStoreDir(_tmpDir); - ss.setSessionStore(ds); + ss.setSessionDataStore(ds); return handler; } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java index 664cf523fa3..5ce7b4c7855 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java @@ -47,9 +47,9 @@ public class IdleSessionTest extends AbstractIdleSessionTest * @see org.eclipse.jetty.server.session.AbstractIdleSessionTest#createServer(int, int, int, int) */ @Override - public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int idleSec) + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) { - return new FileTestServer(port,max,scavenge, idleSec); + return new FileTestServer(port,max,scavenge, evictionPolicy); } @@ -71,7 +71,7 @@ public class IdleSessionTest extends AbstractIdleSessionTest public void checkSessionDeIdled(String sessionId) { //Can't check absence of file to indicate session is de-idled - //because the FileSessionStore writes out the session to a file if anything changes. + //because the FileSessionDataStore writes out the session to a file if anything changes. //The test changes an attribute so the file will probably exist. } @@ -83,6 +83,7 @@ public class IdleSessionTest extends AbstractIdleSessionTest public void deleteSessionData(String sessionId) { FileTestServer.deleteFile(sessionId); + FileTestServer.assertFileExists(sessionId, false); } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java index 4cffa43c715..c813ccf65de 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java @@ -37,9 +37,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port,max,scavenge, idlePassivatePeriod); + return new FileTestServer(port,max,scavenge, evictionPolicy); } } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java index d015d47fea2..e643088577a 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java @@ -40,9 +40,9 @@ public class NewSessionTest extends AbstractNewSessionTest FileTestServer.teardown(); } - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port,max,scavenge,idlePassivatePeriod); + return new FileTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java index 4eabeaf67c5..b16dd46cf33 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java @@ -39,9 +39,9 @@ public class OrphanedSessionTest extends AbstractOrphanedSessionTest FileTestServer.teardown(); } - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port,max,scavenge,idlePassivatePeriod); + return new FileTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java index a65dd5b6754..2aa43e5a68a 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java @@ -50,9 +50,9 @@ public class ProxySerializationTest extends AbstractProxySerializationTest * @see org.eclipse.jetty.server.session.AbstractProxySerializationTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod ) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy ) { - return new FileTestServer(port,max,scavenge, idlePassivatePeriod); + return new FileTestServer(port,max,scavenge, evictionPolicy); } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java index 0391f14f3a8..16ebd57df3c 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java @@ -41,9 +41,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession } - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new FileTestServer(port, max, scavenge, idlePassivatePeriod); + return new FileTestServer(port, max, scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java index 2eb2d436ec0..2626506be13 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java @@ -38,9 +38,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest } - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port,max,scavenge,idlePassivatePeriod); + return new FileTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java index a57da95e836..f5ffeb83f11 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java @@ -40,9 +40,9 @@ public class SessionCookieTest extends AbstractSessionCookieTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port, max, scavenge,idlePassivatePeriod); + return new FileTestServer(port, max, scavenge,evictionPolicy); } } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java index c29eb51ff6e..5589d933746 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java @@ -38,9 +38,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd } @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port,max,scavenge,idlePassivatePeriod); + return new FileTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java index 4551799707b..b104933e083 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java @@ -40,9 +40,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest } @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port, max, scavenge,idlePassivatePeriod); + return new FileTestServer(port, max, scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java index 65a2a26ad66..e71b2d59952 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java @@ -38,9 +38,9 @@ public class SessionValueSharedSaving extends AbstractSessionValueSavingTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new FileTestServer(port,max,scavenge,idlePassivatePeriod); + return new FileTestServer(port,max,scavenge,evictionPolicy); } } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java index 4e55eaa2975..0d3ba6463fb 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java @@ -297,7 +297,7 @@ public class GCloudSessionTestSupport public void listSessions () throws Exception { ensureDatastore(); - GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionStore.KIND); + GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.KIND); Query query = builder.build(); @@ -317,7 +317,7 @@ public class GCloudSessionTestSupport { HashSet ids = new HashSet(); ensureDatastore(); - GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionStore.KIND); + GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.KIND); Query query = builder.build(); @@ -336,7 +336,7 @@ public class GCloudSessionTestSupport { ensureDatastore(); StructuredQuery keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder() - .kind(GCloudSessionStore.KIND) + .kind(GCloudSessionDataStore.KIND) .projection(Projection.property("__key__")) .limit(100) .build(); @@ -355,7 +355,7 @@ public class GCloudSessionTestSupport { ensureDatastore(); StructuredQuery keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder() - .kind(GCloudSessionStore.KIND) + .kind(GCloudSessionDataStore.KIND) .projection(Projection.property("__key__")) .limit(100) .build(); diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudTestServer.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudTestServer.java index d9d4dd50ae8..05d425941fb 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudTestServer.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudTestServer.java @@ -65,11 +65,11 @@ public class GCloudTestServer extends AbstractTestServer { SessionHandler handler = new SessionHandler(); handler.setSessionIdManager(_sessionIdManager); - GCloudSessionStore ds = new GCloudSessionStore(); + GCloudSessionDataStore ds = new GCloudSessionDataStore(); ds.setGCloudConfiguration((GCloudConfiguration)_config); DefaultSessionCache ss = new DefaultSessionCache(handler); - ss.setSessionStore(ds); - handler.setSessionStore(ss); + ss.setSessionDataStore(ds); + handler.setSessionCache(ss); return handler; } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java index c0b40ea65e0..70d3ff7a90c 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java @@ -53,9 +53,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest * @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy) { - return new GCloudTestServer(port, maxInactiveMs, scavengeMs, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java index 7fa2ae62c1d..aca06bbdef1 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java @@ -35,7 +35,7 @@ import org.junit.Ignore; public class InvalidationSessionTest extends AbstractInvalidationSessionTest { static GCloudSessionTestSupport _testSupport; - public static final int IDLE_PASSIVATE_SEC = 3; + public static final int EVICT_SEC = 3; @BeforeClass public static void setup () throws Exception @@ -54,9 +54,9 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest * @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - GCloudTestServer server = new GCloudTestServer(port, maxInactive, scavengeInterval, idlePassivateInterval, _testSupport.getConfiguration()) + GCloudTestServer server = new GCloudTestServer(port, maxInactive, scavengeInterval, evictionPolicy, _testSupport.getConfiguration()) { /** * @see org.eclipse.jetty.gcloud.session.GCloudTestServer#newSessionManager() @@ -65,7 +65,7 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest public SessionHandler newSessionHandler() { SessionHandler handler = super.newSessionHandler(); - handler.getSessionStore().setIdlePassivationTimeoutSec(IDLE_PASSIVATE_SEC); + handler.getSessionCache().setEvictionPolicy(EVICT_SEC); return handler; } @@ -84,7 +84,7 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest //has expired on node2 for it to reload the session and discover it has been deleted. try { - Thread.currentThread().sleep((2*IDLE_PASSIVATE_SEC)*1000); + Thread.currentThread().sleep((2*EVICT_SEC)*1000); } catch (Exception e) { diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java index 289490462c4..2af768028a7 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java @@ -50,9 +50,9 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest * @see org.eclipse.jetty.server.session.AbstractLastAccessTimeTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java index f2b955b217f..1070db261d0 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java @@ -51,9 +51,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe * @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java index 6ef410a05db..e17870bb35a 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java @@ -57,9 +57,9 @@ public class NewSessionTest extends AbstractNewSessionTest * @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java index f8e815a2056..10bf3337aa9 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java @@ -52,9 +52,9 @@ public class OrphanedSessionTest extends AbstractOrphanedSessionTest * @see org.eclipse.jetty.server.session.AbstractOrphanedSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java index 45fbd6f2c55..be947e8e6af 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java @@ -51,9 +51,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession * @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port,int max, int scavengePeriod,int idlePassivatePeriod) + public AbstractTestServer createServer(int port,int max, int scavengePeriod,int evictionPolicy) { - return new GCloudTestServer(port, max, scavengePeriod, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavengePeriod, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java index 00060b793d9..d7f5a9f0403 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java @@ -54,9 +54,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest * @see org.eclipse.jetty.server.session.AbstractRemoveSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java index d945fb39599..79b2a079577 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java @@ -53,9 +53,9 @@ public class SameNodeLoadTest extends AbstractSameNodeLoadTest * @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int, int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java index 8162dcf97b6..1af07adfafd 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java @@ -57,9 +57,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest * @see org.eclipse.jetty.server.session.AbstractSessionExpiryTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java index 84ce3fd575a..6823bc33e88 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java @@ -53,9 +53,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd * @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java index 17a19678500..591a58e8e60 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java @@ -56,9 +56,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest * @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new GCloudTestServer(port,max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port,max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java index 83a3f49325c..e13a468693a 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java @@ -52,9 +52,9 @@ public class SessionValueSavingTest extends AbstractSessionValueSavingTest * @see org.eclipse.jetty.server.session.AbstractSessionValueSavingTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration()); + return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration()); } @Test diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/HashTestServer.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/HashTestServer.java index c6a895d488b..2a47fd4576c 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/HashTestServer.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/HashTestServer.java @@ -33,9 +33,9 @@ public class HashTestServer extends AbstractTestServer super(port, 30, 10, 2); } - public HashTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod) + public HashTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy) { - super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod); + super(port, maxInactivePeriod, scavengePeriod, evictionPolicy); } @@ -44,8 +44,8 @@ public class HashTestServer extends AbstractTestServer { SessionHandler handler = new SessionHandler(); DefaultSessionCache ss = new DefaultSessionCache(handler); - handler.setSessionStore(ss); - ss.setSessionStore(new NullSessionStore()); + handler.setSessionCache(ss); + ss.setSessionDataStore(new NullSessionDataStore()); return handler; } diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java index 0bd03ccc9c9..4c18b3c72ea 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java @@ -22,9 +22,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port,max,scavenge,idlePassivationPeriod); + return new HashTestServer(port,max,scavenge,evictionPolicy); } } diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java index 419381b3668..07b34f90cef 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java @@ -26,9 +26,9 @@ import org.junit.Test; public class NewSessionTest extends AbstractNewSessionTest { - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port,max,scavenge,idlePassivationPeriod); + return new HashTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java index 4ff255706c7..cefb383379f 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java @@ -30,9 +30,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession * @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int, int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port, max, scavenge, idlePassivatePeriod); + return new HashTestServer(port, max, scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java index aae01a17a47..44912267009 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java @@ -34,9 +34,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest * @see org.eclipse.jetty.server.session.AbstractRemoveSessionTest#createServer(int, int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer (port, max, scavenge, idlePassivationPeriod); + return new HashTestServer (port, max, scavenge, evictionPolicy); } } diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java index 3edaf930fc2..166a5c9de4f 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java @@ -22,9 +22,9 @@ public class SessionCookieTest extends AbstractSessionCookieTest { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port, max, scavenge, idlePassivationPeriod); + return new HashTestServer(port, max, scavenge, evictionPolicy); } } diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java index 920b5a2b2d0..8ab67f2940c 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java @@ -24,9 +24,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port,max,scavenge,idlePassivationPeriod); + return new HashTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java index 0304ce788dc..7101a70d447 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java @@ -31,9 +31,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port, max, scavenge,idlePassivationPeriod); + return new HashTestServer(port, max, scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java index 2cd7cca98e4..d2129a4ce85 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSharedSaving.java @@ -22,9 +22,9 @@ public class SessionValueSharedSaving extends AbstractSessionValueSavingTest { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port,max,scavenge,idlePassivationPeriod); + return new HashTestServer(port,max,scavenge,evictionPolicy); } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java index 6b61d55d824..aba7f2d2073 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java @@ -56,9 +56,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest * @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSessionServer.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSessionServer.java index 6c8b757295d..5177a85814c 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSessionServer.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSessionServer.java @@ -20,7 +20,7 @@ package org.eclipse.jetty.server.session; import org.eclipse.jetty.server.SessionIdManager; -import org.eclipse.jetty.session.infinispan.InfinispanSessionStore; +import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore; import org.eclipse.jetty.webapp.WebAppContext; import org.infinispan.Cache; import org.infinispan.commons.api.BasicCache; @@ -37,9 +37,9 @@ public class InfinispanTestSessionServer extends AbstractTestServer - public InfinispanTestSessionServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod, BasicCache config) + public InfinispanTestSessionServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy, BasicCache config) { - super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod, config); + super(port, maxInactivePeriod, scavengePeriod, evictionPolicy, config); } @@ -48,11 +48,11 @@ public class InfinispanTestSessionServer extends AbstractTestServer public SessionHandler newSessionHandler() { SessionHandler handler = new SessionHandler(); - InfinispanSessionStore sds = new InfinispanSessionStore(); + InfinispanSessionDataStore sds = new InfinispanSessionDataStore(); sds.setCache((BasicCache)_config); DefaultSessionCache ss = new DefaultSessionCache(handler); - ss.setSessionStore(sds); - handler.setSessionStore(ss); + ss.setSessionDataStore(sds); + handler.setSessionCache(ss); return handler; } @@ -61,7 +61,7 @@ public class InfinispanTestSessionServer extends AbstractTestServer BasicCache cache = (BasicCache)_config; if (cache != null) { - return cache.containsKey(((InfinispanSessionStore)(context.getSessionHandler().getSessionStore().getSessionStore())).getCacheKey(id)); + return cache.containsKey(((InfinispanSessionDataStore)(context.getSessionHandler().getSessionCache().getSessionDataStore())).getCacheKey(id)); } return false; @@ -72,7 +72,7 @@ public class InfinispanTestSessionServer extends AbstractTestServer BasicCache cache = (BasicCache)_config; if (cache != null) { - return cache.get(((InfinispanSessionStore)(context.getSessionHandler().getSessionStore().getSessionStore())).getCacheKey(id)); + return cache.get(((InfinispanSessionDataStore)(context.getSessionHandler().getSessionCache().getSessionDataStore())).getCacheKey(id)); } return null; diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java index 767164f7f6c..1a8e927f16e 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java @@ -42,9 +42,9 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java index cb6682e80f2..e5ad0ee3d79 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java @@ -51,9 +51,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe * @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java index 825e862df20..da96688d052 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java @@ -50,9 +50,9 @@ public class NewSessionTest extends AbstractNewSessionTest * @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java index c2ffc9e76fd..0a2025c4116 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java @@ -49,9 +49,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession * @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, maxInactive, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, maxInactive, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java index d8ae36a0787..61d4099a924 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/RemoveSessionTest.java @@ -43,9 +43,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); return s; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SameNodeLoadTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SameNodeLoadTest.java index 7d783fd9916..392b18f70f4 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SameNodeLoadTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SameNodeLoadTest.java @@ -51,9 +51,9 @@ public class SameNodeLoadTest extends AbstractSameNodeLoadTest * @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port,maxInactive, scavenge, idlePassivateInterval, __testSupport.getCache()); + InfinispanTestSessionServer server = new InfinispanTestSessionServer(port,maxInactive, scavenge, evictionPolicy, __testSupport.getCache()); return server; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java index a7b6941ff8f..a813da30ff8 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java @@ -42,9 +42,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); return server; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java index ab26d8bc126..5ae548a05eb 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java @@ -50,9 +50,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd * @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java index 3ddabe286d1..04b7e2af61b 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java @@ -57,9 +57,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest * @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } @Test diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmortalSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmortalSessionTest.java index a406bd7d5e2..2b49e677768 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmortalSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmortalSessionTest.java @@ -59,9 +59,9 @@ public class RemoteImmortalSessionTest extends AbstractImmortalSessionTest * @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInvalidationSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInvalidationSessionTest.java index bc6dc5173b6..5f7b2aa62d4 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInvalidationSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteInvalidationSessionTest.java @@ -56,9 +56,9 @@ public class RemoteInvalidationSessionTest extends AbstractInvalidationSessionTe * @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port, int maxInterval, int scavengeInterval, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInterval, int scavengeInterval, int evictionPolicy) { - return new InfinispanTestSessionServer(port, maxInterval, scavengeInterval, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, maxInterval, scavengeInterval, evictionPolicy, __testSupport.getCache()); } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLastAccessTimeTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLastAccessTimeTest.java index a1625ba9818..4183e15ccd5 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLastAccessTimeTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLastAccessTimeTest.java @@ -52,9 +52,9 @@ public class RemoteLastAccessTimeTest extends AbstractLastAccessTimeTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLocalSessionScavengingTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLocalSessionScavengingTest.java index adb2f953960..4339906f56f 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLocalSessionScavengingTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteLocalSessionScavengingTest.java @@ -53,9 +53,9 @@ public class RemoteLocalSessionScavengingTest extends AbstractLocalSessionScaven * @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteNewSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteNewSessionTest.java index 4b294edea3b..3a680edbe4f 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteNewSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteNewSessionTest.java @@ -53,9 +53,9 @@ public class RemoteNewSessionTest extends AbstractNewSessionTest * @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteReentrantRequestSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteReentrantRequestSessionTest.java index 4bb915d4ce9..c165dff4b8b 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteReentrantRequestSessionTest.java @@ -52,9 +52,9 @@ public class RemoteReentrantRequestSessionTest extends AbstractReentrantRequestS * @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, maxInactive, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, maxInactive, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteRemoveSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteRemoveSessionTest.java index cda9acb654d..ebbf9a999ce 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteRemoveSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteRemoveSessionTest.java @@ -46,9 +46,9 @@ public class RemoteRemoveSessionTest extends AbstractRemoveSessionTest @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge,idlePassivateInterval, __testSupport.getCache()); + InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge,evictionPolicy, __testSupport.getCache()); return s; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSameNodeLoadTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSameNodeLoadTest.java index 0a49f3155a4..fbec44136e8 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSameNodeLoadTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSameNodeLoadTest.java @@ -54,9 +54,9 @@ public class RemoteSameNodeLoadTest extends AbstractSameNodeLoadTest * @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int) */ @Override - public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, maxInactive, scavenge,idlePassivateInterval, __testSupport.getCache()); + InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, maxInactive, scavenge,evictionPolicy, __testSupport.getCache()); return server; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionExpiryTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionExpiryTest.java index e0d2d4dae9f..b0438e68513 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionExpiryTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionExpiryTest.java @@ -45,9 +45,9 @@ public class RemoteSessionExpiryTest extends AbstractSessionExpiryTest } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); return server; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionInvalidateAndCreateTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionInvalidateAndCreateTest.java index 8f1af7b44a1..f4da36eb1ff 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionInvalidateAndCreateTest.java @@ -53,9 +53,9 @@ public class RemoteSessionInvalidateAndCreateTest extends AbstractSessionInvalid * @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } @Override diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionRenewTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionRenewTest.java index 6c41761ebde..3c3da4c8a9c 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionRenewTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionRenewTest.java @@ -56,9 +56,9 @@ public class RemoteSessionRenewTest extends AbstractSessionRenewTest * @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache()); + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/DirtyAttributeTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/DirtyAttributeTest.java index 7922a25fda8..305b651c1ac 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/DirtyAttributeTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/DirtyAttributeTest.java @@ -58,12 +58,12 @@ public class DirtyAttributeTest public static int INACTIVE = 4; public static int SCAVENGE = 1; public static int INSPECT = 1; - public static int IDLE_PASSIVATE = 3; + public static int EVICT_SECS = 3; @Test public void testDirtyWrite() throws Exception { - AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE, IDLE_PASSIVATE); + AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE, EVICT_SECS); ServletContextHandler ctxA = server.addContext("/mod"); ctxA.addServlet(TestDirtyServlet.class, "/test"); diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java index bd6a20e9f2a..7403c8e84af 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmortalSessionTest.java @@ -29,9 +29,9 @@ import org.junit.Test; public class ImmortalSessionTest extends AbstractImmortalSessionTest { - public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int idlePassivate) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int evictionPolicy) { - return new JdbcTestServer(port, maxInactiveMs, scavengeMs, idlePassivate); + return new JdbcTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/InvalidationSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/InvalidationSessionTest.java index 1b3aea3e998..3754819dc06 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/InvalidationSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/InvalidationSessionTest.java @@ -29,9 +29,9 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest { public static final int IDLE_PASSIVATE_SEC = 3; - public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int idlePassivateInterval) + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new JdbcTestServer(port, maxInactive, scavengeInterval, idlePassivateInterval); + return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } public void pause() diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java index 7537bad4876..b839d3d2a9d 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java @@ -103,14 +103,14 @@ public class JdbcTestServer extends AbstractTestServer { SessionHandler handler = new SessionHandler(); DefaultSessionCache sessionStore = new DefaultSessionCache(handler); - handler.setSessionStore(sessionStore); - JDBCSessionStore ds = new JDBCSessionStore(); - sessionStore.setSessionStore(ds); + handler.setSessionCache(sessionStore); + JDBCSessionDataStore ds = new JDBCSessionDataStore(); + sessionStore.setSessionDataStore(ds); ds.setGracePeriodSec(_scavengePeriod); DatabaseAdaptor da = new DatabaseAdaptor(); da.setDriverInfo(DRIVER_CLASS, (_config==null?DEFAULT_CONNECTION_URL:(String)_config)); ds.setDatabaseAdaptor(da); - JDBCSessionStore.SessionTableSchema sessionTableSchema = new JDBCSessionStore.SessionTableSchema(); + JDBCSessionDataStore.SessionTableSchema sessionTableSchema = new JDBCSessionDataStore.SessionTableSchema(); sessionTableSchema.setTableName(TABLE); sessionTableSchema.setIdColumn(ID_COL); sessionTableSchema.setAccessTimeColumn(ACCESS_COL); diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java index d16eaa6c2c4..a01df927fc4 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LastAccessTimeTest.java @@ -26,9 +26,9 @@ import org.junit.Test; */ public class LastAccessTimeTest extends AbstractLastAccessTimeTest { - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge, idlePassivate); + return new JdbcTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java index 78533fc962d..822ce9e3d24 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/LocalSessionScavengingTest.java @@ -43,9 +43,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe } } - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge, idlePassivate); + return new JdbcTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ModifyMaxInactiveIntervalTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ModifyMaxInactiveIntervalTest.java index fdb221f957a..10cb08e75c1 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ModifyMaxInactiveIntervalTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ModifyMaxInactiveIntervalTest.java @@ -49,13 +49,12 @@ public class ModifyMaxInactiveIntervalTest public static int __inactive = 4; public static int newMaxInactive = 20; public static int __scavenge = 1; - public static int __inspect = 1; - public static int __idlePassivate = -1; + @Test public void testSessionExpiryAfterModifiedMaxInactiveInterval() throws Exception { - AbstractTestServer server = new JdbcTestServer(0,__inactive,__scavenge, __idlePassivate); + AbstractTestServer server = new JdbcTestServer(0,__inactive,__scavenge, SessionCache.NEVER_EVICT); ServletContextHandler ctxA = server.addContext("/mod"); ctxA.addServlet(TestModServlet.class, "/test"); diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java index 5d9e16f1999..a224d7f57d6 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/NewSessionTest.java @@ -29,9 +29,9 @@ public class NewSessionTest extends AbstractNewSessionTest /** * @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int) */ - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge, idlePassivate); + return new JdbcTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java index 44fda28d623..6f0977bdba7 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/OrphanedSessionTest.java @@ -26,9 +26,9 @@ import org.junit.Test; */ public class OrphanedSessionTest extends AbstractOrphanedSessionTest { - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge,idlePassivate); + return new JdbcTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java index 14957ca70fd..2a9234cce92 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ProxySerializationTest.java @@ -35,9 +35,9 @@ public class ProxySerializationTest extends AbstractProxySerializationTest * @see org.eclipse.jetty.server.session.AbstractProxySerializationTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port, max, scavenge, idlePassivate); + return new JdbcTestServer(port, max, scavenge, evictionPolicy); } /** diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java index 9fead19f2c8..5ca51a62184 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReentrantRequestSessionTest.java @@ -28,9 +28,9 @@ import org.junit.Test; public class ReentrantRequestSessionTest extends AbstractReentrantRequestSessionTest { - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge,idlePassivatePeriod); + return new JdbcTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SaveIntervalTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SaveIntervalTest.java index 35474e5b271..45dcbbb739e 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SaveIntervalTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SaveIntervalTest.java @@ -59,7 +59,7 @@ public class SaveIntervalTest @Test public void testSaveInterval() throws Exception { - AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE, -1); + AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE, SessionCache.NEVER_EVICT); ServletContextHandler ctxA = server.addContext("/mod"); ServletHolder holder = new ServletHolder(); diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java index 6f9548e2b91..bf7c818da30 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionExpiryTest.java @@ -36,9 +36,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest * @see org.eclipse.jetty.server.session.AbstractSessionExpiryTest#createServer(int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge, idlePassivate); + return new JdbcTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java index c0034a85d75..68281f71af4 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionInvalidateAndCreateTest.java @@ -26,9 +26,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge,idlePassivate); + return new JdbcTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java index 38535822bc9..dc7b06d5b6d 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java @@ -30,9 +30,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest { @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new JdbcTestServer(port, max, scavenge, idlePassivate); + return new JdbcTestServer(port, max, scavenge, evictionPolicy); } diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSavingTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSavingTest.java index bdb55980734..ae06ee18481 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSavingTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionValueSavingTest.java @@ -26,9 +26,9 @@ import org.junit.Test; */ public class SessionValueSavingTest extends AbstractSessionValueSavingTest { - public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy) { - return new JdbcTestServer(port,max,scavenge,idlePassivate); + return new JdbcTestServer(port,max,scavenge,evictionPolicy); } @Test diff --git a/tests/test-sessions/test-mongodb-sessions/pom.xml b/tests/test-sessions/test-mongodb-sessions/pom.xml index d2aa2576701..eac700e744f 100644 --- a/tests/test-sessions/test-mongodb-sessions/pom.xml +++ b/tests/test-sessions/test-mongodb-sessions/pom.xml @@ -26,7 +26,7 @@ org.apache.maven.plugins maven-surefire-plugin - true + false diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java index 59ea3f3949b..eddc9251c10 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java @@ -36,6 +36,7 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.server.session.AbstractTestServer; import org.eclipse.jetty.server.session.Session; +import org.eclipse.jetty.server.session.SessionCache; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -80,14 +81,12 @@ public class AttributeNameTest String servletMapping = "/server"; int maxInactivePeriod = 10000; int scavengePeriod = 20000; - int inspectPeriod = 60; - int idlePassivatePeriod = -1; - AbstractTestServer server1 = createServer(0,maxInactivePeriod,scavengePeriod, idlePassivatePeriod); + AbstractTestServer server1 = createServer(0,maxInactivePeriod,scavengePeriod, SessionCache.NEVER_EVICT); server1.addContext(contextPath).addServlet(TestServlet.class,servletMapping); server1.start(); int port1 = server1.getPort(); - AbstractTestServer server2 = createServer(0,maxInactivePeriod,scavengePeriod, idlePassivatePeriod); + AbstractTestServer server2 = createServer(0,maxInactivePeriod,scavengePeriod, SessionCache.NEVER_EVICT); server2.addContext(contextPath).addServlet(TestServlet.class,servletMapping); server2.start(); int port2 = server2.getPort(); diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/CreateAndInvalidateTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/CreateAndInvalidateTest.java new file mode 100644 index 00000000000..b2adfae8de7 --- /dev/null +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/CreateAndInvalidateTest.java @@ -0,0 +1,105 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.nosql.mongodb; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.jetty.server.session.AbstractCreateAndInvalidateTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.After; +import org.junit.Before; + +import com.mongodb.BasicDBObject; +import com.mongodb.DBCollection; +import com.mongodb.DBObject; + +/** + * CreateAndInvalidateTest + * + * + */ +public class CreateAndInvalidateTest extends AbstractCreateAndInvalidateTest +{ + @Before + public void beforeTest() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @After + public void afterTest() throws Exception + { + MongoTestServer.dropCollection(); + } + + + /** + * @see org.eclipse.jetty.server.session.AbstractCreateAndInvalidateTest#createServer(int, int, int, int) + */ + @Override + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) + { + return new MongoTestServer(port,max,scavenge, evictionPolicy); + } + + + + /** + * @see org.eclipse.jetty.server.session.AbstractCreateAndInvalidateTest#checkSession(java.lang.String, boolean) + */ + @Override + public void checkSession(String sessionId, boolean isPersisted) throws Exception + { + DBCollection sessions = MongoTestServer.getCollection(); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,sessionId)); + if (!isPersisted) + assertNull(o); + else + assertNotNull(o); + } + + + /** + * @see org.eclipse.jetty.server.session.AbstractCreateAndInvalidateTest#checkSessionByKey(java.lang.String, java.lang.String, boolean) + */ + public void checkSessionByKey (String sessionId, String context, boolean isPersisted) throws Exception + { + DBCollection sessions = MongoTestServer.getCollection(); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,sessionId)); + if (!isPersisted) + assertNull(o); + else + assertNotNull(o); + + if (isPersisted) + { + Boolean valid = (Boolean)o.get(MongoSessionDataStore.__VALID); + assertNotNull(valid); + assertTrue(valid); + DBObject c = (DBObject)o.get("context"); + assertNotNull(c); + DBObject c1 = (DBObject)c.get(context); + assertNotNull(c1); + } + } +} diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/IdleSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/IdleSessionTest.java index e61c7089264..aa617d3c634 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/IdleSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/IdleSessionTest.java @@ -27,6 +27,8 @@ import org.eclipse.jetty.server.session.AbstractIdleSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; import org.eclipse.jetty.server.session.Session; import org.eclipse.jetty.util.thread.Locker.Lock; +import org.junit.After; +import org.junit.Before; /** * IdleSessionTest @@ -35,14 +37,28 @@ import org.eclipse.jetty.util.thread.Locker.Lock; */ public class IdleSessionTest extends AbstractIdleSessionTest { + @Before + public void beforeTest() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @After + public void afterTest() throws Exception + { + MongoTestServer.dropCollection(); + } + + /** * @see org.eclipse.jetty.server.session.AbstractIdleSessionTest#createServer(int, int, int, int) */ @Override - public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int idleSec) + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) { - return new MongoTestServer(port,max,scavenge, idleSec); + return new MongoTestServer(port,max,scavenge, evictionPolicy); } /** @@ -55,7 +71,7 @@ public class IdleSessionTest extends AbstractIdleSessionTest assertNotNull(_servlet._session); try (Lock lock = ((Session)_servlet._session).lock()) { - assertTrue(((Session)_servlet._session).isPassivated()); + assertTrue(!((Session)_servlet._session).isResident()); } } @@ -69,7 +85,7 @@ public class IdleSessionTest extends AbstractIdleSessionTest assertNotNull(_servlet._session); try (Lock lock = ((Session)_servlet._session).lock()) { - assertTrue(((Session)_servlet._session).isActive()); + assertTrue(((Session)_servlet._session).isResident()); } } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/InvalidateSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/InvalidateSessionTest.java index 14c7af59b24..9c692401480 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/InvalidateSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/InvalidateSessionTest.java @@ -43,9 +43,9 @@ public class InvalidateSessionTest extends AbstractInvalidationSessionTest } @Override - public AbstractTestServer createServer(int port, int maxInterval, int scavengeInterval, int idleInterval) + public AbstractTestServer createServer(int port, int maxInterval, int scavengeInterval, int evictionPolicy) { - return new MongoTestServer(port, maxInterval, scavengeInterval, idleInterval); + return new MongoTestServer(port, maxInterval, scavengeInterval, evictionPolicy); } @Override diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LastAccessTimeTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LastAccessTimeTest.java index 0b422744dde..ca78ffcd5e5 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LastAccessTimeTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LastAccessTimeTest.java @@ -41,9 +41,9 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest MongoTestServer.dropCollection(); } - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateSec) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port,max,scavenge, idlePassivateSec); + return new MongoTestServer(port,max,scavenge, evictionPolicy); } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LocalSessionScavengingTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LocalSessionScavengingTest.java index 985f32e284d..13a1ea41a19 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LocalSessionScavengingTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/LocalSessionScavengingTest.java @@ -41,9 +41,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateSec) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - MongoTestServer mserver=new MongoTestServer(port,max,scavenge, idlePassivateSec); + MongoTestServer mserver=new MongoTestServer(port,max,scavenge, evictionPolicy); return mserver; } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestServer.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestServer.java index 235521acd57..b1eeba21f8f 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestServer.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/MongoTestServer.java @@ -86,12 +86,13 @@ public class MongoTestServer extends AbstractTestServer SessionHandler handler = new SessionHandler(); try { - MongoSessionStore ds = new MongoSessionStore(); + MongoSessionDataStore ds = new MongoSessionDataStore(); ds.setDBCollection(getCollection()); ds.setGracePeriodSec(_scavengePeriod); DefaultSessionCache ss = new DefaultSessionCache(handler); - handler.setSessionStore(ss); + handler.setSessionCache(ss); + ss.setSessionDataStore(ds); return handler; } catch (Exception e) diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/NewSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/NewSessionTest.java index cca043820ee..b85f40cde86 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/NewSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/NewSessionTest.java @@ -44,9 +44,9 @@ public class NewSessionTest extends AbstractNewSessionTest } - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateSec) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port,max,scavenge, idlePassivateSec); + return new MongoTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/OrphanedSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/OrphanedSessionTest.java index bdbb63f45cb..4ba21f03226 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/OrphanedSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/OrphanedSessionTest.java @@ -44,9 +44,9 @@ public class OrphanedSessionTest extends AbstractOrphanedSessionTest } - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateSec) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port,max,scavenge, idlePassivateSec); + return new MongoTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ReentrantRequestSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ReentrantRequestSessionTest.java index fa1ea0de8ae..870f60461a3 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ReentrantRequestSessionTest.java @@ -55,9 +55,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession * @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int, int, int, int) */ @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port, max, scavenge, idlePassivatePeriod); + return new MongoTestServer(port, max, scavenge, evictionPolicy); } } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/RemoveSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/RemoveSessionTest.java index b5be9662359..9d015ec01d9 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/RemoveSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/RemoveSessionTest.java @@ -41,9 +41,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest MongoTestServer.dropCollection(); } - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port,max,scavenge, idlePassivate); + return new MongoTestServer(port,max,scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionExpiryTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionExpiryTest.java index bf7e797d83c..73a8aa17cb7 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionExpiryTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionExpiryTest.java @@ -69,9 +69,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port,max,scavenge, idlePassivate); + return new MongoTestServer(port,max,scavenge, evictionPolicy); } @Test @@ -125,7 +125,7 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest DBCollection sessions = MongoTestServer.getCollection(); verifySessionCreated(listener,sessionId); //verify that the session timeout is set in mongo - verifySessionTimeout(sessions, sessionId, -1000); //SessionManager sets -1 if maxInactive < 0 + verifySessionTimeout(sessions, sessionId, -1); //SessionManager sets -1 if maxInactive < 0 //get the session expiry time from mongo long expiry = getSessionExpiry(sessions, sessionId); @@ -278,9 +278,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest assertNotNull(sessions); assertNotNull(id); - DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id)); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id)); assertNotNull(o); - Long maxIdle = (Long)o.get(MongoSessionStore.__MAX_IDLE); + Long maxIdle = (Long)o.get(MongoSessionDataStore.__MAX_IDLE); assertNotNull(maxIdle); assertEquals(val, maxIdle.longValue()); } @@ -290,9 +290,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest assertNotNull(sessions); assertNotNull(id); - DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id)); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id)); assertNotNull(o); - Long expiry = (Long)o.get(MongoSessionStore.__EXPIRY); + Long expiry = (Long)o.get(MongoSessionDataStore.__EXPIRY); return (expiry == null? null : expiry.longValue()); } @@ -301,9 +301,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest assertNotNull(sessions); assertNotNull(id); - DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id)); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id)); assertNotNull(o); - Long inactiveInterval = (Long)o.get(MongoSessionStore.__MAX_IDLE); + Long inactiveInterval = (Long)o.get(MongoSessionDataStore.__MAX_IDLE); return (inactiveInterval == null? null : inactiveInterval.longValue()); } @@ -312,9 +312,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest assertNotNull(sessions); assertNotNull(id); - DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id)); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id)); assertNotNull(o); - Long accessed = (Long)o.get(MongoSessionStore.__ACCESSED); + Long accessed = (Long)o.get(MongoSessionDataStore.__ACCESSED); return (accessed == null? null : accessed.longValue()); } @@ -323,7 +323,7 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest assertNotNull(sessions); assertNotNull(id); - DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id)); + DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id)); assertNotNull(o); System.err.println(o); } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionInvalidateAndCreateTest.java index 61d562561b4..e58424619f2 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionInvalidateAndCreateTest.java @@ -42,9 +42,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port,max,scavenge,idlePassivate); + return new MongoTestServer(port,max,scavenge,evictionPolicy); } diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionRenewTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionRenewTest.java index 1ae47904724..3c3f38771b7 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionRenewTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionRenewTest.java @@ -49,9 +49,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port, max, scavenge, idlePassivate); + return new MongoTestServer(port, max, scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionSavingValueTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionSavingValueTest.java index 9defa60b3a7..55f5f064dda 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionSavingValueTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionSavingValueTest.java @@ -42,9 +42,9 @@ public class SessionSavingValueTest extends AbstractSessionValueSavingTest } @Override - public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate) + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new MongoTestServer(port, max, scavenge, idlePassivate); + return new MongoTestServer(port, max, scavenge, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractCreateAndInvalidateTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractCreateAndInvalidateTest.java new file mode 100644 index 00000000000..4ba7eb6cee2 --- /dev/null +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractCreateAndInvalidateTest.java @@ -0,0 +1,275 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.server.session; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.server.session.SessionCache; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.StacklessLogging; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + + + +/** + * AbstractCreateAndInvalidateTest + * + * Test that creating a session and invalidating it before the request exits the session + * does not result in the session being in mongo + */ +public abstract class AbstractCreateAndInvalidateTest{ + + protected TestServlet _servlet = new TestServlet(); + protected AbstractTestServer _server1 = null; + + + + + + public abstract AbstractTestServer createServer (int port, int max, int scavenge, int evictionPolicy); + + + + /** + * @param sessionId + * @param isPersisted + */ + public abstract void checkSession (String sessionId, boolean isPersisted) throws Exception; + + /** + * @param sessionid + * @param contextId + * @param isPersisted + * @throws Exception + */ + public abstract void checkSessionByKey (String sessionid, String contextId, boolean isPersisted) throws Exception; + + + /** + * Create and then invalidate a session in the same request. + * @throws Exception + */ + //@Test + public void testSessionCreateAndInvalidate() throws Exception + { + String contextPath = ""; + String servletMapping = "/server"; + int inactivePeriod = 20; + int scavengePeriod = 3; + + + + _server1 = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); + ServletHolder holder = new ServletHolder(_servlet); + ServletContextHandler contextHandler = _server1.addContext(contextPath); + contextHandler.addServlet(holder, servletMapping); + _server1.start(); + int port1 = _server1.getPort(); + + try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + { + HttpClient client = new HttpClient(); + client.start(); + String url = "http://localhost:" + port1 + contextPath + servletMapping; + + //make a request to set up a session on the server + ContentResponse response = client.GET(url); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + //check that the session does not exist + checkSession(_servlet._id, false); + + + } + finally + { + _server1.stop(); + } + } + + /** + * Create a session in a context, forward to another context and create a + * session in it too. Check that both sessions exist after the response + * completes. + * @throws Exception + */ + //@Test + public void testSessionCreateForward () throws Exception + { + String contextPath = ""; + String contextB = "/contextB"; + String servletMapping = "/server"; + int inactivePeriod = 20; + int scavengePeriod = 3; + + + + _server1 = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); + ServletHolder holder = new ServletHolder(_servlet); + ServletContextHandler contextHandler = _server1.addContext(contextPath); + contextHandler.addServlet(holder, servletMapping); + ServletContextHandler ctxB = _server1.addContext(contextB); + ctxB.addServlet(TestServletB.class, servletMapping); + _server1.start(); + int port1 = _server1.getPort(); + + try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + { + HttpClient client = new HttpClient(); + client.start(); + String url = "http://localhost:" + port1 + contextPath + servletMapping; + + //make a request to set up a session on the server + ContentResponse response = client.GET(url+"?action=forward"); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + //check that the sessions exist in mongo + checkSession(_servlet._id, true); + checkSessionByKey (_servlet._id, "0_0_0_0:", true); + checkSessionByKey (_servlet._id, "0_0_0_0:_contextB", true); + } + finally + { + _server1.stop(); + } + } + + /** + * + * Create a session in one context, forward to another context and create another session + * in it, then invalidate the session in the original context: that should invalidate the + * session in both contexts and no session should exist after the response completes. + * @throws Exception + */ + @Test + public void testSessionCreateForwardAndInvalidate () throws Exception + { + String contextPath = ""; + String contextB = "/contextB"; + String servletMapping = "/server"; + int inactivePeriod = 20; + int scavengePeriod = 3; + + + + _server1 = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); + ServletHolder holder = new ServletHolder(_servlet); + ServletContextHandler contextHandler = _server1.addContext(contextPath); + contextHandler.addServlet(holder, servletMapping); + ServletContextHandler ctxB = _server1.addContext(contextB); + ctxB.addServlet(TestServletB.class, servletMapping); + _server1.start(); + int port1 = _server1.getPort(); + + try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + { + HttpClient client = new HttpClient(); + client.start(); + String url = "http://localhost:" + port1 + contextPath + servletMapping; + + //make a request to set up a session on the server + ContentResponse response = client.GET(url+"?action=forwardinv"); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + + //check that the session does not exist + checkSession(_servlet._id, false); + } + finally + { + _server1.stop(); + } + } + + + + + public static class TestServlet extends HttpServlet + { + public String _id = null; + + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException + { + String action = request.getParameter("action"); + + if (action != null && action.startsWith("forward")) + { + HttpSession session = request.getSession(true); + _id = session.getId(); + session.setAttribute("value", new Integer(1)); + + ServletContext contextB = getServletContext().getContext("/contextB"); + RequestDispatcher dispatcherB = contextB.getRequestDispatcher(request.getServletPath()); + dispatcherB.forward(request, httpServletResponse); + + if (action.endsWith("inv")) + session.invalidate(); + + return; + } + + HttpSession session = request.getSession(true); + _id = session.getId(); + session.setAttribute("value", new Integer(1)); + session.invalidate(); + } + } + + public static class TestServletB extends HttpServlet + { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException + { + HttpSession session = request.getSession(false); + if (session == null) session = request.getSession(true); + + // Be sure nothing from contextA is present + Object objectA = session.getAttribute("A"); + assertTrue(objectA == null); + + // Add something, so in contextA we can check if it is visible (it must not). + session.setAttribute("B", "B"); + } + } +} diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractIdleSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractIdleSessionTest.java index 6d6f5ae861a..33b928d1a50 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractIdleSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractIdleSessionTest.java @@ -60,10 +60,10 @@ public abstract class AbstractIdleSessionTest * @param port * @param max * @param scavenge - * @param idleSec + * @param evictionPolicy * @return */ - public abstract AbstractTestServer createServer (int port, int max, int scavenge, int idleSec); + public abstract AbstractTestServer createServer (int port, int max, int scavenge, int evictionPolicy); /** @@ -113,11 +113,11 @@ public abstract class AbstractIdleSessionTest String servletMapping = "/server"; int inactivePeriod = 20; int scavengePeriod = 3; - int idlePeriod = 5; + int evictionSec = 5; - _server1 = createServer(0, inactivePeriod, scavengePeriod, idlePeriod); + _server1 = createServer(0, inactivePeriod, scavengePeriod, evictionSec); ServletHolder holder = new ServletHolder(_servlet); ServletContextHandler contextHandler = _server1.addContext(contextPath); contextHandler.addServlet(holder, servletMapping); @@ -139,8 +139,8 @@ public abstract class AbstractIdleSessionTest sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); //and wait until the session should be idled out - pause(idlePeriod*3); - + pause(evictionSec*3); + //check that the session has been idled checkSessionIdled(AbstractTestServer.extractSessionId(sessionCookie)); @@ -152,18 +152,17 @@ public abstract class AbstractIdleSessionTest //check session de-idled checkSessionDeIdled(AbstractTestServer.extractSessionId(sessionCookie)); - + //wait again for the session to be idled - pause(idlePeriod*3); + pause(evictionSec*3); //check that it is checkSessionIdled(AbstractTestServer.extractSessionId(sessionCookie)); - + //While idle, take some action to ensure that a deidle won't work, like //deleting all sessions in mongo deleteSessionData(AbstractTestServer.extractSessionId(sessionCookie)); - //make a request request = client.newRequest(url + "?action=testfail"); request.getHeaders().add("Cookie", sessionCookie); @@ -171,7 +170,6 @@ public abstract class AbstractIdleSessionTest assertEquals(HttpServletResponse.SC_OK,response2.getStatus()); //Test trying to de-idle an expired session (ie before the scavenger can get to it) - //make a request to set up a session on the server response = client.GET(url + "?action=init"); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); @@ -181,7 +179,7 @@ public abstract class AbstractIdleSessionTest sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); //and wait until the session should be idled out - pause(idlePeriod * 3); + pause(evictionSec * 3); //stop the scavenger if (_server1.getHouseKeeper() != null) @@ -226,7 +224,7 @@ public abstract class AbstractIdleSessionTest Session s = (Session)session; try (Lock lock = s.lock()) { - assertTrue(!s.isPassivated()); + assertTrue(s.isResident()); } _session = s; } @@ -238,8 +236,7 @@ public abstract class AbstractIdleSessionTest Session s = (Session)session; try (Lock lock = s.lock();) { - assertTrue(s.isActive()); - assertFalse(s.isPassivated()); + assertTrue(s.isResident()); } Integer v = (Integer)session.getAttribute("value"); session.setAttribute("value", new Integer(v.intValue()+1)); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmortalSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmortalSessionTest.java index 951498c5e56..f8d27953bb8 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmortalSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmortalSessionTest.java @@ -43,7 +43,7 @@ import org.junit.Test; */ public abstract class AbstractImmortalSessionTest { - public abstract AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int idlePassivatePeriod); + public abstract AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int evictionPolicy); @Test public void testImmortalSession() throws Exception @@ -51,9 +51,8 @@ public abstract class AbstractImmortalSessionTest String contextPath = ""; String servletMapping = "/server"; int scavengePeriod = 2; - int idlePeriod = -1; //turn off session expiry by setting maxInactiveInterval to -1 - AbstractTestServer server = createServer(0, -1, scavengePeriod, idlePeriod); + AbstractTestServer server = createServer(0, -1, scavengePeriod, SessionCache.NEVER_EVICT); ServletContextHandler context = server.addContext(contextPath); context.addServlet(TestServlet.class, servletMapping); @@ -82,6 +81,7 @@ public abstract class AbstractImmortalSessionTest // Be sure the session is still there Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=get"); request.header("Cookie", sessionCookie); + response = request.send(); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); resp = response.getContentAsString(); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractInvalidationSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractInvalidationSessionTest.java index 3573da6307d..ce79cb56058 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractInvalidationSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractInvalidationSessionTest.java @@ -43,7 +43,7 @@ import org.junit.Test; */ public abstract class AbstractInvalidationSessionTest { - public abstract AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int idlePassivatePeriod); + public abstract AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy); public abstract void pause(); @Test diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java index 2dd5fcb63f7..df1f5c2bfff 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java @@ -100,9 +100,9 @@ public abstract class AbstractLastAccessTimeTest assertEquals("test", response1.getContentAsString()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); assertTrue( sessionCookie != null ); - assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsCurrent()); - assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsMax()); - assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsTotal()); + assertEquals(1, ((DefaultSessionCache)m1.getSessionCache()).getSessionsCurrent()); + assertEquals(1, ((DefaultSessionCache)m1.getSessionCache()).getSessionsMax()); + assertEquals(1, ((DefaultSessionCache)m1.getSessionCache()).getSessionsTotal()); // Mangle the cookie, replacing Path with $Path, etc. sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); @@ -164,9 +164,9 @@ public abstract class AbstractLastAccessTimeTest public void assertSessionCounts (int current, int max, int total, SessionHandler manager) { - assertEquals(current, ((DefaultSessionCache)manager.getSessionStore()).getSessionsCurrent()); - assertEquals(max, ((DefaultSessionCache)manager.getSessionStore()).getSessionsMax()); - assertEquals(total, ((DefaultSessionCache)manager.getSessionStore()).getSessionsTotal()); + assertEquals(current, ((DefaultSessionCache)manager.getSessionCache()).getSessionsCurrent()); + assertEquals(max, ((DefaultSessionCache)manager.getSessionCache()).getSessionsMax()); + assertEquals(total, ((DefaultSessionCache)manager.getSessionCache()).getSessionsTotal()); } public static class TestSessionListener implements HttpSessionListener diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLocalSessionScavengingTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLocalSessionScavengingTest.java index 2ffdbbd8f15..b6fae797dae 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLocalSessionScavengingTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLocalSessionScavengingTest.java @@ -40,7 +40,7 @@ import org.junit.Test; */ public abstract class AbstractLocalSessionScavengingTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public void pause(int scavengePeriod) { @@ -61,9 +61,8 @@ public abstract class AbstractLocalSessionScavengingTest String servletMapping = "/server"; int inactivePeriod = 1; int scavengePeriod = 2; - int inspectionPeriod = 2; - int idlePeriod = 20; - AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, idlePeriod); + int evictionSec = 20; + AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, evictionSec); ServletContextHandler context1 = server1.addContext(contextPath); context1.addServlet(TestServlet.class, servletMapping); @@ -71,7 +70,7 @@ public abstract class AbstractLocalSessionScavengingTest { server1.start(); int port1 = server1.getPort(); - AbstractTestServer server2 = createServer(0, inactivePeriod, scavengePeriod * 3, idlePeriod); + AbstractTestServer server2 = createServer(0, inactivePeriod, scavengePeriod * 3, evictionSec); ServletContextHandler context2 = server2.addContext(contextPath); context2.addServlet(TestServlet.class, servletMapping); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractNewSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractNewSessionTest.java index dff96f761b1..7ff306f5566 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractNewSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractNewSessionTest.java @@ -43,7 +43,7 @@ import org.junit.Test; */ public abstract class AbstractNewSessionTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public void pause(int scavenge) { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractOrphanedSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractOrphanedSessionTest.java index 367d2ad3ec6..558d883d5bb 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractOrphanedSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractOrphanedSessionTest.java @@ -41,7 +41,7 @@ import org.junit.Test; public abstract class AbstractOrphanedSessionTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); /** * If nodeA creates a session, and just afterwards crashes, it is the only node that knows about the session. @@ -55,7 +55,7 @@ public abstract class AbstractOrphanedSessionTest String contextPath = ""; String servletMapping = "/server"; int inactivePeriod = 5; - AbstractTestServer server1 = createServer(0, inactivePeriod, -1, -1); + AbstractTestServer server1 = createServer(0, inactivePeriod, -1, SessionCache.NEVER_EVICT); server1.addContext(contextPath).addServlet(TestServlet.class, servletMapping); try { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractProxySerializationTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractProxySerializationTest.java index 098ded2310a..66e556c6c68 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractProxySerializationTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractProxySerializationTest.java @@ -46,7 +46,7 @@ import org.junit.Test; */ public abstract class AbstractProxySerializationTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public abstract void customizeContext (ServletContextHandler c); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractReentrantRequestSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractReentrantRequestSessionTest.java index 1d727eade4b..886fe9751a3 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractReentrantRequestSessionTest.java @@ -31,6 +31,7 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; import org.junit.Test; @@ -42,7 +43,7 @@ import org.junit.Test; */ public abstract class AbstractReentrantRequestSessionTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); @Test public void testReentrantRequestSession() throws Exception @@ -60,8 +61,22 @@ public abstract class AbstractReentrantRequestSessionTest client.start(); try { - ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=reenter&port=" + port + "&path=" + contextPath + servletMapping); + //create the session + ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create&port=" + port + "&path=" + contextPath + servletMapping); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + String sessionCookie = response.getHeaders().get("Set-Cookie"); + assertTrue(sessionCookie != null); + // Mangle the cookie, replacing Path with $Path, etc. + sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); + + //make a request that will make a simultaneous request for the same session + Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=reenter&port=" + port + "&path=" + contextPath + servletMapping); + request.header("Cookie", sessionCookie); + response = request.send(); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + } finally { @@ -85,9 +100,16 @@ public abstract class AbstractReentrantRequestSessionTest @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - HttpSession session = request.getSession(false); + String action = request.getParameter("action"); + if ("create".equals(action)) + { + request.getSession(true); + return; + } + + HttpSession session = request.getSession(false); if ("reenter".equals(action)) { if (session == null) diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java index f1d514bccb0..c73128f3bad 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java @@ -81,8 +81,8 @@ public abstract class AbstractRemoveSessionTest //ensure sessionCreated listener is called assertTrue (testListener.isCreated()); assertEquals(1, m.getSessionsCreated()); - assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax()); - assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal()); + assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsMax()); + assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsTotal()); //now delete the session Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=delete"); @@ -91,18 +91,18 @@ public abstract class AbstractRemoveSessionTest assertEquals(HttpServletResponse.SC_OK,response.getStatus()); //ensure sessionDestroyed listener is called assertTrue(testListener.isDestroyed()); - assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessionsCurrent()); - assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax()); - assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal()); + assertEquals(0, ((DefaultSessionCache)m.getSessionCache()).getSessionsCurrent()); + assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsMax()); + assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsTotal()); // The session is not there anymore, even if we present an old cookie request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=check"); request.header("Cookie", sessionCookie); response = request.send(); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); - assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessionsCurrent()); - assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax()); - assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal()); + assertEquals(0, ((DefaultSessionCache)m.getSessionCache()).getSessionsCurrent()); + assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsMax()); + assertEquals(1, ((DefaultSessionCache)m.getSessionCache()).getSessionsTotal()); } finally { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSameNodeLoadTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSameNodeLoadTest.java index 8ca00599ab8..c974f97a251 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSameNodeLoadTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSameNodeLoadTest.java @@ -53,7 +53,7 @@ public abstract class AbstractSameNodeLoadTest protected boolean _stress = Boolean.getBoolean( "STRESS" ); - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); @Test diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractServerCrossContextSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractServerCrossContextSessionTest.java index d0dca5b1de7..95bb3d4c05d 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractServerCrossContextSessionTest.java @@ -88,8 +88,6 @@ public abstract class AbstractServerCrossContextSessionTest if (session == null) session = request.getSession(true); // Add something to the session session.setAttribute("A", "A"); - - // Perform cross context dispatch to another context // Over there we will check that the session attribute added above is not visible ServletContext contextB = getServletContext().getContext("/contextB"); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCookieTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCookieTest.java index 0f674aa3144..d6f14beb27f 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCookieTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCookieTest.java @@ -43,7 +43,7 @@ import junit.framework.Assert; */ public abstract class AbstractSessionCookieTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public void pause(int scavenge) { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionExpiryTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionExpiryTest.java index c36d1024bb6..b695b1c514e 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionExpiryTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionExpiryTest.java @@ -47,7 +47,7 @@ import org.junit.Test; */ public abstract class AbstractSessionExpiryTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public void pause(int scavengePeriod) { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionInvalidateAndCreateTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionInvalidateAndCreateTest.java index 08d1f81d414..8f2d259c7d9 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionInvalidateAndCreateTest.java @@ -57,7 +57,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest { public class MySessionListener implements HttpSessionListener { - List destroys; + List destroys; public void sessionCreated(HttpSessionEvent e) { @@ -69,11 +69,11 @@ public abstract class AbstractSessionInvalidateAndCreateTest if (destroys == null) destroys = new ArrayList<>(); - destroys.add((String)e.getSession().getAttribute("identity")); + destroys.add(e.getSession().hashCode()); } } - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); @@ -96,8 +96,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest String servletMapping = "/server"; int inactivePeriod = 1; int scavengePeriod = 2; - int idlePassivatePeriod = -1; - AbstractTestServer server = createServer(0, inactivePeriod, scavengePeriod, idlePassivatePeriod); + AbstractTestServer server = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); ServletContextHandler context = server.addContext(contextPath); TestServlet servlet = new TestServlet(); ServletHolder holder = new ServletHolder(servlet); @@ -124,7 +123,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest assertTrue(sessionCookie != null); // Mangle the cookie, replacing Path with $Path, etc. sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); - + // Make a request which will invalidate the existing session and create a new one Request request2 = client.newRequest(url + "?action=test"); request2.header("Cookie", sessionCookie); @@ -136,8 +135,8 @@ public abstract class AbstractSessionInvalidateAndCreateTest //test that the session created in the last test is scavenged: //the HttpSessionListener should have been called when session1 was invalidated and session2 was scavenged - assertTrue(listener.destroys.contains("session1")); - assertTrue(listener.destroys.contains("session2")); + assertTrue(listener.destroys.size() == 2); + assertTrue(listener.destroys.get(0) != listener.destroys.get(1)); //ensure 2 different objects //session2's HttpSessionBindingListener should have been called when it was scavenged assertTrue(servlet.listener.unbound); } @@ -193,6 +192,8 @@ public abstract class AbstractSessionInvalidateAndCreateTest HttpSession session = request.getSession(false); if (session != null) { + String oldId = session.getId(); + //invalidate existing session session.invalidate(); @@ -210,6 +211,9 @@ public abstract class AbstractSessionInvalidateAndCreateTest //now make a new session session = request.getSession(true); + String newId = session.getId(); + assertTrue(!newId.equals(oldId)); + assertTrue (session.getAttribute("identity")==null); session.setAttribute("identity", "session2"); session.setAttribute("listener", listener); } diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionRenewTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionRenewTest.java index 75527fd443d..ac1bd699481 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionRenewTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionRenewTest.java @@ -50,7 +50,7 @@ public abstract class AbstractSessionRenewTest { protected AbstractTestServer _server; - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public abstract boolean verifyChange (WebAppContext context, String oldSessionId, String newSessionId); @@ -63,9 +63,7 @@ public abstract class AbstractSessionRenewTest String servletMapping = "/server"; int maxInactive = 1; int scavengePeriod = 3; - int inspectPeriod = 1; - int idlePassivatePeriod = -1; - _server = createServer(0, maxInactive, scavengePeriod, idlePassivatePeriod); + _server = createServer(0, maxInactive, scavengePeriod, SessionCache.NEVER_EVICT); WebAppContext context = _server.addWebAppContext(".", contextPath); context.setParentLoaderPriority(true); context.addServlet(TestServlet.class, servletMapping); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionValueSavingTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionValueSavingTest.java index dcead37a6e8..2d40c500807 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionValueSavingTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionValueSavingTest.java @@ -41,7 +41,7 @@ import org.junit.Test; */ public abstract class AbstractSessionValueSavingTest { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod); + public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); @Test public void testSessionValueSaving() throws Exception @@ -50,9 +50,7 @@ public abstract class AbstractSessionValueSavingTest String servletMapping = "/server"; int maxInactivePeriod = 10000; int scavengePeriod = 20000; - int inspectPeriod = 5; - int idlePassivatePeriod = -1; - AbstractTestServer server1 = createServer(0, maxInactivePeriod, scavengePeriod, idlePassivatePeriod); + AbstractTestServer server1 = createServer(0, maxInactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); server1.addContext(contextPath).addServlet(TestServlet.class, servletMapping); try diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestServer.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestServer.java index 068701a4c36..9d7b966fe0f 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestServer.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestServer.java @@ -36,13 +36,13 @@ public abstract class AbstractTestServer public static int DEFAULT_MAX_INACTIVE = 30; public static int DEFAULT_SCAVENGE_SEC = 10; - public static int DEFAULT_IDLE_PASSIVATE_SEC = 2; + public static int DEFAULT_EVICTIONPOLICY = SessionCache.NEVER_EVICT; protected static int __workers=0; protected final Server _server; protected final int _maxInactivePeriod; - protected final int _idlePassivatePeriod; + protected final int _evictionPolicy; protected final int _scavengePeriod; protected final ContextHandlerCollection _contexts; protected SessionIdManager _sessionIdManager; @@ -71,20 +71,20 @@ public abstract class AbstractTestServer public AbstractTestServer(int port) { - this(port, DEFAULT_MAX_INACTIVE, DEFAULT_SCAVENGE_SEC, DEFAULT_IDLE_PASSIVATE_SEC); + this(port, DEFAULT_MAX_INACTIVE, DEFAULT_SCAVENGE_SEC, DEFAULT_EVICTIONPOLICY); } - public AbstractTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod) + public AbstractTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy) { - this (port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod, null); + this (port, maxInactivePeriod, scavengePeriod, evictionPolicy, null); } - public AbstractTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod, Object cfg) + public AbstractTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy, Object cfg) { _server = new Server(port); _maxInactivePeriod = maxInactivePeriod; _scavengePeriod = scavengePeriod; - _idlePassivatePeriod = idlePassivatePeriod; + _evictionPolicy = evictionPolicy; _contexts = new ContextHandlerCollection(); _config = cfg; _sessionIdManager = newSessionIdManager(); @@ -134,7 +134,7 @@ public abstract class AbstractTestServer SessionHandler sessionHandler = newSessionHandler(); sessionHandler.setSessionIdManager(_sessionIdManager); sessionHandler.setMaxInactiveInterval(_maxInactivePeriod); - sessionHandler.getSessionStore().setIdlePassivationTimeoutSec(_idlePassivatePeriod); + sessionHandler.getSessionCache().setEvictionPolicy(_evictionPolicy); context.setSessionHandler(sessionHandler); return context; @@ -156,7 +156,7 @@ public abstract class AbstractTestServer SessionHandler sessionHandler = newSessionHandler(); sessionHandler.setSessionIdManager(_sessionIdManager); sessionHandler.setMaxInactiveInterval(_maxInactivePeriod); - sessionHandler.getSessionStore().setIdlePassivationTimeoutSec(_idlePassivatePeriod); + sessionHandler.getSessionCache().setEvictionPolicy(_evictionPolicy); context.setSessionHandler(sessionHandler); return context; diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index 8ffbe4bfe6c..95a25b19d4b 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -44,7 +44,7 @@ import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.server.session.FileSessionStore; +import org.eclipse.jetty.server.session.FileSessionDataStore; import org.eclipse.jetty.server.session.DefaultSessionCache; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -133,10 +133,10 @@ public class TestServer sessiondir.mkdir(); sessiondir.deleteOnExit(); DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler()); - FileSessionStore sds = new FileSessionStore(); - ss.setSessionStore(sds); + FileSessionDataStore sds = new FileSessionDataStore(); + ss.setSessionDataStore(sds); sds.setStoreDir(sessiondir); - webapp.getSessionHandler().setSessionStore(ss); + webapp.getSessionHandler().setSessionCache(ss); contexts.addHandler(webapp);