diff --git a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionManager.java b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionManager.java index a5906d51d35..efc9c3af5f1 100644 --- a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionManager.java +++ b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionManager.java @@ -49,6 +49,7 @@ import com.google.gcloud.datastore.Blob; import com.google.gcloud.datastore.Datastore; import com.google.gcloud.datastore.DatastoreFactory; import com.google.gcloud.datastore.Entity; +import com.google.gcloud.datastore.GqlQuery; import com.google.gcloud.datastore.Key; import com.google.gcloud.datastore.KeyFactory; import com.google.gcloud.datastore.Query; @@ -97,7 +98,7 @@ public class GCloudSessionManager extends AbstractSessionManager private SessionEntityConverter _converter; - private int _maxResults; + private int _maxResults = DEFAULT_MAX_QUERY_RESULTS; /** @@ -702,7 +703,7 @@ public class GCloudSessionManager extends AbstractSessionManager else if (!_scheduler.isStarted()) throw new IllegalStateException("Shared scheduler not started"); - setScavengeInterval(getScavengeInterval()); + setScavengeIntervalSec(getScavengeIntervalSec()); super.doStart(); } @@ -724,56 +725,64 @@ public class GCloudSessionManager extends AbstractSessionManager if (_ownScheduler && _scheduler !=null) _scheduler.stop(); _scheduler = null; - + _sessions.clear(); _sessions = null; } - - - + + + /** * Look for sessions in local memory that have expired. */ public void scavenge () { - //scavenge in the database every so often - //TODO - - //always scavenge in memory - scavengeMemory(); - } - - - protected void scavengeMemory() - { - long now = System.currentTimeMillis(); - for (Session s:_sessions.values()) + try { - if (s.isExpiredAt(now)) - s.timeout(); + //scavenge in the database every so often + scavengeGCloudDataStore(); + } + catch (Exception e) + { + LOG.warn("Problem scavenging", e); } } + + protected void scavengeGCloudDataStore() throws Exception { + //query the datastore for sessions that have expired long now = System.currentTimeMillis(); - Query query = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+KIND+" where expiry < @1 LIMIT "+_maxResults) - .setBinding("1", now) - .build(); - + //give a bit of leeway so we don't immediately something that has only just expired a nanosecond ago + now = now - (_scavengeIntervalMs/2); + + if (LOG.isDebugEnabled()) + LOG.debug("Scavenging for sessions expired before "+now); + + + GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+KIND+" where expiry < @1 limit "+_maxResults); + builder.allowLiteral(true); + builder.addBinding(now); + Query query = builder.build(); QueryResults results = _datastore.run(query); while (results.hasNext()) - { + { Entity sessionEntity = results.next(); - scavengeSession(sessionEntity); - + scavengeSession(sessionEntity); } + } + /** + * Scavenge a session that has expired + * @param e + * @throws Exception + */ protected void scavengeSession (Entity e) throws Exception { @@ -782,17 +791,19 @@ public class GCloudSessionManager extends AbstractSessionManager if (session == null) return; + if (LOG.isDebugEnabled()) + LOG.debug("Scavenging session: {}",session.getId()); //if the session isn't in memory already, put it there so we can do a normal timeout call - Session memSession =_sessions.get(session.getId()); - if (memSession == null) - memSession = _sessions.putIfAbsent(session.getId(), memSession); + Session memSession = _sessions.putIfAbsent(session.getId(), session); + if (memSession == null) + memSession = session; //final check if (memSession.isExpiredAt(now)) memSession.timeout(); } - public long getScavengeInterval () + public long getScavengeIntervalSec () { return _scavengeIntervalMs/1000; } @@ -806,7 +817,7 @@ public class GCloudSessionManager extends AbstractSessionManager * * @param sec */ - public void setScavengeInterval (long sec) + public void setScavengeIntervalSec (long sec) { long old_period=_scavengeIntervalMs; 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 c5421d897c9..09e6254c7e0 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 @@ -19,6 +19,9 @@ package org.eclipse.jetty.gcloud.session; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -31,15 +34,28 @@ import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.file.Files; -import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; + import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.resource.JarResource; import org.eclipse.jetty.util.resource.Resource; import com.google.api.client.util.Strings; +import com.google.gcloud.datastore.Key; +import com.google.gcloud.datastore.Datastore; +import com.google.gcloud.datastore.DatastoreFactory; import com.google.gcloud.datastore.DatastoreOptions; +import com.google.gcloud.datastore.Entity; +import com.google.gcloud.datastore.GqlQuery; +import com.google.gcloud.datastore.ProjectionEntity; +import com.google.gcloud.datastore.Query; +import com.google.gcloud.datastore.Query.ResultType; +import com.google.gcloud.datastore.QueryResults; +import com.google.gcloud.datastore.StructuredQuery; +import com.google.gcloud.datastore.StructuredQuery.Projection; /** * GCloudSessionTestSupport @@ -94,10 +110,9 @@ public class GCloudSessionTestSupport String line; while ((line = _reader.readLine()) != (null) && !line.contains(_startupSentinel)) { - System.err.println(line); + //System.err.println(line); } } - System.err.println("SENTINEL FOUND"); } @@ -133,6 +148,7 @@ public class GCloudSessionTestSupport File _datastoreDir; File _gcdInstallDir; File _gcdUnpackedDir; + Datastore _ds; public GCloudSessionTestSupport (String projectId, int port, File gcdInstallDir) { @@ -220,9 +236,6 @@ public class GCloudSessionTestSupport processBuilder.redirectOutput(new File("/tmp/run.out")); processBuilder.command("bash", new File(_gcdUnpackedDir, "gcd.sh").getAbsolutePath(), "create", "-p",_projectId, _projectId); } - - for (String s:processBuilder.command()) - System.err.println(s); Process temp = processBuilder.start(); System.err.println("Create outcome: "+temp.waitFor()); @@ -287,4 +300,70 @@ public class GCloudSessionTestSupport stopDatastore(); clearDatastore(); } + + public void ensureDatastore() + throws Exception + { + if (_ds == null) + _ds = DatastoreFactory.instance().get(getConfiguration().getDatastoreOptions()); + } + public void listSessions () throws Exception + { + ensureDatastore(); + GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionManager.KIND); + + Query query = builder.build(); + + QueryResults results = _ds.run(query); + assertNotNull(results); + while (results.hasNext()) + { + Entity e = results.next(); + System.err.println(e.getString("clusterId")+" expires at "+e.getLong("expiry")); + } + } + + public void assertSessions(int count) throws Exception + { + ensureDatastore(); + StructuredQuery keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder() + .kind(GCloudSessionManager.KIND) + .projection(Projection.property("__key__")) + .limit(100) + .build(); + QueryResults results = _ds.run(keyOnlyProjectionQuery); + assertNotNull(results); + int actual = 0; + while (results.hasNext()) + { + results.next(); + ++actual; + } + assertEquals(count, actual); + } + + public void deleteSessions () throws Exception + { + ensureDatastore(); + StructuredQuery keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder() + .kind(GCloudSessionManager.KIND) + .projection(Projection.property("__key__")) + .limit(100) + .build(); + QueryResults results = _ds.run(keyOnlyProjectionQuery); + if (results != null) + { + List keys = new ArrayList(); + + while (results.hasNext()) + { + ProjectionEntity pe = results.next(); + keys.add(pe.key()); + } + + _ds.delete(keys.toArray(new Key[keys.size()])); + } + + assertSessions(0); + } } 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 aea6f39e075..32243d2ee0f 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 @@ -24,6 +24,9 @@ import org.eclipse.jetty.server.SessionManager; import org.eclipse.jetty.server.session.AbstractTestServer; import org.eclipse.jetty.server.session.SessionHandler; +import com.google.gcloud.datastore.Datastore; +import com.google.gcloud.datastore.DatastoreFactory; + /** * GCloudTestServer * @@ -76,7 +79,7 @@ public class GCloudTestServer extends AbstractTestServer GCloudSessionManager sessionManager = new GCloudSessionManager(); sessionManager.setSessionIdManager((GCloudSessionIdManager)_sessionIdManager); sessionManager.setStaleIntervalSec(1); - sessionManager.setScavengeInterval(_scavengePeriod); + sessionManager.setScavengeIntervalSec(_scavengePeriod); return sessionManager; } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java new file mode 100644 index 00000000000..d4f42fe78de --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java @@ -0,0 +1,70 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractLastAccessTimeTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * LastAccessTimeTest + * + * + */ +public class LastAccessTimeTest extends AbstractLastAccessTimeTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + /** + * @see org.eclipse.jetty.server.session.AbstractLastAccessTimeTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port, max, scavenge, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testLastAccessTime() throws Exception + { + super.testLastAccessTime(); + } + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java new file mode 100644 index 00000000000..ca39661a309 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java @@ -0,0 +1,71 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * LocalSessionScavengingTest + * + * + */ +public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port, max, scavenge, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testLocalSessionsScavenging() throws Exception + { + super.testLocalSessionsScavenging(); + } + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java new file mode 100644 index 00000000000..ffaaaec0da3 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java @@ -0,0 +1,75 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractOrphanedSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * OrphanedSessionTest + * + * + */ +public class OrphanedSessionTest extends AbstractOrphanedSessionTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + + /** + * @see org.eclipse.jetty.server.session.AbstractOrphanedSessionTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port, max, scavenge, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testOrphanedSession() throws Exception + { + super.testOrphanedSession(); + _testSupport.assertSessions(0); + } + + + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java new file mode 100644 index 00000000000..e8216187a57 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java @@ -0,0 +1,72 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * ReentrantRequestSessionTest + * + * + */ +public class ReentrantRequestSessionTest extends AbstractReentrantRequestSessionTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testReentrantRequestSession() throws Exception + { + super.testReentrantRequestSession(); + } + + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java index ac47692bfd8..5b7f99b3d93 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java @@ -67,7 +67,6 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest @Override public void testRemoveSession() throws Exception { - // TODO Auto-generated method stub super.testRemoveSession(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java new file mode 100644 index 00000000000..e230f43d67a --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java @@ -0,0 +1,71 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractSameNodeLoadTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * SameNodeLoadTest + * + * + */ +public class SameNodeLoadTest extends AbstractSameNodeLoadTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testLoad() throws Exception + { + super.testLoad(); + } + + +} 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 new file mode 100644 index 00000000000..59f366b6c73 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java @@ -0,0 +1,71 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractServerCrossContextSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * ServerCrossContextSessionTest + * + * + */ +public class ServerCrossContextSessionTest extends AbstractServerCrossContextSessionTest +{ + + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + /** + * @see org.eclipse.jetty.server.session.AbstractServerCrossContextSessionTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testCrossContextDispatch() throws Exception + { + super.testCrossContextDispatch(); + } + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java index dbdfc9e9d60..08bc1c40e73 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java @@ -69,13 +69,18 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest public void testSessionNotExpired() throws Exception { super.testSessionNotExpired(); + _testSupport.deleteSessions(); } + /** + * @see org.eclipse.jetty.server.session.AbstractSessionExpiryTest#testSessionExpiry() + */ @Test @Override public void testSessionExpiry() throws Exception { super.testSessionExpiry(); + _testSupport.assertSessions(0); } } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java new file mode 100644 index 00000000000..b56a13ea547 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java @@ -0,0 +1,73 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * SessionInvalidateAndCreateTest + * + * + */ +public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAndCreateTest +{ + + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port, max, scavenge, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testSessionScavenge() throws Exception + { + super.testSessionScavenge(); + } + + +} 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 new file mode 100644 index 00000000000..5ed5740746b --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java @@ -0,0 +1,72 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractSessionMigrationTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * SessionMigrationTest + * + * + */ +public class SessionMigrationTest extends AbstractSessionMigrationTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionMigrationTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _testSupport.getConfiguration()); + } + + + @Test + @Override + public void testSessionMigration() throws Exception + { + super.testSessionMigration(); + } + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java new file mode 100644 index 00000000000..c7b0c878bd5 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java @@ -0,0 +1,71 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractSessionRenewTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * SessionRenewTest + * + * + */ +public class SessionRenewTest extends AbstractSessionRenewTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port,max, scavenge, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testSessionRenewal() throws Exception + { + super.testSessionRenewal(); + } + + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java new file mode 100644 index 00000000000..54bf8ffac4d --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java @@ -0,0 +1,72 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import org.eclipse.jetty.server.session.AbstractSessionValueSavingTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * SessionValueSavingTest + * + * + */ +public class SessionValueSavingTest extends AbstractSessionValueSavingTest +{ + + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionValueSavingTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port, max, scavenge, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testSessionValueSaving() throws Exception + { + super.testSessionValueSaving(); + } + + +} 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 new file mode 100644 index 00000000000..97b656fbd20 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java @@ -0,0 +1,99 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.gcloud.session; + +import static org.junit.Assert.fail; +import org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * StopSessionManagerPreserveSessionTest + * + * + */ +public class StopSessionManagerPreserveSessionTest extends AbstractStopSessionManagerPreserveSessionTest +{ + static GCloudSessionTestSupport _testSupport; + + @BeforeClass + public static void setup () throws Exception + { + String projectId = System.getProperty("test.projectId", null); + String port = System.getProperty("test.port","0"); + _testSupport = new GCloudSessionTestSupport(projectId, + Integer.parseInt(port), + null); + _testSupport.setUp(); + } + + @AfterClass + public static void teardown () throws Exception + { + _testSupport.tearDown(); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest#checkSessionPersisted(boolean) + */ + @Override + public void checkSessionPersisted(boolean expected) + { + try + { + _testSupport.assertSessions(1); + } + catch (Exception e) + { + fail(e.getMessage()); + } + + } + + /** + * @see org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _testSupport.getConfiguration()); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractStopSessionManagerPreserveSessionTest#configureSessionManagement(org.eclipse.jetty.servlet.ServletContextHandler) + */ + @Override + public void configureSessionManagement(ServletContextHandler context) + { + + } + + @Test + @Override + public void testStopSessionManagerPreserveSession() throws Exception + { + super.testStopSessionManagerPreserveSession(); + } + + +}