From 31ea1704a1fdaef6f7d862dfacb905c5ac4728a3 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Fri, 11 Dec 2015 11:42:29 +1100 Subject: [PATCH] Make calling passivate/active depend on type of session data store; fix tests --- .../session/GCloudSessionDataStore.java | 9 + .../session/GCloudSessionIdManager.java | 7 +- .../InfinispanSessionDataStore.java | 15 +- .../InfinispanSessionIdManager.java | 7 +- .../nosql/mongodb/MongoSessionDataStore.java | 14 +- .../nosql/mongodb/MongoSessionIdManager.java | 5 +- .../jetty/proxy/BalancerServletTest.java | 2 +- .../session/AbstractSessionIdManager.java | 6 +- .../server/session/AbstractSessionStore.java | 8 +- .../session/CachingSessionDataStore.java | 9 + .../jetty/server/session/ContextId.java | 2 +- .../server/session/FileSessionDataStore.java | 11 +- .../server/session/HashSessionIdManager.java | 9 + .../server/session/JDBCSessionDataStore.java | 13 ++ .../server/session/JDBCSessionIdManager.java | 6 +- .../server/session/NullSessionDataStore.java | 10 ++ .../server/session/SessionDataStore.java | 7 + .../jetty/server/session/SessionManager.java | 9 +- .../eclipse/jetty/server/ResponseTest.java | 8 +- .../session/FileSessionManagerTest.java | 13 +- .../server/session/SessionCookieTest.java | 12 +- .../jetty/server/session/FileTestServer.java | 2 +- .../jetty/server/session/HashTestServer.java | 2 +- .../server/session/InfinispanTestSupport.java | 1 - .../server/session/LastAccessTimeTest.java | 9 - .../ReloadedSessionMissingClassTest.java | 2 +- .../nosql/mongodb/AttributeNameTest.java | 14 ++ .../ClientCrossContextSessionTest.java | 16 ++ .../nosql/mongodb/ForwardedSessionTest.java | 16 ++ .../nosql/mongodb/InvalidateSessionTest.java | 16 ++ .../nosql/mongodb/LastAccessTimeTest.java | 21 +++ .../mongodb/LocalSessionScavengingTest.java | 16 ++ .../jetty/nosql/mongodb/MongoTestServer.java | 43 ++--- .../jetty/nosql/mongodb/NewSessionTest.java | 16 ++ .../nosql/mongodb/OrphanedSessionTest.java | 17 ++ .../mongodb/PurgeInvalidSessionTest.java | 3 +- .../nosql/mongodb/PurgeValidSessionTest.java | 6 +- .../mongodb/ReentrantRequestSessionTest.java | 17 ++ .../nosql/mongodb/RemoveSessionTest.java | 16 ++ .../nosql/mongodb/ScatterGunLoadTest.java | 16 ++ .../ServerCrossContextSessionTest.java | 17 ++ .../nosql/mongodb/SessionExpiryTest.java | 16 ++ .../SessionInvalidateAndCreateTest.java | 16 ++ .../nosql/mongodb/SessionMigrationTest.java | 16 ++ .../jetty/nosql/mongodb/SessionRenewTest.java | 16 ++ .../nosql/mongodb/SessionSavingValueTest.java | 16 ++ .../StopSessionManagerDeleteSessionTest.java | 163 ------------------ ...StopSessionManagerPreserveSessionTest.java | 98 ----------- .../AbstractInvalidationSessionTest.java | 2 +- .../session/AbstractLastAccessTimeTest.java | 37 ++-- 50 files changed, 461 insertions(+), 367 deletions(-) delete mode 100644 tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerDeleteSessionTest.java delete mode 100644 tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerPreserveSessionTest.java diff --git a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java index 14ed51a4d65..b601d76831d 100644 --- a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java +++ b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java @@ -384,6 +384,15 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore return reference.get(); } + + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return true; + } } diff --git a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionIdManager.java b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionIdManager.java index b3157c9114d..f290f8137dc 100644 --- a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionIdManager.java +++ b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionIdManager.java @@ -45,7 +45,6 @@ public class GCloudSessionIdManager extends AbstractSessionIdManager private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); public static final int DEFAULT_IDLE_EXPIRY_MULTIPLE = 2; public static final String KIND = "GCloudSessionId"; - private Server _server; private Datastore _datastore; private KeyFactory _keyFactory; private GCloudConfiguration _config; @@ -58,8 +57,7 @@ public class GCloudSessionIdManager extends AbstractSessionIdManager */ public GCloudSessionIdManager(Server server) { - super(); - _server = server; + super(server); } /** @@ -68,8 +66,7 @@ public class GCloudSessionIdManager extends AbstractSessionIdManager */ public GCloudSessionIdManager(Server server, Random random) { - super(random); - _server = server; + super(server,random); } diff --git a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java index 6c3a2a1b960..18b3ef09d4b 100644 --- a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java +++ b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java @@ -121,7 +121,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore try { SessionData sd = load(candidate); - if (sd.isExpiredAt(now)) + if (sd == null || sd.isExpiredAt(now)) expired.add(candidate); } @@ -159,6 +159,17 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore public static String getCacheKey (String id, ContextId contextId) { - return contextId.toString()+"_"+id; + return contextId.getCanonicalContextPath()+"_"+contextId.getVhost()+"_"+id; + } + + + + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return true; } } diff --git a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionIdManager.java b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionIdManager.java index 9b596b5a957..b2a1d35ec25 100644 --- a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionIdManager.java +++ b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionIdManager.java @@ -70,7 +70,6 @@ public class InfinispanSessionIdManager extends AbstractSessionIdManager public final static String ID_KEY = "__o.e.j.s.infinispanIdMgr__"; public static final int DEFAULT_IDLE_EXPIRY_MULTIPLE = 2; protected BasicCache _cache; - private Server _server; private int _idleExpiryMultiple = DEFAULT_IDLE_EXPIRY_MULTIPLE; @@ -79,14 +78,12 @@ public class InfinispanSessionIdManager extends AbstractSessionIdManager public InfinispanSessionIdManager(Server server) { - super(); - _server = server; + super(server); } public InfinispanSessionIdManager(Server server, Random random) { - super(random); - _server = server; + super(server, random); } diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java index a5663b1165b..656180e2a78 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java @@ -345,7 +345,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore for ( DBObject session : verifiedExpiredSessions ) { String id = (String)session.get(__ID); - if (LOG.isDebugEnabled()) LOG.debug("Mongo confirmed expired session {}", id); + if (LOG.isDebugEnabled()) LOG.debug("{} Mongo confirmed expired session {}", _contextId,id); expiredSessions.add(id); } } @@ -368,7 +368,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore for (DBObject session : oldExpiredSessions) { String id = (String)session.get(__ID); - if (LOG.isDebugEnabled()) LOG.debug("Mongo found old expired session {}", id); + if (LOG.isDebugEnabled()) LOG.debug("{} Mongo found old expired session {}", _contextId, id); expiredSessions.add(id); } @@ -615,4 +615,14 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore return temp.get(keyChain[keyChain.length - 1]); } + + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return true; + } + } diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java index 5fa3e32f714..24a3e04f249 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java @@ -54,7 +54,6 @@ public class MongoSessionIdManager extends AbstractSessionIdManager final DBCollection _sessions; - protected Server _server; /** @@ -75,9 +74,8 @@ public class MongoSessionIdManager extends AbstractSessionIdManager /* ------------------------------------------------------------ */ public MongoSessionIdManager(Server server, DBCollection sessions) { - super(new Random()); + super(server, new Random()); - _server = server; _sessions = sessions; _sessions.ensureIndex( @@ -95,7 +93,6 @@ public class MongoSessionIdManager extends AbstractSessionIdManager BasicDBObjectBuilder.start().add("sparse", false).add("background", true).get()); } - /* ------------------------------------------------------------ */ diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/BalancerServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/BalancerServletTest.java index 4d29b131adc..d7b2420ee40 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/BalancerServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/BalancerServletTest.java @@ -99,7 +99,7 @@ public class BalancerServletTest if (nodeName != null) { - AbstractSessionIdManager sessionIdManager = new HashSessionIdManager(); + AbstractSessionIdManager sessionIdManager = new HashSessionIdManager(server); sessionIdManager.setWorkerName(nodeName); server.setSessionIdManager(sessionIdManager); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java index 9c399703528..0a0f9e921e0 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionIdManager.java @@ -46,13 +46,15 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme protected SessionScavenger _scavenger; /* ------------------------------------------------------------ */ - public AbstractSessionIdManager() + public AbstractSessionIdManager(Server server) { + _server = server; } /* ------------------------------------------------------------ */ - public AbstractSessionIdManager(Random random) + public AbstractSessionIdManager(Server server, Random random) { + this(server); _random=random; } 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/AbstractSessionStore.java index a489940d8de..39b580e32ef 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/AbstractSessionStore.java @@ -232,13 +232,15 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements throw new IllegalArgumentException ("Put key="+id+" session="+(session==null?"null":session.getId())); session.setSessionManager(_manager); - + //if the session is new, the data has changed, or the cache is considered stale, write it to any backing store if ((session.isNew() || session.getSessionData().isDirty() || isStale(session)) && _sessionDataStore != null) { - session.willPassivate(); + if (_sessionDataStore.isPassivating()) + session.willPassivate(); _sessionDataStore.store(id, session.getSessionData()); - session.didActivate(); + if (_sessionDataStore.isPassivating()) + session.didActivate(); } doPutIfAbsent(id,session); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionDataStore.java index bc170181464..f68d81252bf 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionDataStore.java @@ -156,6 +156,15 @@ public class CachingSessionDataStore extends AbstractSessionDataStore super.doStop(); } + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return true; + } + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/ContextId.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/ContextId.java index ae95dce8150..6824ebc2e75 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/ContextId.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/ContextId.java @@ -37,7 +37,7 @@ public class ContextId public static ContextId getContextId (String node, Context context) { - return new ContextId(node, getContextPath(context), getVirtualHost(context)); + return new ContextId((node==null?"":node), getContextPath(context), getVirtualHost(context)); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java index 4e49f6b7827..bbef34e3567 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java @@ -221,7 +221,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore File file = null; if (_storeDir != null) { - file = new File(_storeDir, id); + file = new File(_storeDir, _contextId.toString()+"_"+id); if (file.exists()) file.delete(); @@ -274,6 +274,15 @@ public class FileSessionDataStore extends AbstractSessionDataStore if (!_storeDir.exists()) _storeDir.mkdirs(); } + + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return true; + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java index cddcb5924da..70d94259e4c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionIdManager.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.server.session; import java.util.Set; +import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.ConcurrentHashSet; /** @@ -30,6 +31,14 @@ import org.eclipse.jetty.util.ConcurrentHashSet; */ public class HashSessionIdManager extends AbstractSessionIdManager { + /** + * @param server + */ + public HashSessionIdManager(Server server) + { + super(server); + } + private final Set _ids = new ConcurrentHashSet(); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java index e8be2b19c3f..e73e7bba2f1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java @@ -1020,6 +1020,19 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore { _unloadables.clear(); } + + + + + + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return true; + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java index 8c7bf55365c..55d2a3df9d8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java @@ -144,14 +144,12 @@ public class JDBCSessionIdManager extends org.eclipse.jetty.server.session.Abstr public JDBCSessionIdManager(Server server) { - super(); - _server=server; + super(server); } public JDBCSessionIdManager(Server server, Random random) { - super(random); - _server=server; + super(server,random); } public SessionIdTableSchema getSessionIdTableSchema() diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java index c7d9897d52f..35de7f0f6c5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionDataStore.java @@ -75,4 +75,14 @@ public class NullSessionDataStore extends AbstractSessionDataStore return candidates; //whatever is suggested we accept } + + /** + * @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating() + */ + @Override + public boolean isPassivating() + { + return false; + } + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java index 7130060dbb3..78c014c3562 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionDataStore.java @@ -93,4 +93,11 @@ public interface SessionDataStore extends LifeCycle public Set getExpired (Set candidates); + + /** + * True if this type of datastore will passivate session objects + * @return + */ + public boolean isPassivating (); + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionManager.java index eb50d4eee5b..2314456a15d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionManager.java @@ -233,8 +233,6 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je if (_sessionStore == null) throw new IllegalStateException("No session store configured"); - if (_sessionIdManager == null) - throw new IllegalStateException("No session id manager"); _context=ContextHandler.getCurrentContext(); _loader=Thread.currentThread().getContextClassLoader(); @@ -255,7 +253,7 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je try { Thread.currentThread().setContextClassLoader(serverLoader); - _sessionIdManager=new HashSessionIdManager(); + _sessionIdManager=new HashSessionIdManager(server); server.setSessionIdManager(_sessionIdManager); server.manage(_sessionIdManager); _sessionIdManager.start(); @@ -302,10 +300,9 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je tmp=_context.getInitParameter(org.eclipse.jetty.server.SessionManager.__CheckRemoteSessionEncoding); if (tmp!=null) _checkingRemoteSessionIdEncoding=Boolean.parseBoolean(tmp); - - _contextId = ContextId.getContextId(_sessionIdManager.getWorkerName(), _context); } + _contextId = ContextId.getContextId(_sessionIdManager.getWorkerName(), _context); if (_sessionStore instanceof AbstractSessionStore) ((AbstractSessionStore)_sessionStore).setSessionManager(this); @@ -985,7 +982,7 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je return; // couldn't get/load a session for this context with that id } - _sessionTimeStats.set(round((System.currentTimeMillis() - session.getCreationTime())/1000.0)); + _sessionTimeStats.set(round((System.currentTimeMillis() - session.getSessionData().getCreated())/1000.0)); session.invalidateAndRemove(); } catch (Exception e) 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 b5942464891..7f8bce900be 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 @@ -466,9 +466,11 @@ public class ResponseTest request.setRequestedSessionId("12345"); request.setRequestedSessionIdFromCookie(false); HashSessionManager manager = new HashSessionManager(); - manager.setSessionIdManager(new HashSessionIdManager()); + manager.setSessionIdManager(new HashSessionIdManager(_server)); request.setSessionManager(manager); - request.setSession(new TestSession(manager, "12345")); + TestSession tsession = new TestSession(manager, "12345"); + tsession.setExtendedId(manager.getSessionIdManager().getExtendedId("12345", null)); + request.setSession(tsession); manager.setCheckingRemoteSessionIdEncoding(false); @@ -541,7 +543,7 @@ public class ResponseTest request.setRequestedSessionId("12345"); request.setRequestedSessionIdFromCookie(i>2); HashSessionManager manager = new HashSessionManager(); - manager.setSessionIdManager(new HashSessionIdManager()); + manager.setSessionIdManager(new HashSessionIdManager(_server)); request.setSessionManager(manager); request.setSession(new TestSession(manager, "12345")); manager.setCheckingRemoteSessionIdEncoding(false); 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 306059e6978..bf887ddb5bc 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 @@ -60,7 +60,7 @@ public class FileSessionManagerTest Server server = new Server(); SessionHandler handler = new SessionHandler(); handler.setServer(server); - final HashSessionIdManager idmgr = new HashSessionIdManager(); + final HashSessionIdManager idmgr = new HashSessionIdManager(server); idmgr.setServer(server); server.setSessionIdManager(idmgr); @@ -92,7 +92,7 @@ public class FileSessionManagerTest Server server = new Server(); SessionHandler handler = new SessionHandler(); handler.setServer(server); - final HashSessionIdManager idmgr = new HashSessionIdManager(); + final HashSessionIdManager idmgr = new HashSessionIdManager(server); idmgr.setServer(server); server.setSessionIdManager(idmgr); final FileSessionManager manager = new FileSessionManager(); @@ -106,7 +106,7 @@ public class FileSessionManagerTest manager.start(); //See SessionKey.getKey() - String expectedFilename = "_0.0.0.0_validFile123"; + String expectedFilename = "__0.0.0.0_validFile123"; Assert.assertTrue(new File(testDir, expectedFilename).createNewFile()); @@ -134,7 +134,7 @@ public class FileSessionManagerTest Assert.assertTrue(testDir.canWrite()); handler.setSessionManager(manager); - AbstractSessionIdManager idManager = new HashSessionIdManager(); + AbstractSessionIdManager idManager = new HashSessionIdManager(server); idManager.setServer(server); idManager.setWorkerName("foo"); manager.setSessionIdManager(idManager); @@ -153,10 +153,7 @@ public class FileSessionManagerTest manager.setMaxInactiveInterval(30); // change max inactive interval for *new* sessions manager.stop(); - for (String f: testDir.list()) - System.err.println(f); - - String expectedFilename = "_0.0.0.0_"+session.getId(); + String expectedFilename = "foo__0.0.0.0_"+session.getId(); Assert.assertTrue("File should exist!", new File(testDir, expectedFilename).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 c28a49edc86..b7e75827688 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 @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.eclipse.jetty.http.HttpCookie; +import org.eclipse.jetty.server.Server; import org.junit.Test; /** @@ -127,6 +128,14 @@ public class SessionCookieTest public class MockSessionIdManager extends AbstractSessionIdManager { + /** + * @param server + */ + public MockSessionIdManager(Server server) + { + super(server); + } + /** * @see org.eclipse.jetty.server.SessionIdManager#isIdInUse(java.lang.String) */ @@ -187,7 +196,8 @@ public class SessionCookieTest @Test public void testSecureSessionCookie () throws Exception { - MockSessionIdManager idMgr = new MockSessionIdManager(); + Server server = new Server(); + MockSessionIdManager idMgr = new MockSessionIdManager(server); idMgr.setWorkerName("node1"); MockSessionManager mgr = new MockSessionManager(); mgr.setSessionIdManager(idMgr); 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 390b3b82868..c3c89a47475 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 @@ -64,7 +64,7 @@ public class FileTestServer extends AbstractTestServer public SessionIdManager newSessionIdManager(Object config) { - HashSessionIdManager mgr = new HashSessionIdManager(); + HashSessionIdManager mgr = new HashSessionIdManager(_server); mgr.setWorkerName("worker"+(__workers++)); return mgr; } 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 dd4de0e3a62..11e3f5ef4a8 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 @@ -41,7 +41,7 @@ public class HashTestServer extends AbstractTestServer public SessionIdManager newSessionIdManager(Object config) { - HashSessionIdManager mgr = new HashSessionIdManager(); + HashSessionIdManager mgr = new HashSessionIdManager(_server); mgr.setWorkerName("worker"+(__workers++)); return mgr; } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java index a3b61bd1221..04a3fedbc52 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java @@ -88,7 +88,6 @@ public class InfinispanTestSupport _tmpdir = File.createTempFile("infini", "span"); _tmpdir.delete(); _tmpdir.mkdir(); - System.err.println("Temp file: "+_tmpdir); Configuration config = _builder.persistence().addSingleFileStore().location(_tmpdir.getAbsolutePath()).storeAsBinary().build(); _manager.defineConfiguration(_name, config); } 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 442da4cc456..9fe361d5f88 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 @@ -52,14 +52,5 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest { super.testLastAccessTime(); } - - @Override - public void assertAfterScavenge(SessionManager manager) - { - //The infinispan session manager will remove a session from its local memory that was a candidate to be scavenged if - //it checks with the cluster and discovers that another node is managing it, so the count is 0 - assertSessionCounts(0, 1, 1, manager); - } - } diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java index 44acb9d2632..6d4917ce073 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java @@ -53,7 +53,7 @@ public class ReloadedSessionMissingClassTest @Test public void testSessionReloadWithMissingClass() throws Exception { - ((StdErrLog)Log.getLogger(org.eclipse.jetty.server.session.JDBCSessionManager.class)).setHideStacks(true); + ((StdErrLog)Log.getLogger("org.eclipse.jetty.server.session")).setHideStacks(true); Resource.setDefaultUseCaches(false); String contextPath = "/foo"; 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 02a4e124aa8..c4f6202c9a5 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,8 @@ 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.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -48,7 +50,19 @@ import org.junit.Test; public class AttributeNameTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } public AbstractTestServer createServer(int port, int max, int scavenge) throws Exception diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ClientCrossContextSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ClientCrossContextSessionTest.java index 58798067a78..3f7a19850fd 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ClientCrossContextSessionTest.java @@ -20,10 +20,26 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractClientCrossContextSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class ClientCrossContextSessionTest extends AbstractClientCrossContextSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + public AbstractTestServer createServer(int port) { return new MongoTestServer(port); diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ForwardedSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ForwardedSessionTest.java index 6cd4c59499d..a126442a413 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ForwardedSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ForwardedSessionTest.java @@ -21,6 +21,8 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractForwardedSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -30,7 +32,21 @@ import org.junit.Test; */ public class ForwardedSessionTest extends AbstractForwardedSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + + /** * @see org.eclipse.jetty.server.session.AbstractForwardedSessionTest#createServer(int) */ 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 510c8eccd96..73de70cb6b6 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 @@ -21,11 +21,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractInvalidationSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class InvalidateSessionTest extends AbstractInvalidationSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port) { 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 bf86b5e1ff2..c84ef67c4e8 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 @@ -20,19 +20,40 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractLastAccessTimeTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class LastAccessTimeTest extends AbstractLastAccessTimeTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + public AbstractTestServer createServer(int port, int max, int scavenge) { return new MongoTestServer(port,max,scavenge); } + + + @Test public void testLastAccessTime() throws Exception { super.testLastAccessTime(); } + + } 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 0ad644bcc30..e1be78a4f79 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 @@ -20,10 +20,26 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port, int max, int scavenge) { 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 f85451ceb6e..ee1597ec654 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 @@ -20,7 +20,6 @@ package org.eclipse.jetty.nosql.mongodb; import java.net.UnknownHostException; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.SessionManager; import org.eclipse.jetty.server.session.AbstractSessionStore; @@ -28,9 +27,8 @@ import org.eclipse.jetty.server.session.AbstractTestServer; import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.server.session.StalePeriodStrategy; -import com.mongodb.BasicDBObject; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; +import com.mongodb.DBCollection; +import com.mongodb.Mongo; import com.mongodb.MongoException; @@ -44,27 +42,25 @@ public class MongoTestServer extends AbstractTestServer - public static class TestMongoSessionIdManager extends MongoSessionIdManager + public static void dropCollection () throws MongoException, UnknownHostException { - - public TestMongoSessionIdManager(Server server) throws UnknownHostException, MongoException - { - super(server); - } - - - public void deleteAll () - { - - DBCursor checkSessions = _sessions.find(); - - for (DBObject session : checkSessions) - { - _sessions.remove(session); - } - } + new Mongo().getDB("HttpSessions").getCollection("testsessions").drop(); } + + public static void createCollection() throws UnknownHostException, MongoException + { + new Mongo().getDB("HttpSessions").createCollection("testsessions", null); + } + + + public static DBCollection getCollection () throws UnknownHostException, MongoException + { + return new Mongo().getDB("HttpSessions").getCollection("testsessions"); + } + + + public MongoTestServer(int port) { super(port, 30, 10); @@ -85,8 +81,7 @@ public class MongoTestServer extends AbstractTestServer { try { - System.err.println("MongoTestServer:SessionIdManager scavenge: delay:"+ _scavengePeriod + " period:"+_scavengePeriod); - MongoSessionIdManager idManager = new TestMongoSessionIdManager(_server); + MongoSessionIdManager idManager = new MongoSessionIdManager(_server, getCollection()); idManager.setWorkerName("w"+(__workers++)); return idManager; 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 2e6f6a679a6..4a674cfd60b 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 @@ -20,6 +20,8 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractNewSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -27,6 +29,20 @@ import org.junit.Test; */ public class NewSessionTest extends AbstractNewSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + public AbstractTestServer createServer(int port, int max, int scavenge) { 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 7299cbd334c..cc8dbf0ce8c 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 @@ -20,6 +20,8 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractOrphanedSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -27,6 +29,21 @@ import org.junit.Test; */ public class OrphanedSessionTest extends AbstractOrphanedSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + + public AbstractTestServer createServer(int port, int max, int scavenge) { return new MongoTestServer(port,max,scavenge); diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeInvalidSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeInvalidSessionTest.java index 0e6689fb1ef..4ccfe6e8061 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeInvalidSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeInvalidSessionTest.java @@ -36,7 +36,6 @@ import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.servlet.ServletContextHandler; import org.junit.Ignore; -import org.junit.Test; import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; @@ -127,7 +126,7 @@ public class PurgeInvalidSessionTest } - @Test + @Ignore public void testPurgeInvalidSessionsWithLimit() throws Exception { String contextPath = ""; diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeValidSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeValidSessionTest.java index 3daca5049d8..c770e222283 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeValidSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/PurgeValidSessionTest.java @@ -34,10 +34,8 @@ 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.nosql.mongodb.MongoTestServer.TestMongoSessionIdManager; import org.eclipse.jetty.servlet.ServletContextHandler; import org.junit.Ignore; -import org.junit.Test; import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; @@ -125,7 +123,7 @@ public class PurgeValidSessionTest } - @Test + @Ignore public void testPurgeValidSessionWithPurgeLimitSet() throws Exception { String contextPath = ""; @@ -153,7 +151,7 @@ public class PurgeValidSessionTest try { // start with no sessions - ((TestMongoSessionIdManager)idManager).deleteAll(); + //((TestMongoSessionIdManager)idManager).deleteAll(); HttpClient client = new HttpClient(); client.start(); 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 1666c3f93a1..ee839d0aea9 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 @@ -20,6 +20,8 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -27,6 +29,21 @@ import org.junit.Test; */ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + + public AbstractTestServer createServer(int port) { return new MongoTestServer(port); 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 13ac126132e..be6cffea327 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 @@ -20,11 +20,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractRemoveSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class RemoveSessionTest extends AbstractRemoveSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + public AbstractTestServer createServer(int port, int max, int scavenge) { return new MongoTestServer(port,max,scavenge); diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ScatterGunLoadTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ScatterGunLoadTest.java index 0e5af91da26..b700d29e5d5 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ScatterGunLoadTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ScatterGunLoadTest.java @@ -20,6 +20,8 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractScatterGunLoadTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -27,6 +29,20 @@ import org.junit.Test; */ public class ScatterGunLoadTest extends AbstractScatterGunLoadTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + public AbstractTestServer createServer(int port) { diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ServerCrossContextSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ServerCrossContextSessionTest.java index 7504e07c3af..956134a89f8 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ServerCrossContextSessionTest.java @@ -20,11 +20,28 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractServerCrossContextSessionTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class ServerCrossContextSessionTest extends AbstractServerCrossContextSessionTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + + public AbstractTestServer createServer(int port) { return new MongoTestServer(port); 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 54df88f08cf..1fd9de38357 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 @@ -20,11 +20,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractSessionExpiryTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class SessionExpiryTest extends AbstractSessionExpiryTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port, int max, int scavenge) { 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 b40f4e53efe..5002c6708e8 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 @@ -20,11 +20,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAndCreateTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port, int max, int scavenge) { diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionMigrationTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionMigrationTest.java index 04014b51fc7..e7e2642e34b 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionMigrationTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/SessionMigrationTest.java @@ -20,11 +20,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractSessionMigrationTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class SessionMigrationTest extends AbstractSessionMigrationTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port) { 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 d0da35d6481..4bf75fb7215 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 @@ -20,11 +20,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractSessionRenewTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class SessionRenewTest extends AbstractSessionRenewTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port, int max, int scavenge) { 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 52fe20cb52c..6b02b95f9b6 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 @@ -20,11 +20,27 @@ package org.eclipse.jetty.nosql.mongodb; import org.eclipse.jetty.server.session.AbstractSessionValueSavingTest; import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class SessionSavingValueTest extends AbstractSessionValueSavingTest { + + @BeforeClass + public static void beforeClass() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @AfterClass + public static void afterClass() throws Exception + { + MongoTestServer.dropCollection(); + } + @Override public AbstractTestServer createServer(int port, int max, int scavenge) { diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerDeleteSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerDeleteSessionTest.java deleted file mode 100644 index 201bc5bd628..00000000000 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerDeleteSessionTest.java +++ /dev/null @@ -1,163 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2015 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.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.net.UnknownHostException; - -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.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.Ignore; -import org.junit.Test; - -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.Mongo; -import com.mongodb.MongoException; - -public class StopSessionManagerDeleteSessionTest -{ - public MongoTestServer createServer(int port, int max, int scavenge) - { - MongoTestServer server = new MongoTestServer(port,max,scavenge); - - return server; - } - - /** - * @throws Exception - */ - @Ignore - public void testStopSessionManagerDeleteSession() throws Exception - { - String contextPath = ""; - String servletMapping = "/server"; - - MongoTestServer server = createServer(0, 1, 0); - ServletContextHandler context = server.addContext(contextPath); - ServletHolder holder = new ServletHolder(); - TestServlet servlet = new TestServlet(); - holder.setServlet(servlet); - - context.addServlet(holder, servletMapping); - - MongoSessionManager sessionManager = (MongoSessionManager)context.getSessionHandler().getSessionManager(); - MongoSessionIdManager idManager = (MongoSessionIdManager)server.getServer().getSessionIdManager(); - - - server.start(); - int port=server.getPort(); - try - { - HttpClient client = new HttpClient(); - client.start(); - try - { - //Create a session - ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create"); - 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="); - - //stop the session manager - sessionManager.stop(); - - //check the database to see that the session has been marked invalid - servlet.checkSessionInDB(false); - - } - finally - { - client.stop(); - } - } - finally - { - server.stop(); - } - } - - - public static class TestServlet extends HttpServlet - { - DBCollection _sessions; - String _id; - - public TestServlet() throws UnknownHostException, MongoException - { - super(); - _sessions = new Mongo().getDB("HttpSessions").getCollection("sessions"); - } - - public void checkSessionInDB (boolean expectedValid) - { - DBObject dbSession = _sessions.findOne(new BasicDBObject("id", _id)); - assertTrue(dbSession != null); - assertEquals(expectedValid, dbSession.get("valid")); -/* if (!expectedValid) - assertNotNull(dbSession.get(MongoSessionDataStore.__INVALIDATED));*/ - } - - public String getId() - { - return _id; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException - { - String action = request.getParameter("action"); - if ("create".equals(action)) - { - HttpSession session = request.getSession(true); - session.setAttribute("foo", "bar"); - assertTrue(session.isNew()); - _id = session.getId(); - } - else if ("test".equals(action)) - { - String id = request.getRequestedSessionId(); - assertNotNull(id); - id = id.substring(0, id.indexOf(".")); - - HttpSession existingSession = request.getSession(false); - assertTrue(existingSession == null); - - //not in db any more - DBObject dbSession = _sessions.findOne(new BasicDBObject("id", id)); - assertTrue(dbSession == null); - } - } - } -} diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerPreserveSessionTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerPreserveSessionTest.java deleted file mode 100644 index 2fcf2e87289..00000000000 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/StopSessionManagerPreserveSessionTest.java +++ /dev/null @@ -1,98 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2015 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.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.net.UnknownHostException; - -import org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.junit.Before; -import org.junit.Test; - -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.Mongo; -import com.mongodb.MongoException; - -/** - * StopSessionManagerPreserveSessionTest - * - * - */ -public class StopSessionManagerPreserveSessionTest extends AbstractStopSessionManagerPreserveSessionTest -{ - DBCollection _sessions; - - @Before - public void setUp() throws UnknownHostException, MongoException - { - _sessions = new Mongo().getDB("HttpSessions").getCollection("sessions"); - } - - - - public MongoTestServer createServer(int port) - { - MongoTestServer server = new MongoTestServer(port); - server.getServer().setStopTimeout(0); - return server; - } - - - - @Override - public void checkSessionPersisted(boolean expected) - { - DBObject dbSession = _sessions.findOne(new BasicDBObject("id", _id)); - - if (expected) - { - assertTrue(dbSession != null); - assertEquals(expected, dbSession.get("valid")); - } - else - { - assertTrue(dbSession==null); - } - } - - - @Override - public void configureSessionManagement(ServletContextHandler context) - { - - } - - /** - * @throws Exception - */ - @Test - public void testStopSessionManagerPreserveSession() throws Exception - { - super.testStopSessionManagerPreserveSession(); - } - - - -} 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 dcd830aa67e..83e4d1dd78e 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 @@ -85,7 +85,7 @@ public abstract class AbstractInvalidationSessionTest assertTrue(sessionCookie != null); // Mangle the cookie, replacing Path with $Path, etc. sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); - + // Be sure the session is also present in node2 Request request2 = client.newRequest(urls[1] + "?action=increment"); request2.header("Cookie", sessionCookie); 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 4f954d4b1e7..d684bef41bd 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 @@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.PrintWriter; +import java.util.HashSet; +import java.util.Set; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -51,7 +53,10 @@ import org.junit.Test; */ public abstract class AbstractLastAccessTimeTest { + public abstract AbstractTestServer createServer(int port, int max, int scavenge); + + @Test public void testLastAccessTime() throws Exception @@ -120,12 +125,13 @@ public abstract class AbstractLastAccessTimeTest Thread.sleep(requestInterval); assertSessionCounts(1,1,1, m2); } + // At this point, session1 should be eligible for expiration. // Let's wait for the scavenger to run, waiting 2.5 times the scavenger period Thread.sleep(scavengePeriod * 2500L); //check that the session was not scavenged over on server1 by ensuring that the SessionListener destroy method wasn't called - assertFalse(listener1.destroyed); + assertFalse(listener1._destroys.contains(AbstractTestServer.extractSessionId(sessionCookie))); assertAfterScavenge(m1); } finally @@ -163,19 +169,19 @@ public abstract class AbstractLastAccessTimeTest public static class TestSessionListener implements HttpSessionListener { - public boolean destroyed = false; - public boolean created = false; + public Set _creates = new HashSet(); + public Set _destroys = new HashSet(); @Override public void sessionDestroyed(HttpSessionEvent se) { - destroyed = true; + _destroys.add(se.getSession().getId()); } @Override public void sessionCreated(HttpSessionEvent se) { - created = true; + _creates.add(se.getSession().getId()); } } @@ -183,7 +189,10 @@ public abstract class AbstractLastAccessTimeTest public static class TestServlet extends HttpServlet { - + /** + * + */ + private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException @@ -212,14 +221,14 @@ public abstract class AbstractLastAccessTimeTest private void sendResult(HttpSession session, PrintWriter writer) { - if (session != null) - { - writer.print(session.getAttribute("test")); - } - else - { - writer.print("null"); - } + if (session != null) + { + writer.print(session.getAttribute("test")); + } + else + { + writer.print("null"); + } } } }