diff options
author | Joakim Erdfelt | 2015-10-13 15:53:35 +0000 |
---|---|---|
committer | Joakim Erdfelt | 2015-10-13 15:53:35 +0000 |
commit | 4dfd68b315c199452e2e4e2c697a0c0b76651cd7 (patch) | |
tree | 031f09952a06344d6a65d04b554df4086d0f5612 /tests/test-sessions | |
parent | 407ca46d94b566822c219fe518b487f16d0becc4 (diff) | |
parent | 785167a0104dcefcce0c1a615a053c05b6bcea1b (diff) | |
download | org.eclipse.jetty.project-4dfd68b315c199452e2e4e2c697a0c0b76651cd7.tar.gz org.eclipse.jetty.project-4dfd68b315c199452e2e4e2c697a0c0b76651cd7.tar.xz org.eclipse.jetty.project-4dfd68b315c199452e2e4e2c697a0c0b76651cd7.zip |
Merge branch 'jetty-9.3.x'
Conflicts:
aggregates/jetty-all-compact3/pom.xml
aggregates/jetty-all/pom.xml
apache-jsp/pom.xml
apache-jstl/pom.xml
examples/async-rest/async-rest-jar/pom.xml
examples/async-rest/async-rest-webapp/pom.xml
examples/async-rest/pom.xml
examples/embedded/pom.xml
examples/pom.xml
jetty-alpn/jetty-alpn-client/pom.xml
jetty-alpn/jetty-alpn-server/pom.xml
jetty-alpn/pom.xml
jetty-annotations/pom.xml
jetty-ant/pom.xml
jetty-cdi/cdi-core/pom.xml
jetty-cdi/cdi-full-servlet/pom.xml
jetty-cdi/cdi-servlet/pom.xml
jetty-cdi/cdi-websocket/pom.xml
jetty-cdi/pom.xml
jetty-cdi/test-cdi-webapp/pom.xml
jetty-client/pom.xml
jetty-continuation/pom.xml
jetty-deploy/pom.xml
jetty-distribution/pom.xml
jetty-fcgi/fcgi-client/pom.xml
jetty-fcgi/fcgi-server/pom.xml
jetty-fcgi/pom.xml
jetty-http-spi/pom.xml
jetty-http/pom.xml
jetty-http2/http2-alpn-tests/pom.xml
jetty-http2/http2-client/pom.xml
jetty-http2/http2-common/pom.xml
jetty-http2/http2-hpack/pom.xml
jetty-http2/http2-http-client-transport/pom.xml
jetty-http2/http2-server/pom.xml
jetty-http2/pom.xml
jetty-infinispan/pom.xml
jetty-io/pom.xml
jetty-jaas/pom.xml
jetty-jaspi/pom.xml
jetty-jmx/pom.xml
jetty-jndi/pom.xml
jetty-jspc-maven-plugin/pom.xml
jetty-maven-plugin/pom.xml
jetty-monitor/pom.xml
jetty-nosql/pom.xml
jetty-osgi/jetty-osgi-alpn/pom.xml
jetty-osgi/jetty-osgi-boot-jsp/pom.xml
jetty-osgi/jetty-osgi-boot-warurl/pom.xml
jetty-osgi/jetty-osgi-boot/pom.xml
jetty-osgi/jetty-osgi-httpservice/pom.xml
jetty-osgi/pom.xml
jetty-osgi/test-jetty-osgi-context/pom.xml
jetty-osgi/test-jetty-osgi-webapp/pom.xml
jetty-osgi/test-jetty-osgi/pom.xml
jetty-plus/pom.xml
jetty-proxy/pom.xml
jetty-quickstart/pom.xml
jetty-rewrite/pom.xml
jetty-runner/pom.xml
jetty-security/pom.xml
jetty-server/pom.xml
jetty-servlet/pom.xml
jetty-servlets/pom.xml
jetty-spring/pom.xml
jetty-start/pom.xml
jetty-util-ajax/pom.xml
jetty-util/pom.xml
jetty-webapp/pom.xml
jetty-websocket/javax-websocket-client-impl/pom.xml
jetty-websocket/javax-websocket-server-impl/pom.xml
jetty-websocket/pom.xml
jetty-websocket/websocket-api/pom.xml
jetty-websocket/websocket-client/pom.xml
jetty-websocket/websocket-common/pom.xml
jetty-websocket/websocket-server/pom.xml
jetty-websocket/websocket-servlet/pom.xml
jetty-xml/pom.xml
pom.xml
tests/pom.xml
tests/test-continuation/pom.xml
tests/test-http-client-transport/pom.xml
tests/test-integration/pom.xml
tests/test-jmx/jmx-webapp-it/pom.xml
tests/test-jmx/jmx-webapp/pom.xml
tests/test-jmx/pom.xml
tests/test-loginservice/pom.xml
tests/test-quickstart/pom.xml
tests/test-sessions/pom.xml
tests/test-sessions/test-hash-sessions/pom.xml
tests/test-sessions/test-infinispan-sessions/pom.xml
tests/test-sessions/test-jdbc-sessions/pom.xml
tests/test-sessions/test-mongodb-sessions/pom.xml
tests/test-sessions/test-sessions-common/pom.xml
tests/test-webapps/pom.xml
tests/test-webapps/test-jaas-webapp/pom.xml
tests/test-webapps/test-jetty-webapp/pom.xml
tests/test-webapps/test-jndi-webapp/pom.xml
tests/test-webapps/test-mock-resources/pom.xml
tests/test-webapps/test-proxy-webapp/pom.xml
tests/test-webapps/test-servlet-spec/pom.xml
tests/test-webapps/test-servlet-spec/test-container-initializer/pom.xml
tests/test-webapps/test-servlet-spec/test-spec-webapp/pom.xml
tests/test-webapps/test-servlet-spec/test-web-fragment/pom.xml
tests/test-webapps/test-webapp-rfc2616/pom.xml
Diffstat (limited to 'tests/test-sessions')
23 files changed, 1936 insertions, 1 deletions
diff --git a/tests/test-sessions/pom.xml b/tests/test-sessions/pom.xml index ddcf953635..a3dda9f0e3 100644 --- a/tests/test-sessions/pom.xml +++ b/tests/test-sessions/pom.xml @@ -35,5 +35,6 @@ <module>test-jdbc-sessions</module> <module>test-mongodb-sessions</module> <module>test-infinispan-sessions</module> + <module>test-gcloud-sessions</module> </modules> </project> diff --git a/tests/test-sessions/test-gcloud-sessions/pom.xml b/tests/test-sessions/test-gcloud-sessions/pom.xml new file mode 100644 index 0000000000..1c487b7f3b --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/pom.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +// ======================================================================== +// Copyright (c) Webtide LLC +// +// 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.apache.org/licenses/LICENSE-2.0.txt +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.eclipse.jetty.tests</groupId> + <artifactId>test-sessions-parent</artifactId> + <version>9.3.4-SNAPSHOT</version> + </parent> + <artifactId>test-gcloud-sessions</artifactId> + <name>Jetty Tests :: Sessions :: GCloud</name> + <url>http://www.eclipse.org/jetty</url> + <properties> + <bundle-symbolic-name>${project.groupId}.sessions.gcloud</bundle-symbolic-name> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <!-- DO NOT DEPLOY (or Release) --> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-client</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.tests</groupId> + <artifactId>test-sessions-common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.gcloud</groupId> + <artifactId>gcloud-session-manager</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.toolchain</groupId> + <artifactId>jetty-test-helper</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <profiles> + <profile> + <id>gcloud</id> + <activation> + <property> + <name>gcloud.enabled</name> + <value>true</value> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>false</skipTests> + <systemPropertyVariables> + <test.projectId>jetty9-work</test.projectId> + <test.port>8088</test.port> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> 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 new file mode 100644 index 0000000000..5d05a3f698 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.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.AbstractClientCrossContextSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * ClientCrossContextSessionTest + * + * + */ +public class ClientCrossContextSessionTest extends AbstractClientCrossContextSessionTest +{ + 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.AbstractClientCrossContextSessionTest#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/ForwardedSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java new file mode 100644 index 0000000000..20109ae51f --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java @@ -0,0 +1,62 @@ +// +// ======================================================================== +// 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.AbstractForwardedSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * ForwardedSessionTest + * + * + */ +public class ForwardedSessionTest extends AbstractForwardedSessionTest +{ + 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.AbstractForwardedSessionTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _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 new file mode 100644 index 0000000000..adfdf9b7a5 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java @@ -0,0 +1,372 @@ +// +// ======================================================================== +// 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.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.file.Files; +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 + * + * + */ +public class GCloudSessionTestSupport +{ + + /** + * GCloudTestConfiguration + * + * Specialization of GCloudConfiguration for gcd test environment + * + */ + public class GCloudTestConfiguration extends GCloudConfiguration + { + int _port; + + public GCloudTestConfiguration(String projectId, int port) + { + setProjectId(projectId); + _port = port; + } + + + @Override + public DatastoreOptions getDatastoreOptions() throws Exception + { + return DatastoreOptions.builder() + .projectId(_projectId) + .host("http://localhost:" + _port) + .build(); + } + } + + + private static class ProcessOutputReader implements Runnable + { + private InputStream _is; + private String _startupSentinel; + private BufferedReader _reader; + + public ProcessOutputReader (InputStream is, String startupSentinel) + throws Exception + { + _is = is; + _startupSentinel = startupSentinel; + _reader = new BufferedReader(new InputStreamReader(_is)); + if (!Strings.isNullOrEmpty(_startupSentinel)) + { + String line; + while ((line = _reader.readLine()) != (null) && !line.contains(_startupSentinel)) + { + //System.err.println(line); + } + } + } + + + public void run() + { + String line; + try + { + while ((line = _reader.readLine()) != (null)) + { + } + } + catch (IOException ignore) + { + /* ignore */ + } + finally + { + IO.close(_reader); + } + } + } + + + public static String DEFAULT_PROJECTID = "jetty9-work"; + public static int DEFAULT_PORT = 8088; + public static String DEFAULT_GCD_ZIP = "gcd-v1beta2-rev1-2.1.2b.zip"; + public static String DEFAULT_GCD_UNPACKED = "gcd-v1beta2-rev1-2.1.2b"; + public static String DEFAULT_DOWNLOAD_URL = "http://storage.googleapis.com/gcd/tools/"; + + String _projectId; + int _port; + File _datastoreDir; + File _gcdInstallDir; + File _gcdUnpackedDir; + Datastore _ds; + + public GCloudSessionTestSupport (String projectId, int port, File gcdInstallDir) + { + _projectId = projectId; + if (_projectId == null) + _projectId = DEFAULT_PROJECTID; + _port = port; + if (_port <= 0) + _port = DEFAULT_PORT; + + _gcdInstallDir = gcdInstallDir; + if (_gcdInstallDir == null) + _gcdInstallDir = new File (System.getProperty("java.io.tmpdir")); + } + + public GCloudSessionTestSupport () + { + this(null,0, null); + } + + public GCloudConfiguration getConfiguration () + { + return new GCloudTestConfiguration(_projectId, _port); + } + + + public void setUp() + throws Exception + { + downloadGCD(); + createDatastore(); + startDatastore(); + } + + + public void downloadGCD() + throws Exception + { + File zipFile = new File (_gcdInstallDir, DEFAULT_GCD_ZIP); + _gcdUnpackedDir = new File (_gcdInstallDir, DEFAULT_GCD_UNPACKED); + File gcdSh = new File (_gcdUnpackedDir, "gcd.sh"); + if (gcdSh.exists()) + return; + + + if (_gcdInstallDir.exists() && !zipFile.exists()) + { + //download it + ReadableByteChannel rbc = Channels.newChannel(new URL(DEFAULT_DOWNLOAD_URL+DEFAULT_GCD_ZIP).openStream()); + try (FileOutputStream fos = new FileOutputStream(zipFile)) + { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + } + } + + if (zipFile.exists()) + { + //unpack it + Resource zipResource = JarResource.newJarResource(Resource.newResource(zipFile)); + zipResource.copyTo(_gcdInstallDir); + } + + System.err.println("GCD downloaded and unpacked"); + } + + + + public void createDatastore () + throws Exception + { + + _datastoreDir = Files.createTempDirectory("gcloud-sessions").toFile(); + _datastoreDir.deleteOnExit(); + + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT); + processBuilder.directory(_datastoreDir); + if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")) + { + processBuilder.command("cmd", "/C", new File(_gcdUnpackedDir, "gcd.cmd").getAbsolutePath(), "create", "-p", _projectId, _projectId); + processBuilder.redirectOutput(new File("NULL:")); + } + else + { + processBuilder.redirectOutput(new File("/tmp/run.out")); + processBuilder.command("bash", new File(_gcdUnpackedDir, "gcd.sh").getAbsolutePath(), "create", "-p",_projectId, _projectId); + } + + Process temp = processBuilder.start(); + System.err.println("Create outcome: "+temp.waitFor()); + } + + + public void startDatastore() + throws Exception + { + //start the datastore for the test + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.directory(_datastoreDir); + processBuilder.redirectErrorStream(true); + if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")) + { + processBuilder.command("cmd", "/C", new File(_gcdUnpackedDir, "gcd.cmd").getAbsolutePath(), "start", "--testing", "--allow_remote_shutdown","--port="+String.valueOf(_port), _projectId); + } + else + { + processBuilder.command("bash", new File(_gcdUnpackedDir, "gcd.sh").getAbsolutePath(), "start", "--testing", "--allow_remote_shutdown", "--port="+String.valueOf(_port), _projectId); + } + + System.err.println("Starting datastore"); + Process temp = processBuilder.start(); + ProcessOutputReader reader = new ProcessOutputReader(temp.getInputStream(), "Dev App Server is now running"); + Thread readerThread = new Thread(reader, "GCD reader"); + readerThread.setDaemon(true); + readerThread.start(); + } + + public void stopDatastore() + throws Exception + { + //Send request to terminate test datastore + URL url = new URL("http", "localhost", _port, "/_ah/admin/quit"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + OutputStream out = con.getOutputStream(); + out.write("".getBytes()); + out.flush(); + InputStream in = con.getInputStream(); + while (in.read() != -1) + { + // consume input + + } + + System.err.println("Stop issued"); + } + + + public void clearDatastore() + { + org.eclipse.jetty.util.IO.delete(_datastoreDir); + } + + public void tearDown() + throws Exception + { + 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<Entity> query = builder.build(); + + QueryResults<Entity> results = _ds.run(query); + assertNotNull(results); + System.err.println("SESSIONS::::::::"); + while (results.hasNext()) + { + + Entity e = results.next(); + System.err.println(e.getString("clusterId")+" expires at "+e.getLong("expiry")); + } + System.err.println("END OF SESSIONS::::::::"); + } + + public void assertSessions(int count) throws Exception + { + ensureDatastore(); + StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder() + .kind(GCloudSessionManager.KIND) + .projection(Projection.property("__key__")) + .limit(100) + .build(); + QueryResults<ProjectionEntity> 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<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder() + .kind(GCloudSessionManager.KIND) + .projection(Projection.property("__key__")) + .limit(100) + .build(); + QueryResults<ProjectionEntity> results = _ds.run(keyOnlyProjectionQuery); + if (results != null) + { + List<Key> keys = new ArrayList<Key>(); + + 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 new file mode 100644 index 0000000000..11f2125f68 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudTestServer.java @@ -0,0 +1,97 @@ +// +// ======================================================================== +// 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.SessionIdManager; +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 + * + * + */ +public class GCloudTestServer extends AbstractTestServer +{ + static int __workers=0; + public static int STALE_INTERVAL_SEC = 1; + + + + /** + * @param port + * @param maxInactivePeriod + * @param scavengePeriod + * @param sessionIdMgrConfig + */ + public GCloudTestServer(int port, int maxInactivePeriod, int scavengePeriod, GCloudConfiguration config) + { + super(port, maxInactivePeriod, scavengePeriod, config); + } + + /** + * @param port + * @param configuration + */ + public GCloudTestServer(int port, GCloudConfiguration configuration) + { + super(port, 30,10, configuration); + } + + /** + * @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionIdManager(java.lang.Object) + */ + @Override + public SessionIdManager newSessionIdManager(Object config) + { + GCloudSessionIdManager idManager = new GCloudSessionIdManager(getServer()); + idManager.setWorkerName("w"+(__workers++)); + idManager.setConfig((GCloudConfiguration)config); + return idManager; + } + + /** + * @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionManager() + */ + @Override + public SessionManager newSessionManager() + { + GCloudSessionManager sessionManager = new GCloudSessionManager(); + sessionManager.setSessionIdManager((GCloudSessionIdManager)_sessionIdManager); + sessionManager.setStaleIntervalSec(STALE_INTERVAL_SEC); + sessionManager.setScavengeIntervalSec(_scavengePeriod); + return sessionManager; + + } + + /** + * @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionHandler(org.eclipse.jetty.server.SessionManager) + */ + @Override + public SessionHandler newSessionHandler(SessionManager sessionManager) + { + return new SessionHandler(sessionManager); + } + +} diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java new file mode 100644 index 0000000000..84c3840d21 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.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.AbstractImmortalSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * ImmortalSessionTest + * + * + */ +public class ImmortalSessionTest extends AbstractImmortalSessionTest +{ + 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.AbstractImmortalSessionTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs) + { + return new GCloudTestServer(port, port, scavengeMs, _testSupport.getConfiguration()); + } + + @Test + @Override + public void testImmortalSession() throws Exception + { + super.testImmortalSession(); + } + + +} 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 new file mode 100644 index 0000000000..6cc875cb71 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java @@ -0,0 +1,82 @@ +// +// ======================================================================== +// 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.AbstractInvalidationSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * InvalidationSessionTest + * + * + */ +public class InvalidationSessionTest extends AbstractInvalidationSessionTest +{ + 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.AbstractInvalidationSessionTest#createServer(int) + */ + @Override + public AbstractTestServer createServer(int port) + { + return new GCloudTestServer(port, _testSupport.getConfiguration()); + } + + /** + * @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*GCloudTestServer.STALE_INTERVAL_SEC)*1000); + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + +} 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 0000000000..d4f42fe78d --- /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 0000000000..ca39661a30 --- /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/NewSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java new file mode 100644 index 0000000000..1dc256b74b --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java @@ -0,0 +1,74 @@ +// +// ======================================================================== +// 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 java.io.File; + +import org.eclipse.jetty.server.session.AbstractNewSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * NewSessionTest + * + * + */ +public class NewSessionTest extends AbstractNewSessionTest +{ + GCloudSessionTestSupport _testSupport; + + @Before + public 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(); + } + + @After + public void teardown () throws Exception + { + _testSupport.tearDown(); + } + + + /** + * @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int) + */ + @Override + public AbstractTestServer createServer(int port, int max, int scavenge) + { + return new GCloudTestServer(port, max, scavenge, _testSupport.getConfiguration()); + } + + @Test + public void testNewSession() throws Exception + { + super.testNewSession(); + } +} 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 0000000000..ffaaaec0da --- /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 0000000000..e8216187a5 --- /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 new file mode 100644 index 0000000000..5b7f99b3d9 --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.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.AbstractRemoveSessionTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * RemoveSessionTest + * + * + */ +public class RemoveSessionTest extends AbstractRemoveSessionTest +{ + 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.AbstractRemoveSessionTest#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 testRemoveSession() throws Exception + { + 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 0000000000..e230f43d67 --- /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 0000000000..59f366b6c7 --- /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 new file mode 100644 index 0000000000..785a2a19ec --- /dev/null +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java @@ -0,0 +1,102 @@ +// +// ======================================================================== +// 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.AbstractSessionExpiryTest; +import org.eclipse.jetty.server.session.AbstractTestServer; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * SessionExpiryTest + * + * + */ +public class SessionExpiryTest extends AbstractSessionExpiryTest +{ + + 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.AbstractSessionExpiryTest#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 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); + } + + @Override + public void verifySessionCreated(TestHttpSessionListener listener, String sessionId) + { + super.verifySessionCreated(listener, sessionId); + try{ _testSupport.listSessions(); _testSupport.assertSessions(1);}catch(Exception e) {e.printStackTrace();} + } + + @Override + public void verifySessionDestroyed(TestHttpSessionListener listener, String sessionId) + { + super.verifySessionDestroyed(listener, sessionId); + try{ _testSupport.listSessions(); _testSupport.assertSessions(0);}catch(Exception e) {e.printStackTrace();} + } + + + +} 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 0000000000..b56a13ea54 --- /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 0000000000..5ed5740746 --- /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 0000000000..c7b0c878bd --- /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 0000000000..54bf8ffac4 --- /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 0000000000..97b656fbd2 --- /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(); + } + + +} 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 0d1ac5ba92..8d2d660404 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 @@ -83,19 +83,22 @@ public abstract class AbstractInvalidationSessionTest assertTrue(sessionCookie != null); // Mangle the cookie, replacing Path with $Path, etc. sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path="); - + + // Be sure the session is also present in node2 Request request2 = client.newRequest(urls[1] + "?action=increment"); request2.header("Cookie", sessionCookie); ContentResponse response2 = request2.send(); assertEquals(HttpServletResponse.SC_OK,response2.getStatus()); + // Invalidate on node1 Request request1 = client.newRequest(urls[0] + "?action=invalidate"); request1.header("Cookie", sessionCookie); response1 = request1.send(); assertEquals(HttpServletResponse.SC_OK, response1.getStatus()); + pause(); |