From 8dfcfd021c8c9ac426701f52b3fa7972e84ab5ba Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Fri, 20 May 2016 15:46:38 +1000 Subject: [PATCH] Refactor session tests to common base; add option to save session when created. --- .../InfinispanSessionDataStore.java | 7 +- .../server/session/AbstractSessionCache.java | 49 ++++- .../server/session/FileSessionDataStore.java | 1 + .../jetty/server/session/SessionCache.java | 3 + .../jetty/server/session/SessionHandler.java | 2 +- .../ClientCrossContextSessionTest.java | 8 +- .../jetty/server/session/FileTestServer.java | 5 +- .../server/session/ForwardedSessionTest.java | 7 +- .../server/session/ImmediateSaveTest.java | 58 ++++++ .../server/session/ScatterGunLoadTest.java | 8 +- .../ServerCrossContextSessionTest.java | 8 +- .../ClientCrossContextSessionTest.java | 7 +- .../gcloud/session/ForwardedSessionTest.java | 13 +- .../session/GCloudSessionTestSupport.java | 2 +- .../gcloud/session/GCloudTestServer.java | 17 +- .../gcloud/session/ImmediateSaveTest.java | 76 +++++++ .../session/InvalidationSessionTest.java | 37 +--- .../ServerCrossContextSessionTest.java | 8 +- .../gcloud/session/SessionMigrationTest.java | 13 +- ...StopSessionManagerPreserveSessionTest.java | 15 +- .../ClientCrossContextSessionTest.java | 13 +- .../jetty/server/session/HashTestServer.java | 8 - .../server/session/ScatterGunLoadTest.java | 6 +- .../ServerCrossContextSessionTest.java | 6 +- .../ClientCrossContextSessionTest.java | 6 +- .../server/session/ForwardedSessionTest.java | 6 +- .../server/session/ImmediateSaveTest.java | 64 ++++++ .../session/InfinispanTestSessionServer.java | 6 - .../server/session/SessionMigrationTest.java | 8 +- .../RemoteClientCrossContextSessionTest.java | 6 +- .../remote/RemoteForwardedSessionTest.java | 5 +- .../remote/RemoteImmediateSaveTest.java | 66 ++++++ .../remote/RemoteInvalidationSessionTest.java | 31 +-- .../remote/RemoteSessionMigrationTest.java | 13 +- .../ClientCrossContextSessionTest.java | 6 +- .../server/session/ForwardedSessionTest.java | 7 +- .../server/session/ImmediateSaveTest.java | 55 +++++ .../session/InvalidationSessionTest.java | 16 -- .../jetty/server/session/JdbcTestServer.java | 7 +- .../ReloadedSessionMissingClassTest.java | 3 +- .../ServerCrossContextSessionTest.java | 6 +- .../server/session/SessionMigrationTest.java | 6 +- ...StopSessionManagerPreserveSessionTest.java | 9 +- .../session/WebAppObjectInSessionTest.java | 7 +- .../ClientCrossContextSessionTest.java | 7 +- .../nosql/mongodb/ForwardedSessionTest.java | 9 +- .../nosql/mongodb/ImmediateSaveTest.java | 67 ++++++ .../nosql/mongodb/InvalidateSessionTest.java | 20 -- .../jetty/nosql/mongodb/MongoTestServer.java | 19 +- .../nosql/mongodb/ScatterGunLoadTest.java | 5 +- .../ServerCrossContextSessionTest.java | 8 +- .../nosql/mongodb/SessionMigrationTest.java | 5 +- ...AbstractClientCrossContextSessionTest.java | 6 +- .../AbstractCreateAndInvalidateTest.java | 10 +- .../session/AbstractForwardedSessionTest.java | 7 +- .../session/AbstractIdleSessionTest.java | 12 +- .../session/AbstractImmediateSaveTest.java | 194 ++++++++++++++++++ .../session/AbstractImmortalSessionTest.java | 3 +- .../AbstractInvalidationSessionTest.java | 21 +- .../session/AbstractLastAccessTimeTest.java | 6 +- .../AbstractLocalSessionScavengingTest.java | 3 +- .../session/AbstractNewSessionTest.java | 31 ++- .../session/AbstractOrphanedSessionTest.java | 4 +- .../AbstractProxySerializationTest.java | 6 +- .../AbstractReentrantRequestSessionTest.java | 4 +- .../session/AbstractRemoveSessionTest.java | 3 +- .../session/AbstractSameNodeLoadTest.java | 4 +- .../session/AbstractScatterGunLoadTest.java | 7 +- ...AbstractServerCrossContextSessionTest.java | 6 +- .../session/AbstractSessionCookieTest.java | 3 +- .../session/AbstractSessionExpiryTest.java | 3 +- ...bstractSessionInvalidateAndCreateTest.java | 4 +- .../session/AbstractSessionMigrationTest.java | 8 +- .../session/AbstractSessionRenewTest.java | 3 +- .../AbstractSessionValueSavingTest.java | 3 +- ...StopSessionManagerPreserveSessionTest.java | 11 +- .../server/session/AbstractTestBase.java | 30 +++ .../server/session/AbstractTestServer.java | 6 - .../AbstractWebAppObjectInSessionTest.java | 9 +- 79 files changed, 867 insertions(+), 390 deletions(-) create mode 100644 tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java create mode 100644 tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmediateSaveTest.java create mode 100644 tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java create mode 100644 tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmediateSaveTest.java create mode 100644 tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java create mode 100644 tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ImmediateSaveTest.java create mode 100644 tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmediateSaveTest.java create mode 100644 tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestBase.java 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 66059bc8c7d..560a38cf08a 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 @@ -201,6 +201,8 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception { + try + { //Put an idle timeout on the cache entry if the session is not immortal - //if no requests arrive at any node before this timeout occurs, or no node //scavenges the session before this timeout occurs, the session will be removed. @@ -212,7 +214,10 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore if (LOG.isDebugEnabled()) LOG.debug("Session {} saved to infinispan, expires {} ", id, data.getExpiry()); - + } catch (Exception e) + { + e.printStackTrace(); + } } 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 dc29116ef64..b97534e8664 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 @@ -76,6 +76,11 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements */ protected int _evictionPolicy = SessionCache.NEVER_EVICT; + /** + * If true, as soon as a new session is created, it will be persisted to the SessionDataStore + */ + protected boolean _saveOnCreate = false; + /** * If true, a session that will be evicted from the cache because it has been @@ -262,6 +267,20 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements } + @Override + public boolean isSaveOnCreate() + { + return _saveOnCreate; + } + + + @Override + public void setSaveOnCreate(boolean saveOnCreate) + { + _saveOnCreate = saveOnCreate; + } + + /** * Get a session object. * @@ -402,7 +421,8 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements if (data == null) //session doesn't exist return null; - + + data.setLastNode(_context.getWorkerName());//we are going to manage the node session = newSession(data); return session; } @@ -537,6 +557,19 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements //not there, so find out if session data exists for it return _sessionDataStore.exists (id); } + + /** + * Check to see if this cache contains an entry for the session + * corresponding to the session id. + * + * @see org.eclipse.jetty.server.session.SessionCache#contains(java.lang.String) + */ + @Override + public boolean contains (String id) throws Exception + { + //just ask our object cache, not the store + return (doGet(id) != null); + } /** @@ -700,8 +733,8 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements { return _saveOnInactiveEviction; } - - + + /** * @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long) */ @@ -710,6 +743,16 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements { if (LOG.isDebugEnabled()) LOG.debug("Creating new session id="+id); Session session = newSession(request, _sessionDataStore.newSessionData(id, time, time, time, maxInactiveMs)); + session.getSessionData().setLastNode(_context.getWorkerName()); + try + { + if (isSaveOnCreate() && _sessionDataStore != null) + _sessionDataStore.store(id, session.getSessionData()); + } + catch (Exception e) + { + LOG.warn("Save of new session {} failed", id, e); + } return session; } } 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 38c0c003f56..5a5bb6219f5 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 @@ -242,6 +242,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore } catch (Exception e) { + e.printStackTrace(); if (file != null) file.delete(); // No point keeping the file if we didn't save the whole session throw new UnwriteableSessionDataException(id, _context,e); 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 0271f2fea13..b96f49bfd6f 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 @@ -66,6 +66,7 @@ public interface SessionCache extends LifeCycle Session renewSessionId (String oldId, String newId) throws Exception; Session get(String id) throws Exception; void put(String id, Session session) throws Exception; + boolean contains (String id) throws Exception; boolean exists (String id) throws Exception; Session delete (String id) throws Exception; void shutdown (); @@ -77,4 +78,6 @@ public interface SessionCache extends LifeCycle int getEvictionPolicy (); void setSaveOnInactiveEviction (boolean saveOnEvict); boolean isSaveOnInactiveEviction (); + void setSaveOnCreate(boolean saveOnCreate); + boolean isSaveOnCreate(); } 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 6d6fe4fb2f8..869797aae3a 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 @@ -954,7 +954,7 @@ public class SessionHandler extends ScopedHandler } session.setExtendedId(_sessionIdManager.getExtendedId(id, null)); - session.getSessionData().setLastNode(_sessionIdManager.getWorkerName()); //TODO write through the change of node? + //session.getSessionData().setLastNode(_sessionIdManager.getWorkerName()); //TODO write through the change of node? } return session; } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java index d01e5c61698..3e48304032d 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java @@ -40,11 +40,15 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes FileTestServer.teardown(); } - public AbstractTestServer createServer(int port) + + @Override + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) { - return new FileTestServer(port); + return new FileTestServer(port,max,scavenge, evictionPolicy); } + + @Test public void testCrossContextDispatch() throws Exception { 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 d3b80b81779..a64dde27dda 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 @@ -120,10 +120,7 @@ public class FileTestServer extends AbstractTestServer } - public FileTestServer(int port) - { - super(port, 30, 10,2); - } + public FileTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod) { diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java index 17f298aba59..2843c7b4296 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java @@ -42,11 +42,12 @@ public class ForwardedSessionTest extends AbstractForwardedSessionTest { FileTestServer.teardown(); } - + + @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) { - return new FileTestServer(port); + return new FileTestServer(port,max,scavenge, evictionPolicy); } diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java new file mode 100644 index 00000000000..d7db65d3e63 --- /dev/null +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java @@ -0,0 +1,58 @@ +// +// ======================================================================== +// 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 org.junit.After; +import org.junit.Before; + + + +/** + * ImmediateSaveTest + * + * + */ +public class ImmediateSaveTest extends AbstractImmediateSaveTest +{ + @Before + public void before() throws Exception + { + FileTestServer.setup(); + } + + @After + public void after() + { + FileTestServer.teardown(); + } + + + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { return new FileTestServer(port, max, scavenge, evictionPolicy) + { + public SessionHandler newSessionHandler() + { + SessionHandler h = super.newSessionHandler(); + h.getSessionCache().setSaveOnCreate(true); + return h; + } + }; + } + +} diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java index a03a5fd63c4..be1aa346c71 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java @@ -41,11 +41,15 @@ public class ScatterGunLoadTest extends AbstractScatterGunLoadTest FileTestServer.teardown(); } - public AbstractTestServer createServer(int port) + + @Override + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) { - return new FileTestServer(port); + return new FileTestServer(port,max,scavenge, evictionPolicy); } + + @Test public void testLightLoad() throws Exception { diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java index 6118e1ed94c..6afeda77f84 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java @@ -38,11 +38,15 @@ public class ServerCrossContextSessionTest extends AbstractServerCrossContextSes FileTestServer.teardown(); } - public AbstractTestServer createServer(int port) + + @Override + public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy) { - return new FileTestServer(port); + return new FileTestServer(port,max,scavenge, evictionPolicy); } + + @Test public void testCrossContextDispatch() throws Exception { diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java index b69aeb067a6..d8e8a063b34 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java @@ -47,13 +47,10 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes _testSupport.tearDown(); } - /** - * @see org.eclipse.jetty.server.session.AbstractClientCrossContextSessionTest#createServer(int) - */ @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy) { - return new GCloudTestServer(port, _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/ForwardedSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java index fae7a6ab515..0003e274464 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java @@ -46,13 +46,10 @@ public class ForwardedSessionTest extends AbstractForwardedSessionTest _testSupport.tearDown(); } - /** - * @see org.eclipse.jetty.server.session.AbstractForwardedSessionTest#createServer(int) - */ - @Override - public AbstractTestServer createServer(int port) - { - return new GCloudTestServer(port, _testSupport.getConfiguration()); - } + @Override + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy) + { + return new GCloudTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy, _testSupport.getConfiguration()); + } } 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 0d3ba6463fb..cb66b374b80 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 @@ -345,7 +345,7 @@ public class GCloudSessionTestSupport int actual = 0; while (results.hasNext()) { - results.next(); + ProjectionEntity e = results.next(); ++actual; } assertEquals(count, actual); 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 05d425941fb..8c77f5fe6d8 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 @@ -30,11 +30,6 @@ import org.eclipse.jetty.server.session.SessionHandler; */ public class GCloudTestServer extends AbstractTestServer { - static protected int __maxInactivePeriod = 30; - static protected int __scavengePeriod = 10; - static protected int __idlePeriod = 2; - - /** * @param port @@ -42,19 +37,11 @@ public class GCloudTestServer extends AbstractTestServer * @param scavengePeriod * @param sessionIdMgrConfig */ - public GCloudTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod, GCloudConfiguration config) + public GCloudTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy, GCloudConfiguration config) { - super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod, config); + super(port, maxInactivePeriod, scavengePeriod, evictionPolicy, config); } - /** - * @param port - * @param configuration - */ - public GCloudTestServer(int port, GCloudConfiguration configuration) - { - super(port, 30,10, __idlePeriod, configuration); - } /** diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmediateSaveTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmediateSaveTest.java new file mode 100644 index 00000000000..aeebd070fda --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmediateSaveTest.java @@ -0,0 +1,76 @@ +// +// ======================================================================== +// 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.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractImmediateSaveTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.eclipse.jetty.server.session.SessionHandler; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + + + +/** + * ImmediateSaveTest + * + * + */ +public class ImmediateSaveTest extends AbstractImmediateSaveTest +{ + + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + _testSupport = new GCloudSessionTestSupport(); + _testSupport.setUp(); + } + + + @After + public void deleteSessions () throws Exception + { + _testSupport.deleteSessions(); + } + + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { + return new GCloudTestServer(port, max, scavenge, evictionPolicy,_testSupport.getConfiguration()) + { + public SessionHandler newSessionHandler() + { + SessionHandler h = super.newSessionHandler(); + h.getSessionCache().setSaveOnCreate(true); + return h; + } + }; + } +} 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 aca06bbdef1..24bde761387 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 EVICT_SEC = 3; + @BeforeClass public static void setup () throws Exception @@ -65,7 +65,7 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest public SessionHandler newSessionHandler() { SessionHandler handler = super.newSessionHandler(); - handler.getSessionCache().setEvictionPolicy(EVICT_SEC); + handler.getSessionCache().setEvictionPolicy(evictionPolicy); return handler; } @@ -73,37 +73,4 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest return server; } - /** - * @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#pause() - */ - @Override - public void pause() - { - //This test moves around a session between 2 nodes. After it is invalidated on the 1st node, - //it will still be in the memory of the 2nd node. We need to wait until after the stale time - //has expired on node2 for it to reload the session and discover it has been deleted. - try - { - Thread.currentThread().sleep((2*EVICT_SEC)*1000); - } - catch (Exception e) - { - e.printStackTrace(); - } - - } - - /** - * @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#testInvalidation() - */ - @Ignore - @Override - public void testInvalidation() throws Exception - { - // Ignore - //super.testInvalidation(); - } - - - } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java index 91e25be2e59..87178be93be 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java @@ -47,13 +47,11 @@ public class ServerCrossContextSessionTest extends AbstractServerCrossContextSes { _testSupport.tearDown(); } - /** - * @see org.eclipse.jetty.server.session.AbstractServerCrossContextSessionTest#createServer(int) - */ + @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy) { - return new GCloudTestServer(port, _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/SessionMigrationTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java index 4836f3ab4c0..283904f653d 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java @@ -47,15 +47,12 @@ public class SessionMigrationTest extends AbstractSessionMigrationTest _testSupport.tearDown(); } - /** - * @see org.eclipse.jetty.server.session.AbstractSessionMigrationTest#createServer(int) - */ - @Override - public AbstractTestServer createServer(int port) - { - return new GCloudTestServer(port, _testSupport.getConfiguration()); - } + @Override + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy) + { + return new GCloudTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy, _testSupport.getConfiguration()); + } @Test @Override diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java index 41c57ff81f2..ad8746cb24b 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java @@ -53,7 +53,7 @@ public class StopSessionManagerPreserveSessionTest extends AbstractStopSessionMa * @see org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest#checkSessionPersisted(boolean) */ @Override - public void checkSessionPersisted(boolean expected) + public void checkSessionPersisted(String id, boolean expected) { try { @@ -66,15 +66,12 @@ public class StopSessionManagerPreserveSessionTest extends AbstractStopSessionMa } - /** - * @see org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest#createServer(int) - */ - @Override - public AbstractTestServer createServer(int port) - { - return new GCloudTestServer(port, _testSupport.getConfiguration()); - } + @Override + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy) + { + return new GCloudTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy, _testSupport.getConfiguration()); + } /** * @see org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest#configureSessionManagement(org.eclipse.jetty.servlet.ServletContextHandler) */ diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java index 10700a100e6..870802570b1 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java @@ -35,13 +35,10 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes super.testCrossContextDispatch(); } - /** - * @see org.eclipse.jetty.server.session.AbstractClientCrossContextSessionTest#createServer(int) - */ - @Override - public AbstractTestServer createServer(int port) - { - return new HashTestServer(port); - } + @Override + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { + return new HashTestServer(port,max,scavenge,evictionPolicy); + } } 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 2a47fd4576c..9257d382d68 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 @@ -18,20 +18,12 @@ package org.eclipse.jetty.server.session; -import org.eclipse.jetty.server.SessionIdManager; - - /** * @version $Revision$ $Date$ */ public class HashTestServer extends AbstractTestServer { - static int __workers=0; - public HashTestServer(int port) - { - super(port, 30, 10, 2); - } public HashTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy) { diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java index 05d18a2500f..2b073d8c0ca 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ScatterGunLoadTest.java @@ -26,11 +26,11 @@ import org.junit.Test; public class ScatterGunLoadTest extends AbstractScatterGunLoadTest { - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port); + return new HashTestServer(port,max,scavenge,evictionPolicy); } - @Test public void testLightLoad() throws Exception { diff --git a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java index 559f7387f0e..b5fa1f85079 100644 --- a/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-hash-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java @@ -22,11 +22,11 @@ import org.junit.Test; public class ServerCrossContextSessionTest extends AbstractServerCrossContextSessionTest { - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) { - return new HashTestServer(port); + return new HashTestServer(port,max,scavenge,evictionPolicy); } - @Test public void testCrossContextDispatch() throws Exception { diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java index ac1034a47ea..439de537865 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java @@ -44,11 +44,11 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes } + @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, __testSupport.getCache()); - return server; + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); } @Test diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java index 377acad3096..d5aa449b4f5 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java @@ -49,11 +49,11 @@ public class ForwardedSessionTest extends AbstractForwardedSessionTest } + @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, __testSupport.getCache()); - return server; + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); } @Test diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java new file mode 100644 index 00000000000..94a4e9c20d7 --- /dev/null +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java @@ -0,0 +1,64 @@ +// +// ======================================================================== +// 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 org.junit.AfterClass; +import org.junit.BeforeClass; + + + +/** + * RemoteImmediateSaveTest + * + * + */ +public class ImmediateSaveTest extends AbstractImmediateSaveTest +{ + InfinispanTestSessionServer _server; + public static InfinispanTestSupport __testSupport; + + @BeforeClass + public static void setup () throws Exception + { + __testSupport = new InfinispanTestSupport(); + __testSupport.setup(); + } + + @AfterClass + public static void teardown () throws Exception + { + __testSupport.teardown(); + } + + + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { + _server = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()) + { + public SessionHandler newSessionHandler() + { + SessionHandler h = super.newSessionHandler(); + h.getSessionCache().setSaveOnCreate(true); + return h; + } + }; + return _server; + } + +} 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 5177a85814c..5f615d1072c 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 @@ -29,12 +29,6 @@ import org.infinispan.commons.util.CloseableIteratorSet; public class InfinispanTestSessionServer extends AbstractTestServer { - - public InfinispanTestSessionServer(int port, BasicCache config) - { - this(port, 30, 10, 2, config); - } - public InfinispanTestSessionServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy, BasicCache config) diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java index 856d86b92d3..365e5e26221 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java @@ -46,13 +46,11 @@ public class SessionMigrationTest extends AbstractSessionMigrationTest __testSupport.teardown(); } - /** - * @see org.eclipse.jetty.server.session.AbstractSessionMigrationTest#createServer(int) - */ + @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - return new InfinispanTestSessionServer(port, __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/RemoteClientCrossContextSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteClientCrossContextSessionTest.java index 1b6fd11899c..18cb070cbce 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteClientCrossContextSessionTest.java @@ -53,11 +53,11 @@ public class RemoteClientCrossContextSessionTest extends AbstractClientCrossCont } + @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, __testSupport.getCache()); - return server; + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); } @Test diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteForwardedSessionTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteForwardedSessionTest.java index 44dd561fabf..19b89769afd 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteForwardedSessionTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteForwardedSessionTest.java @@ -53,10 +53,9 @@ public class RemoteForwardedSessionTest extends AbstractForwardedSessionTest @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) { - InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, __testSupport.getCache()); - return server; + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); } @Test diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmediateSaveTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmediateSaveTest.java new file mode 100644 index 00000000000..5c5db7d3829 --- /dev/null +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteImmediateSaveTest.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.remote; + +import org.eclipse.jetty.server.session.AbstractImmediateSaveTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.eclipse.jetty.server.session.InfinispanTestSessionServer; +import org.eclipse.jetty.server.session.SessionHandler; +import org.junit.AfterClass; +import org.junit.BeforeClass; + + + +/** + * RemoteImmediateSaveTest + * + * + */ +public class RemoteImmediateSaveTest extends AbstractImmediateSaveTest +{ + public static RemoteInfinispanTestSupport __testSupport; + + + @BeforeClass + public static void setup () throws Exception + { + __testSupport = new RemoteInfinispanTestSupport("remote-session-test"); + __testSupport.setup(); + } + + @AfterClass + public static void teardown () throws Exception + { + __testSupport.teardown(); + } + + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { + return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache()) + { + public SessionHandler newSessionHandler() + { + SessionHandler h = super.newSessionHandler(); + h.getSessionCache().setSaveOnCreate(true); + return h; + } + }; + } + +} 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 5f7b2aa62d4..78aebd70858 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 @@ -35,7 +35,7 @@ public class RemoteInvalidationSessionTest extends AbstractInvalidationSessionTe { public static RemoteInfinispanTestSupport __testSupport; - public static final int IDLE_PASSIVATE_SEC = 3; + @@ -61,35 +61,6 @@ public class RemoteInvalidationSessionTest extends AbstractInvalidationSessionTe return new InfinispanTestSessionServer(port, maxInterval, scavengeInterval, evictionPolicy, __testSupport.getCache()); } - - - @Ignore - @Override - public void testInvalidation() throws Exception - { - //Ignore - //super.testInvalidation(); - } - /** - * @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#pause() - */ - @Override - public void pause() - { - //This test moves a session from node 1 to node 2, then invalidates the session back on node1. This - //should never happen with a decent load balancer. - //The infinispan session manager on node 2 will hold the session in local memory for a specific (configurable) - //amount of time. We've set the stale session time to 3 sec, so we need to pause for at least this long before making - //another request to node2 so - //that the node will re-load the session from the database and discover that it has gone. - try - { - Thread.sleep(2 * IDLE_PASSIVATE_SEC * 1000); - } - catch (InterruptedException e) - { - } - } } diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionMigrationTest.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionMigrationTest.java index 31ad12a121b..8a2b4264e26 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionMigrationTest.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/remote/RemoteSessionMigrationTest.java @@ -49,15 +49,12 @@ public class RemoteSessionMigrationTest extends AbstractSessionMigrationTest __testSupport.teardown(); } - /** - * @see org.eclipse.jetty.server.session.AbstractSessionMigrationTest#createServer(int) - */ - @Override - public AbstractTestServer createServer(int port) - { - return new InfinispanTestSessionServer(port, __testSupport.getCache()); - } + @Override + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy) + { + return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache()); + } @Override public void testSessionMigration() throws Exception { diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java index 24b79b32de3..52cb5765676 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ClientCrossContextSessionTest.java @@ -29,9 +29,11 @@ import org.junit.Test; public class ClientCrossContextSessionTest extends AbstractClientCrossContextSessionTest { - public AbstractTestServer createServer(int port) + + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new JdbcTestServer(port); + return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java index 7e562d2a2b7..a7b908585ff 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ForwardedSessionTest.java @@ -30,13 +30,10 @@ import org.junit.Test; public class ForwardedSessionTest extends AbstractForwardedSessionTest { - /** - * @see org.eclipse.jetty.server.session.AbstractForwardedSessionTest#createServer(int) - */ @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new JdbcTestServer(port); + return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } @Test diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java new file mode 100644 index 00000000000..e27c6785e26 --- /dev/null +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ImmediateSaveTest.java @@ -0,0 +1,55 @@ +// +// ======================================================================== +// 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 org.junit.After; +import org.junit.AfterClass; + + + +/** + * ImmediateSaveTest + * + * + */ +public class ImmediateSaveTest extends AbstractImmediateSaveTest +{ + JdbcTestServer _server; + + @AfterClass + public static void tearDown() throws Exception + { + JdbcTestServer.shutdown(null); + } + + + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { + _server = new JdbcTestServer(port, max, scavenge, evictionPolicy) + { + public SessionHandler newSessionHandler() + { + SessionHandler h = super.newSessionHandler(); + h.getSessionCache().setSaveOnCreate(true); + return h; + } + }; + return _server; + } +} 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 3754819dc06..e6ad87d6398 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 @@ -27,28 +27,12 @@ import org.junit.Test; */ public class InvalidationSessionTest extends AbstractInvalidationSessionTest { - public static final int IDLE_PASSIVATE_SEC = 3; public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } - public void pause() - { - //This test moves around a session between 2 nodes. Due to optimizations in the handling of - //the sessions for the JDBC SessionManager, this can mean that a session that may have been - //deleted on one node is then accessed again shortly afterwards, it can appear as if the - //session is still live in the memory of that node. By waiting a little time, we can ensure - //that the node will re-load the session from the database and discover that it has gone. - try - { - Thread.sleep(2 * IDLE_PASSIVATE_SEC * 1000); - } - catch (InterruptedException e) - { - } - } @Test public void testInvalidation() throws Exception 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 b839d3d2a9d..46b6ba962fe 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 @@ -78,12 +78,7 @@ public class JdbcTestServer extends AbstractTestServer } } - - public JdbcTestServer(int port) - { - super(port); - } - + public JdbcTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod, String connectionUrl) { super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod, connectionUrl); 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 d6dea649102..76ba2a5628e 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 @@ -89,7 +89,8 @@ public class ReloadedSessionMissingClassTest URLClassLoader loaderWithoutFoo = new URLClassLoader(barUrls, Thread.currentThread().getContextClassLoader()); - AbstractTestServer server1 = new JdbcTestServer(0); + AbstractTestServer server1 = new JdbcTestServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); + WebAppContext webApp = server1.addWebAppContext(unpackedWarDir.getCanonicalPath(), contextPath); webApp.setClassLoader(loaderWithFoo); webApp.addServlet("Bar", "/bar"); diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java index b650278f2ce..ed8787a62f5 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ServerCrossContextSessionTest.java @@ -27,11 +27,11 @@ import org.junit.Test; public class ServerCrossContextSessionTest extends AbstractServerCrossContextSessionTest { - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new JdbcTestServer(port); + return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } - @Test public void testCrossContextDispatch() throws Exception { diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java index d8197b2edd3..d07155c2b55 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/SessionMigrationTest.java @@ -27,11 +27,11 @@ import org.junit.Test; public class SessionMigrationTest extends AbstractSessionMigrationTest { - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new JdbcTestServer(port); + return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } - @Test public void testSessionMigration() throws Exception { diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/StopSessionManagerPreserveSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/StopSessionManagerPreserveSessionTest.java index f320209757c..28c5bc04230 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/StopSessionManagerPreserveSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/StopSessionManagerPreserveSessionTest.java @@ -37,23 +37,24 @@ public class StopSessionManagerPreserveSessionTest extends AbstractStopSessionMa } @Override - public void checkSessionPersisted(boolean expected) + public void checkSessionPersisted(String id, boolean expected) { try { - boolean actual = _server.existsInSessionTable(_id, true); + boolean actual = _server.existsInSessionTable(id, true); assertEquals(expected, actual); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } } @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - _server = new JdbcTestServer(0); + _server = new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); return _server; } diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java index 2deec032692..7025e44ee24 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java @@ -29,13 +29,12 @@ import org.junit.Test; */ public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest { - - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { Resource.setDefaultUseCaches(false); - return new JdbcTestServer(port); + return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } - @Test public void testWebappObjectInSession() 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 4a5fc2ebe7e..28ece5e6293 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 @@ -40,11 +40,14 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes MongoTestServer.dropCollection(); } - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new MongoTestServer(port); + return new MongoTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } + + @Test public void testCrossContextDispatch() throws Exception { 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 cf342246bd5..26691b79e99 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 @@ -47,15 +47,12 @@ public class ForwardedSessionTest extends AbstractForwardedSessionTest } - /** - * @see org.eclipse.jetty.server.session.AbstractForwardedSessionTest#createServer(int) - */ @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new MongoTestServer(port); + return new MongoTestServer(port,maxInactive, scavengeInterval, evictionPolicy); } - + @Test public void testSessionCreateInForward() throws Exception { diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ImmediateSaveTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ImmediateSaveTest.java new file mode 100644 index 00000000000..ca28fc1acb2 --- /dev/null +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/ImmediateSaveTest.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.nosql.mongodb; + +import static org.junit.Assert.assertNotNull; + +import org.eclipse.jetty.server.session.AbstractImmediateSaveTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.eclipse.jetty.server.session.SessionHandler; +import org.junit.After; +import org.junit.Before; + +import com.mongodb.BasicDBObject; +import com.mongodb.DBObject; + +/** + * ImmediateSaveTest + * + * + */ +public class ImmediateSaveTest extends AbstractImmediateSaveTest +{ + + @Before + public void beforeTest() throws Exception + { + MongoTestServer.dropCollection(); + MongoTestServer.createCollection(); + } + + @After + public void afterTest() throws Exception + { + MongoTestServer.dropCollection(); + } + + + + public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy) + { + return new MongoTestServer(port, max, scavenge, evictionPolicy) + { + public SessionHandler newSessionHandler() + { + SessionHandler h = super.newSessionHandler(); + h.getSessionCache().setSaveOnCreate(true); + return h; + } + }; + } +} 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 9c692401480..53b96c29f72 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 @@ -27,7 +27,6 @@ import org.junit.Test; public class InvalidateSessionTest extends AbstractInvalidationSessionTest { - public final static int IDLE_PASSIVATE_SEC = 1; @BeforeClass public static void beforeClass() throws Exception @@ -47,23 +46,4 @@ public class InvalidateSessionTest extends AbstractInvalidationSessionTest { return new MongoTestServer(port, maxInterval, scavengeInterval, evictionPolicy); } - - @Override - public void pause() - { - try - { - Thread.sleep(2 * IDLE_PASSIVATE_SEC * 1000); - } - catch (InterruptedException e) - { - } - } - - @Test - public void testInvalidation() throws Exception - { - super.testInvalidation(); - } - } 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 b1eeba21f8f..f12a801115e 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 @@ -57,21 +57,12 @@ public class MongoTestServer extends AbstractTestServer } - public MongoTestServer(int port) - { - super(port); - } - - - public MongoTestServer(int port, int idlePassivatePeriod) - { - super(port, 30, 10, idlePassivatePeriod); - } - - public MongoTestServer(int port, int maxInactivePeriod, int scavengePeriod,int idlePassivatePeriod) + public MongoTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod) { super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod); } + + public MongoTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod, boolean saveAllAttributes) @@ -105,7 +96,7 @@ public class MongoTestServer extends AbstractTestServer public static void main(String... args) throws Exception { - MongoTestServer server8080 = new MongoTestServer(8080); +/* MongoTestServer server8080 = new MongoTestServer(8080); server8080.addContext("/").addServlet(SessionDump.class,"/"); server8080.start(); @@ -114,7 +105,7 @@ public class MongoTestServer extends AbstractTestServer server8081.start(); server8080.join(); - server8081.join(); + server8081.join();*/ } } 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 4389c2a2ac2..cc44df46884 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 @@ -44,9 +44,10 @@ public class ScatterGunLoadTest extends AbstractScatterGunLoadTest } - public AbstractTestServer createServer(int port) + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new MongoTestServer(port); + return new MongoTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } @Test 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 12a336bc529..e85b7ab2388 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 @@ -41,12 +41,14 @@ public class ServerCrossContextSessionTest extends AbstractServerCrossContextSes MongoTestServer.dropCollection(); } - - public AbstractTestServer createServer(int port) + + @Override + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new MongoTestServer(port); + return new MongoTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } + @Test public void testCrossContextDispatch() throws Exception { 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 a0ac5a68672..21d8c420ac1 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 @@ -42,11 +42,12 @@ public class SessionMigrationTest extends AbstractSessionMigrationTest } @Override - public AbstractTestServer createServer(int port) + public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy) { - return new MongoTestServer(port); + return new MongoTestServer(port, maxInactive, scavengeInterval, evictionPolicy); } + @Test public void testSessionMigration() throws Exception { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractClientCrossContextSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractClientCrossContextSessionTest.java index 0daaf73ae14..8c0b9b9f90d 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractClientCrossContextSessionTest.java @@ -40,10 +40,10 @@ import org.junit.Test; /** * AbstractClientCrossContextSessionTest */ -public abstract class AbstractClientCrossContextSessionTest +public abstract class AbstractClientCrossContextSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port); + @Test public void testCrossContextDispatch() throws Exception @@ -51,7 +51,7 @@ public abstract class AbstractClientCrossContextSessionTest String contextA = "/contextA"; String contextB = "/contextB"; String servletMapping = "/server"; - AbstractTestServer server = createServer(0); + AbstractTestServer server = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); TestServletA servletA = new TestServletA(); ServletHolder holderA = new ServletHolder(servletA); ServletContextHandler ctxA = server.addContext(contextA); 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 index 396c79f4fe3..2f2717b6e3c 100644 --- 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 @@ -56,18 +56,12 @@ import org.junit.Test; * Test that creating a session and invalidating it before the request exits the session * does not result in the session being persisted */ -public abstract class AbstractCreateAndInvalidateTest{ +public abstract class AbstractCreateAndInvalidateTest extends AbstractTestBase +{ protected TestServlet _servlet = new TestServlet(); protected AbstractTestServer _server1 = null; - - - - - public abstract AbstractTestServer createServer (int port, int max, int scavenge, int evictionPolicy); - - /** * @param sessionId diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractForwardedSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractForwardedSessionTest.java index da238eea628..306ae50f055 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractForwardedSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractForwardedSessionTest.java @@ -48,17 +48,14 @@ import org.junit.Test; * This test requires that the sessions will be persisted, as the server is stopped and * then restarted in order to check that all the attributes were saved. */ -public abstract class AbstractForwardedSessionTest +public abstract class AbstractForwardedSessionTest extends AbstractTestBase { - - public abstract AbstractTestServer createServer(int port); - @Test public void testSessionCreateInForward() throws Exception { - AbstractTestServer testServer = createServer(0); + AbstractTestServer testServer = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); ServletContextHandler testServletContextHandler = testServer.addContext("/context"); testServletContextHandler.addServlet(Servlet1.class, "/one"); testServletContextHandler.addServlet(Servlet2.class, "/two"); 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 33b928d1a50..06a4ad1771f 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 @@ -49,21 +49,11 @@ import org.junit.Test; * * */ -public abstract class AbstractIdleSessionTest +public abstract class AbstractIdleSessionTest extends AbstractTestBase { protected TestServlet _servlet = new TestServlet(); protected AbstractTestServer _server1 = null; - - - /** - * @param port - * @param max - * @param scavenge - * @param evictionPolicy - * @return - */ - public abstract AbstractTestServer createServer (int port, int max, int scavenge, int evictionPolicy); /** diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmediateSaveTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmediateSaveTest.java new file mode 100644 index 00000000000..994e01f0592 --- /dev/null +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractImmediateSaveTest.java @@ -0,0 +1,194 @@ +// +// ======================================================================== +// 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.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; + +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.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.Test; + + +/** + * AbstractImmediateSaveTest + * + * + */ +public abstract class AbstractImmediateSaveTest extends AbstractTestBase +{ + protected ServletContextHandler _context; + + + public void checkSessionSaved (String id) throws Exception + { + assertTrue(_context.getSessionHandler().getSessionCache().getSessionDataStore().exists(id)); + } + + + public void pause(int scavenge) + { + try + { + Thread.sleep(scavenge * 1000L); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + + @Test + public void testSaveNewSession() throws Exception + { + String servletMapping = "/server"; + int scavengePeriod = 3; + int maxInactivePeriod = -1; + AbstractTestServer server = createServer(0, maxInactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); + _context = server.addContext("/"); + ServletHolder h = new ServletHolder(); + h.setServlet(new TestServlet()); + _context.addServlet(h, servletMapping); + String contextPath = ""; + + try + { + server.start(); + int port=server.getPort(); + HttpClient client = new HttpClient(); + client.start(); + try + { + 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="); + } + finally + { + client.stop(); + } + } + finally + { + server.stop(); + } + } + + + + @Test + public void testSaveNewSessionWithEviction() throws Exception + { + String servletMapping = "/server"; + int scavengePeriod = 3; + int maxInactivePeriod = 1; + AbstractTestServer server = createServer(0, maxInactivePeriod, scavengePeriod, SessionCache.EVICT_ON_SESSION_EXIT); + _context = server.addContext("/"); + ServletHolder h = new ServletHolder(); + h.setServlet(new TestServlet()); + _context.addServlet(h, servletMapping); + String contextPath = ""; + + try + { + server.start(); + int port=server.getPort(); + HttpClient client = new HttpClient(); + client.start(); + try + { + //make request to make a save-on-create 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="); + + //session should now be evicted from the cache + assertFalse(_context.getSessionHandler().getSessionCache().contains(AbstractTestServer.extractSessionId(sessionCookie))); + + //make another request for the same session + Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=test"); + request.header("Cookie", sessionCookie); + response = request.send(); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + //session should now be evicted from the cache again + assertFalse(_context.getSessionHandler().getSessionCache().contains(AbstractTestServer.extractSessionId(sessionCookie))); + + } + finally + { + client.stop(); + } + } + finally + { + server.stop(); + } + + } + + public class TestServlet extends HttpServlet + { + String 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); + assertNotNull(session); + try + { + checkSessionSaved(session.getId()); + } + catch (Exception e) + { + fail(e.getMessage()); + } + } + else if ("test".equals(action)) + { + HttpSession session = request.getSession(false); + assertNotNull(session); + } + } + } +} 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 f8d27953bb8..85580812224 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 @@ -41,9 +41,8 @@ import org.junit.Test; /** * AbstractImmortalSessionTest */ -public abstract class AbstractImmortalSessionTest +public abstract class AbstractImmortalSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int evictionPolicy); @Test public void testImmortalSession() throws Exception 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 ce79cb56058..536a6467ae8 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 @@ -38,20 +38,25 @@ import org.junit.Test; /** * AbstractInvalidationSessionTest + * * Goal of the test is to be sure that invalidating a session on one node - * result in the session being unavailable in the other node also. + * result in the session being unavailable in the other node also. This + * simulates an environment without a sticky load balancer. In this case, + * you must use session eviction, to try to ensure that as the session + * bounces around it gets a fresh load of data from the SessionDataStore. */ -public abstract class AbstractInvalidationSessionTest +public abstract class AbstractInvalidationSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy); - public abstract void pause(); + @Test public void testInvalidation() throws Exception { String contextPath = ""; String servletMapping = "/server"; - AbstractTestServer server1 = createServer(0, 30, 1, 1); + int maxInactiveInterval = 30; + int scavengeInterval = 1; + AbstractTestServer server1 = createServer(0, maxInactiveInterval, scavengeInterval, SessionCache.EVICT_ON_SESSION_EXIT); server1.addContext(contextPath).addServlet(TestServlet.class, servletMapping); @@ -59,7 +64,7 @@ public abstract class AbstractInvalidationSessionTest { server1.start(); int port1 = server1.getPort(); - AbstractTestServer server2 = createServer(0, 30, 1, 1); + AbstractTestServer server2 = createServer(0, maxInactiveInterval, scavengeInterval, SessionCache.EVICT_ON_SESSION_EXIT); server2.addContext(contextPath).addServlet(TestServlet.class, servletMapping); try @@ -96,9 +101,7 @@ public abstract class AbstractInvalidationSessionTest Request request1 = client.newRequest(urls[0] + "?action=invalidate"); request1.header("Cookie", sessionCookie); response1 = request1.send(); - assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); - - pause(); + assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); // Be sure on node2 we don't see the session anymore request2 = client.newRequest(urls[1] + "?action=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 ff4174fd6a8..4cdf10ce5c7 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 @@ -51,13 +51,9 @@ import org.junit.Test; * scavenged by node A. In other words, it tests that a session that migrates from one node * to another is not timed out on the original node. */ -public abstract class AbstractLastAccessTimeTest +public abstract class AbstractLastAccessTimeTest extends AbstractTestBase { - - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod); - - @Test public void testLastAccessTime() throws Exception { 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 d4104b360ee..7920698b6a8 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 @@ -39,9 +39,8 @@ import org.junit.Test; /** * AbstractLocalSessionScavengingTest */ -public abstract class AbstractLocalSessionScavengingTest +public abstract class AbstractLocalSessionScavengingTest extends AbstractTestBase { - 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/AbstractNewSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractNewSessionTest.java index 7932d220141..3ca0e44b5be 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 @@ -20,7 +20,9 @@ package org.eclipse.jetty.server.session; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; - +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import javax.servlet.ServletException; @@ -38,18 +40,17 @@ import org.junit.Test; /** * AbstractNewSessionTest * - * Create a session, wait for it to be scanvenged, represent the cookie and check that a + * Create a session, wait for it to be scavenged, re-present the cookie and check that a * new session is created. */ -public abstract class AbstractNewSessionTest +public abstract class AbstractNewSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public void pause(int scavenge) { try { - Thread.sleep(scavenge * 2500L); + Thread.sleep(scavenge * 1000L); } catch (InterruptedException e) { @@ -62,7 +63,8 @@ public abstract class AbstractNewSessionTest { String servletMapping = "/server"; int scavengePeriod = 3; - AbstractTestServer server = createServer(0, 1, scavengePeriod, SessionCache.NEVER_EVICT); + int maxInactivePeriod = 1; + AbstractTestServer server = createServer(0, maxInactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT); ServletContextHandler context = server.addContext("/"); context.addServlet(TestServlet.class, servletMapping); String contextPath = ""; @@ -82,11 +84,11 @@ public abstract class AbstractNewSessionTest // Mangle the cookie, replacing Path with $Path, etc. sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); - // Let's wait for the scavenger to run, waiting 2.5 times the scavenger period - pause(scavengePeriod); + // Let's wait for the scavenger to run + pause(maxInactivePeriod + scavengePeriod); - // The session is not there anymore, but we present an old cookie - // The server creates a new session, we must ensure we released all locks + // The session should not be there anymore, but we present an old cookie + // The server should create a new session. Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=old-create"); request.header("Cookie", sessionCookie); response = request.send(); @@ -105,6 +107,8 @@ public abstract class AbstractNewSessionTest } public static class TestServlet extends HttpServlet { + String id; + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -113,10 +117,15 @@ public abstract class AbstractNewSessionTest { HttpSession session = request.getSession(true); assertTrue(session.isNew()); + id = session.getId(); } else if ("old-create".equals(action)) { - request.getSession(true); + HttpSession s = request.getSession(false); + assertNull(s); + s = request.getSession(true); + assertNotNull(s); + assertFalse(s.getId().equals(id)); } else { 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 558d883d5bb..751f4317524 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 @@ -38,11 +38,9 @@ import org.junit.Test; /** * AbstractOrphanedSessionTest */ -public abstract class AbstractOrphanedSessionTest +public abstract class AbstractOrphanedSessionTest extends AbstractTestBase { - 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. * We want to test that the session data is gone after scavenging. 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 6a6657c8ae3..9979f0dbc7c 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 @@ -44,13 +44,11 @@ import org.junit.Test; * * */ -public abstract class AbstractProxySerializationTest +public abstract class AbstractProxySerializationTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public abstract void customizeContext (ServletContextHandler c); - - + /** * @param msec milliseconds to sleep 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 6249dc1e793..e3468d2ebd8 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 @@ -41,9 +41,9 @@ import org.junit.Test; * While a request is still active in a context, make another * request to it to ensure both share same session. */ -public abstract class AbstractReentrantRequestSessionTest +public abstract class AbstractReentrantRequestSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); + @Test public void testReentrantRequestSession() throws Exception 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 86231aac87c..daf3796737c 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 @@ -45,9 +45,8 @@ import org.junit.Test; * Test that invalidating a session does not return the session on the next request. * */ -public abstract class AbstractRemoveSessionTest +public abstract class AbstractRemoveSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod); @Test 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 c974f97a251..ec58ad6a740 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 @@ -48,12 +48,10 @@ import org.junit.Test; * This test performs multiple concurrent requests for the same session on the same node. * */ -public abstract class AbstractSameNodeLoadTest +public abstract class AbstractSameNodeLoadTest extends AbstractTestBase { protected boolean _stress = Boolean.getBoolean( "STRESS" ); - - 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/AbstractScatterGunLoadTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractScatterGunLoadTest.java index 27d832cf8f9..118934b045a 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractScatterGunLoadTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractScatterGunLoadTest.java @@ -50,11 +50,10 @@ import org.junit.Test; * In the real world, we must have a load balancer that uses sticky sessions * to keep the session pinned to a particular node. */ -public abstract class AbstractScatterGunLoadTest +public abstract class AbstractScatterGunLoadTest extends AbstractTestBase { protected boolean _stress = Boolean.getBoolean( "STRESS" ); - public abstract AbstractTestServer createServer(int port); @Test public void testLightLoad() @@ -64,14 +63,14 @@ public abstract class AbstractScatterGunLoadTest { String contextPath = ""; String servletMapping = "/server"; - AbstractTestServer server1 = createServer( 0 ); + AbstractTestServer server1 = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); server1.addContext( contextPath ).addServlet( TestServlet.class, servletMapping ); try { server1.start(); int port1 = server1.getPort(); - AbstractTestServer server2 = createServer( 0 ); + AbstractTestServer server2 = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); server2.addContext( contextPath ).addServlet( TestServlet.class, servletMapping ); try 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 95bb3d4c05d..e2dc8f36189 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 @@ -39,18 +39,16 @@ import org.junit.Test; /** * AbstractServerCrossContextSessionTest */ -public abstract class AbstractServerCrossContextSessionTest +public abstract class AbstractServerCrossContextSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port); - @Test public void testCrossContextDispatch() throws Exception { String contextA = "/contextA"; String contextB = "/contextB"; String servletMapping = "/server"; - AbstractTestServer server = createServer(0); + AbstractTestServer server = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); ServletContextHandler ctxA = server.addContext(contextA); ctxA.addServlet(TestServletA.class, servletMapping); ServletContextHandler ctxB = server.addContext(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 516dd20f6ef..078c7b43450 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 @@ -41,9 +41,8 @@ import junit.framework.Assert; /** * AbstractSessionCookieTest */ -public abstract class AbstractSessionCookieTest +public abstract class AbstractSessionCookieTest extends AbstractTestBase { - 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 278dd31f268..4b227e7aba9 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 @@ -46,9 +46,8 @@ import org.junit.Test; * * */ -public abstract class AbstractSessionExpiryTest +public abstract class AbstractSessionExpiryTest extends AbstractTestBase { - 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 52e12b27ac1..f36ecc32710 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 @@ -53,7 +53,7 @@ import org.junit.Test; * newly created session correctly (removed from the server and session listeners called). * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=377610 */ -public abstract class AbstractSessionInvalidateAndCreateTest +public abstract class AbstractSessionInvalidateAndCreateTest extends AbstractTestBase { public class MySessionListener implements HttpSessionListener { @@ -70,8 +70,6 @@ public abstract class AbstractSessionInvalidateAndCreateTest } } - 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/AbstractSessionMigrationTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionMigrationTest.java index 0d47aa3716c..f3d3d3b73f2 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionMigrationTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractSessionMigrationTest.java @@ -40,16 +40,16 @@ import org.junit.Test; * * Check that a session that is active on node 1 can be accessed on node2. */ -public abstract class AbstractSessionMigrationTest +public abstract class AbstractSessionMigrationTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port); + @Test public void testSessionMigration() throws Exception { String contextPath = ""; String servletMapping = "/server"; - AbstractTestServer server1 = createServer(0); + AbstractTestServer server1 = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); server1.addContext(contextPath).addServlet(TestServlet.class, servletMapping); try @@ -57,7 +57,7 @@ public abstract class AbstractSessionMigrationTest server1.start(); int port1=server1.getPort(); - AbstractTestServer server2 = createServer(0); + AbstractTestServer server2 = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); server2.addContext(contextPath).addServlet(TestServlet.class, servletMapping); try 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 ac1bd699481..78368ac9ea2 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 @@ -46,11 +46,10 @@ import org.eclipse.jetty.webapp.WebAppContext; * * Test that changes the session id during a request. */ -public abstract class AbstractSessionRenewTest +public abstract class AbstractSessionRenewTest extends AbstractTestBase { protected AbstractTestServer _server; - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); public abstract boolean verifyChange (WebAppContext context, String oldSessionId, String newSessionId); 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 2d40c500807..5232fdf98e4 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 @@ -39,9 +39,8 @@ import org.junit.Test; /** * AbstractSessionValueSavingTest */ -public abstract class AbstractSessionValueSavingTest +public abstract class AbstractSessionValueSavingTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy); @Test public void testSessionValueSaving() throws Exception diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractStopSessionManagerPreserveSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractStopSessionManagerPreserveSessionTest.java index 05002ccac69..dd06a2de388 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractStopSessionManagerPreserveSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractStopSessionManagerPreserveSessionTest.java @@ -40,15 +40,14 @@ import org.junit.Test; * * */ -public abstract class AbstractStopSessionManagerPreserveSessionTest +public abstract class AbstractStopSessionManagerPreserveSessionTest extends AbstractTestBase { public String _id; - public abstract void checkSessionPersisted (boolean expected); - - public abstract AbstractTestServer createServer (int port); + public abstract void checkSessionPersisted (String id, boolean expected); + public abstract void configureSessionManagement(ServletContextHandler context); @Test @@ -57,7 +56,7 @@ public abstract class AbstractStopSessionManagerPreserveSessionTest String contextPath = ""; String servletMapping = "/server"; - AbstractTestServer server = createServer(0); + AbstractTestServer server = createServer(0, -1, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); ServletContextHandler context = server.addContext(contextPath); ServletHolder holder = new ServletHolder(); TestServlet servlet = new TestServlet(); @@ -87,7 +86,7 @@ public abstract class AbstractStopSessionManagerPreserveSessionTest context.getSessionHandler().stop(); //check the database to see that the session is still valid - checkSessionPersisted(true); + checkSessionPersisted(_id, true); } finally diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestBase.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestBase.java new file mode 100644 index 00000000000..6b1f225b6da --- /dev/null +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractTestBase.java @@ -0,0 +1,30 @@ +// +// ======================================================================== +// 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; + +/** + * AbstractTestBase + * + * + */ +public abstract class AbstractTestBase +{ + public abstract AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy); +} 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 9d7b966fe0f..065f4daddd2 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 @@ -34,7 +34,6 @@ import org.eclipse.jetty.webapp.WebAppContext; public abstract class AbstractTestServer { public static int DEFAULT_MAX_INACTIVE = 30; - public static int DEFAULT_SCAVENGE_SEC = 10; public static int DEFAULT_EVICTIONPOLICY = SessionCache.NEVER_EVICT; @@ -68,11 +67,6 @@ public abstract class AbstractTestServer } - - public AbstractTestServer(int port) - { - this(port, DEFAULT_MAX_INACTIVE, DEFAULT_SCAVENGE_SEC, DEFAULT_EVICTIONPOLICY); - } public AbstractTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy) { diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractWebAppObjectInSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractWebAppObjectInSessionTest.java index d924953a470..b489ae6dd97 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractWebAppObjectInSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractWebAppObjectInSessionTest.java @@ -44,10 +44,9 @@ import org.junit.Test; * * This test is only appropriate for clustered session managers. */ -public abstract class AbstractWebAppObjectInSessionTest +public abstract class AbstractWebAppObjectInSessionTest extends AbstractTestBase { - public abstract AbstractTestServer createServer(int port); - + @Test public void testWebappObjectInSession() throws Exception { @@ -94,7 +93,7 @@ public abstract class AbstractWebAppObjectInSessionTest //copy(sourceFile, targetFile); IO.copy(resource.getInputStream(), new FileOutputStream(targetFile)); - AbstractTestServer server1 = createServer(0); + AbstractTestServer server1 = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); server1.addWebAppContext(warDir.getCanonicalPath(), contextPath).addServlet(WebAppObjectInSessionServlet.class.getName(), servletMapping); try @@ -102,7 +101,7 @@ public abstract class AbstractWebAppObjectInSessionTest server1.start(); int port1 = server1.getPort(); - AbstractTestServer server2 = createServer(0); + AbstractTestServer server2 = createServer(0, AbstractTestServer.DEFAULT_MAX_INACTIVE, AbstractTestServer.DEFAULT_SCAVENGE_SEC, AbstractTestServer.DEFAULT_EVICTIONPOLICY); server2.addWebAppContext(warDir.getCanonicalPath(), contextPath).addServlet(WebAppObjectInSessionServlet.class.getName(), servletMapping); try