Merge branch 'gcloud-session-manager' into jetty-9.3.x

This commit is contained in:
Jan Bartel 2015-10-13 08:36:36 +11:00
commit 84ef692be5
34 changed files with 4055 additions and 14 deletions

View File

@ -778,6 +778,11 @@
<artifactId>jetty-infinispan</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</groupId>
<artifactId>jetty-nosql</artifactId>

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>org.eclipse.jetty.gcloud</groupId>
<artifactId>gcloud-parent</artifactId>
<version>9.3.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gcloud-session-manager</artifactId>
<name>Jetty :: GCloud :: Session Manager</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>${gcloud.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-servlet</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<bundle-symbolic-name>${project.groupId}.session</bundle-symbolic-name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Export-Package>org.eclipse.jetty.gcloud.session.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}";</Export-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,43 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ============================================================================================== -->
<!-- GCloud configuration from property file -->
<!-- Note: passwords stored in the property file can use jetty obfuscation (see -->
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
<!-- ============================================================================================== -->
<Call id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration" name="fromFile">
<Arg><Property name="jetty.base" default="."/>/<Property name="jetty.gcloudSession.configFile" default="etc/gcloud.props"/></Arg>
</Call>
<!-- ============================================================================================== -->
<!-- Alternate GCloud configuration from properties -->
<!-- Note: passwords can use jetty obfuscation (see -->
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
<!-- ============================================================================================== -->
<!--
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"/></Set>
<Set name="p12File"><Property name="jetty.gcloudSession.p12File"/></Set>
<Set name="serviceAccount"><Property name="jetty.gcloudSession.serviceAccount"/></Set>
<Set name="password"><Property name="jetty.gcloudSession.password"/></Set>
</New>
-->
<!-- ===================================================================== -->
<!-- Configure a GCloudSessionIdManager -->
<!-- ===================================================================== -->
<Set name="sessionIdManager">
<New id="idMgr" class="org.eclipse.jetty.gcloud.session.GCloudSessionIdManager">
<Arg>
<Ref id="Server"/>
</Arg>
<Set name="workerName"><Property name="jetty.gcloudSession.workerName" default="node1"/></Set>
<Set name="config"><Ref id="gconf"/></Set>
</New>
</Set>
</Configure>

View File

@ -0,0 +1,75 @@
#
# Jetty GCloudDatastore Session Manager module
#
[depend]
annotations
webapp
[files]
maven://com.google.gcloud/gcloud-java-datastore/0.0.7|lib/gcloud/gcloud-java-datastore-0.0.7.jar
maven://com.google.gcloud/gcloud-java-core/0.0.7|lib/gcloud/gcloud-java-core-0.0.7.jar
maven://com.google.auth/google-auth-library-credentials/0.1.0|lib/gcloud/google-auth-library-credentials-0.1.0.jar
maven://com.google.auth/google-auth-library-oauth2-http/0.1.0|lib/gcloud/google-auth-library-oauth2-http-0.1.0.jar
maven://com.google.http-client/google-http-client-jackson2/1.19.0|lib/gcloud/google-http-client-jackson2-1.19.0.jar
maven://com.fasterxml.jackson.core/jackson-core/2.1.3|lib/gcloud/jackson-core-2.1.3.jar
maven://com.google.http-client/google-http-client/1.20.0|lib/gcloud/google-http-client-1.20.0.jar
maven://com.google.code.findbugs/jsr305/1.3.9|lib/gcloud/jsr305-1.3.9.jar
maven://org.apache.httpcomponents/httpclient/4.0.1|lib/gcloud/httpclient-4.0.1.jar
maven://org.apache.httpcomponents/httpcore/4.0.1|lib/gcloud/httpcore-4.0.1.jar
maven://commons-logging/commons-logging/1.1.1|lib/gcloud/commons-logging-1.1.1.jar
maven://commons-codec/commons-codec/1.3|lib/gcloud/commons-codec-1.3.jar
maven://com.google.oauth-client/google-oauth-client/1.20.0|lib/gcloud//google-oauth-client-1.20.0.jar
maven://com.google.guava/guava/18.0|lib/gcloud/guava-18.0.jar
maven://com.google.api-client/google-api-client-appengine/1.20.0|lib/gcloud/google-api-client-appengine-1.20.0.jar
maven://com.google.oauth-client/google-oauth-client-appengine/1.20.0|lib/gcloud/google-oauth-client-appengine-1.20.0.jar
maven://com.google.oauth-client/google-oauth-client-servlet/1.20.0|lib/gcloud/google-oauth-client-servlet-1.20.0.jar
maven://com.google.http-client/google-http-client-jdo/1.20.0|lib/gcloud/google-http-client-jdo-1.20.0.jar
maven://com.google.api-client/google-api-client-servlet/1.20.0|lib/gcloud/google-api-client-servlet-1.20.0.jar
maven://javax.jdo/jdo2-api/2.3-eb|lib/gcloud/jdo2-api-2.3-eb.jar
maven://javax.transaction/transaction-api/1.1|lib/gcloud/transaction-api-1.1.jar
maven://com.google.http-client/google-http-client-appengine/1.20.0|lib/gcloud/google-http-client-appengine-1.20.0.jar
maven://com.google.http-client/google-http-client-jackson/1.20.0|lib/gcloud/google-http-client-jackson-1.20.0.jar
maven://org.codehaus.jackson/jackson-core-asl/1.9.11|lib/gcloud/jackson-core-asl-1.9.11.jar
maven://joda-time/joda-time/2.8.2|lib/gcloud/joda-time-2.8.2.jar
maven://org.json/json/20090211|lib/gcloud/json-20090211.jar
maven://com.google.apis/google-api-services-datastore-protobuf/v1beta2-rev1-2.1.2|lib/gcloud/google-api-services-datastore-protobuf-v1beta2-rev1-2.1.2.jar
maven://com.google.protobuf/protobuf-java/2.5.0|lib/gcloud/protobuf-java-2.5.0.jar
maven://com.google.http-client/google-http-client-protobuf/1.15.0-rc|lib/gcloud/google-http-client-protobuf-1.15.0-rc.jar
maven://com.google.api-client/google-api-client/1.15.0-rc|lib/gcloud/google-api-client-1.15.0-rc.jar
maven://com.google.apis/google-api-services-datastore/v1beta2-rev23-1.19.0|lib/gcloud/google-api-services-datastore-v1beta2-rev23-1.19.0.jar
[lib]
lib/gcloud-session-manager-${jetty.version}.jar
lib/gcloud/*.jar
[xml]
etc/jetty-gcloud-sessions.xml
[license]
GCloudDatastore is an open source project hosted on Github and released under the Apache 2.0 license.
https://github.com/GoogleCloudPlatform/gcloud-java
http://www.apache.org/licenses/LICENSE-2.0.html
[ini-template]
## GCloudDatastore Session config
## Unique identifier for this node in the cluster
# jetty.gcloudSession.workerName=node1
## Name of properties files containing gcloud config
#jetty.gcloudSession.configFilet=etc/gcloud.props
##Alternative to properties file, individual properties
## the gcloud projectId
#jetty.gcloudSession.projectId=
## the p12 file associated with the project
#jetty.gcloudSession.p12File=
## the serviceAccount for the Datastore
#jetty.gcloudSession.serviceAccount=
## the password (can be obfuscated)
#jetty.gcloudSession.password=

View File

@ -0,0 +1,184 @@
//
// ========================================================================
// 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 java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.util.Properties;
import org.eclipse.jetty.util.security.Password;
import com.google.gcloud.AuthCredentials;
import com.google.gcloud.datastore.DatastoreOptions;
/**
* GCloudConfiguration
*
*
*/
public class GCloudConfiguration
{
public static final String PROJECT_ID = "projectId";
public static final String P12 = "p12";
public static final String PASSWORD = "password";
public static final String SERVICE_ACCOUNT = "serviceAccount";
private String _projectId;
private File _p12File;
private String _serviceAccount;
private String _password;
private AuthCredentials _authCredentials;
private DatastoreOptions _options;
/**
* Generate a configuration from a properties file
*
* @param propsFile
* @return
* @throws IOException
*/
public static GCloudConfiguration fromFile(String propsFile)
throws IOException
{
if (propsFile == null)
throw new IllegalArgumentException ("Null properties file");
File f = new File(propsFile);
if (!f.exists())
throw new IllegalArgumentException("No such file "+f.getAbsolutePath());
Properties props = new Properties();
try (FileInputStream is=new FileInputStream(f))
{
props.load(is);
}
GCloudConfiguration config = new GCloudConfiguration();
config.setProjectId(props.getProperty(PROJECT_ID));
config.setP12File(props.getProperty(P12));
config.setPassword(props.getProperty(PASSWORD));
config.setServiceAccount(props.getProperty(SERVICE_ACCOUNT));
return config;
}
public String getProjectId()
{
return _projectId;
}
public File getP12File()
{
return _p12File;
}
public String getServiceAccount()
{
return _serviceAccount;
}
public void setProjectId(String projectId)
{
checkForModification();
_projectId = projectId;
}
public void setP12File (String file)
{
checkForModification();
_p12File = new File(file);
}
public void setServiceAccount (String serviceAccount)
{
checkForModification();
_serviceAccount = serviceAccount;
}
public void setPassword (String pwd)
{
checkForModification();
Password p = new Password(pwd);
_password = p.toString();
}
public DatastoreOptions getDatastoreOptions ()
throws Exception
{
if (_options == null)
{
_options = DatastoreOptions.builder()
.projectId(_projectId)
.authCredentials(getAuthCredentials())
.build();
}
return _options;
}
/**
* @return
* @throws Exception
*/
public AuthCredentials getAuthCredentials()
throws Exception
{
if (_authCredentials == null)
{
if (_password == null)
throw new IllegalStateException("No password");
if (_projectId == null)
throw new IllegalStateException("No project id");
if (_projectId == null)
throw new IllegalStateException("No project id");
if (_p12File == null || !_p12File.exists())
throw new IllegalStateException("No p12 file: "+(_p12File==null?"null":_p12File.getAbsolutePath()));
if (_serviceAccount == null)
throw new IllegalStateException("No service account");
char[] pwdChars = _password.toCharArray();
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(new FileInputStream(getP12File()), pwdChars);
PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", pwdChars);
_authCredentials = AuthCredentials.createFor(getServiceAccount(), privateKey);
}
return _authCredentials;
}
/**
* @throws IllegalStateException
*/
protected void checkForModification () throws IllegalStateException
{
if (_authCredentials != null || _options != null)
throw new IllegalStateException("Cannot modify auth configuration after datastore initialized");
}
}

View File

@ -0,0 +1,323 @@
//
// ========================================================================
// 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.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SessionManager;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.session.AbstractSession;
import org.eclipse.jetty.server.session.AbstractSessionIdManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import com.google.gcloud.datastore.Datastore;
import com.google.gcloud.datastore.DatastoreFactory;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;
/**
* GCloudSessionIdManager
*
*
*
*/
public class GCloudSessionIdManager extends AbstractSessionIdManager
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
public static final int DEFAULT_IDLE_EXPIRY_MULTIPLE = 2;
public static final String KIND = "GCloudSessionId";
private Server _server;
private Datastore _datastore;
private KeyFactory _keyFactory;
private GCloudConfiguration _config;
/**
* @param server
*/
public GCloudSessionIdManager(Server server)
{
super();
_server = server;
}
/**
* @param server
* @param random
*/
public GCloudSessionIdManager(Server server, Random random)
{
super(random);
_server = server;
}
/**
* Start the id manager.
* @see org.eclipse.jetty.server.session.AbstractSessionIdManager#doStart()
*/
@Override
protected void doStart() throws Exception
{
if (_config == null)
throw new IllegalStateException("No gcloud configuration specified");
_datastore = DatastoreFactory.instance().get(_config.getDatastoreOptions());
_keyFactory = _datastore.newKeyFactory().kind(KIND);
super.doStart();
}
/**
* Stop the id manager
* @see org.eclipse.jetty.server.session.AbstractSessionIdManager#doStop()
*/
@Override
protected void doStop() throws Exception
{
super.doStop();
}
/**
* Check to see if the given session id is being
* used by a session in any context.
*
* This method will consult the cluster.
*
* @see org.eclipse.jetty.server.SessionIdManager#idInUse(java.lang.String)
*/
@Override
public boolean idInUse(String id)
{
if (id == null)
return false;
String clusterId = getClusterId(id);
//ask the cluster - this should also tickle the idle expiration timer on the sessionid entry
//keeping it valid
try
{
return exists(clusterId);
}
catch (Exception e)
{
LOG.warn("Problem checking inUse for id="+clusterId, e);
return false;
}
}
/**
* Remember a new in-use session id.
*
* This will save the in-use session id to the cluster.
*
* @see org.eclipse.jetty.server.SessionIdManager#addSession(javax.servlet.http.HttpSession)
*/
@Override
public void addSession(HttpSession session)
{
if (session == null)
return;
//insert into the store
insert (((AbstractSession)session).getClusterId());
}
public GCloudConfiguration getConfig()
{
return _config;
}
public void setConfig(GCloudConfiguration config)
{
_config = config;
}
/**
* Remove a session id from the list of in-use ids.
*
* This will remvove the corresponding session id from the cluster.
*
* @see org.eclipse.jetty.server.SessionIdManager#removeSession(javax.servlet.http.HttpSession)
*/
@Override
public void removeSession(HttpSession session)
{
if (session == null)
return;
//delete from the cache
delete (((AbstractSession)session).getClusterId());
}
/**
* Remove a session id. This compels all other contexts who have a session
* with the same id to also remove it.
*
* @see org.eclipse.jetty.server.SessionIdManager#invalidateAll(java.lang.String)
*/
@Override
public void invalidateAll(String id)
{
//delete the session id from list of in-use sessions
delete (id);
//tell all contexts that may have a session object with this id to
//get rid of them
Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class);
for (int i=0; contexts!=null && i<contexts.length; i++)
{
SessionHandler sessionHandler = ((ContextHandler)contexts[i]).getChildHandlerByClass(SessionHandler.class);
if (sessionHandler != null)
{
SessionManager manager = sessionHandler.getSessionManager();
if (manager != null && manager instanceof GCloudSessionManager)
{
((GCloudSessionManager)manager).invalidateSession(id);
}
}
}
}
/**
* Change a session id.
*
* Typically this occurs when a previously existing session has passed through authentication.
*
* @see org.eclipse.jetty.server.session.AbstractSessionIdManager#renewSessionId(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
*/
@Override
public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request)
{
//generate a new id
String newClusterId = newSessionId(request.hashCode());
delete(oldClusterId);
insert(newClusterId);
//tell all contexts to update the id
Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class);
for (int i=0; contexts!=null && i<contexts.length; i++)
{
SessionHandler sessionHandler = ((ContextHandler)contexts[i]).getChildHandlerByClass(SessionHandler.class);
if (sessionHandler != null)
{
SessionManager manager = sessionHandler.getSessionManager();
if (manager != null && manager instanceof GCloudSessionManager)
{
((GCloudSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
}
}
}
}
/**
* Ask the datastore if a particular id exists.
*
* @param id
* @return
*/
protected boolean exists (String id)
{
if (_datastore == null)
throw new IllegalStateException ("No DataStore");
Key key = _keyFactory.newKey(id);
return _datastore.get(key) != null;
}
/**
* Put a session id into the cluster.
*
* @param id
*/
protected void insert (String id)
{
if (_datastore == null)
throw new IllegalStateException ("No DataStore");
Entity entity = Entity.builder(makeKey(id))
.set("id", id).build();
_datastore.put(entity);
}
/**
* Remove a session id from the cluster.
*
* @param id
*/
protected void delete (String id)
{
if (_datastore == null)
throw new IllegalStateException ("No DataStore");
_datastore.delete(makeKey(id));
}
/**
* Generate a unique key from the session id.
*
* @param id
* @return
*/
protected Key makeKey (String id)
{
return _keyFactory.newKey(id);
}
}

View File

@ -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.security.HashLoginService;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.webapp.WebAppContext;
public class GCloudSessionTester
{
public static void main( String[] args ) throws Exception
{
if (args.length < 4)
System.err.println("Usage: GCloudSessionTester projectid p12file password serviceaccount");
System.setProperty("org.eclipse.jetty.server.session.LEVEL", "DEBUG");
Server server = new Server(8080);
HashLoginService loginService = new HashLoginService();
loginService.setName( "Test Realm" );
loginService.setConfig( "../../jetty-distribution/target/distribution/demo-base/resources/realm.properties" );
server.addBean( loginService );
GCloudConfiguration config = new GCloudConfiguration();
config.setProjectId(args[0]);
config.setP12File(args[1]);
config.setPassword(args[2]);
config.setServiceAccount(args[3]);
GCloudSessionIdManager idmgr = new GCloudSessionIdManager(server);
idmgr.setConfig(config);
idmgr.setWorkerName("w1");
server.setSessionIdManager(idmgr);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
GCloudSessionManager mgr = new GCloudSessionManager();
mgr.setSessionIdManager(idmgr);
webapp.setSessionHandler(new SessionHandler(mgr));
// A WebAppContext is a ContextHandler as well so it needs to be set to
// the server so it is aware of where to send the appropriate requests.
server.setHandler(webapp);
// Start things up!
server.start();
server.join();
}
}

23
jetty-gcloud/pom.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>jetty-project</artifactId>
<groupId>org.eclipse.jetty</groupId>
<version>9.3.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.gcloud</groupId>
<artifactId>gcloud-parent</artifactId>
<packaging>pom</packaging>
<name>Jetty :: GCloud</name>
<properties>
<gcloud.version>0.0.8</gcloud.version>
</properties>
<modules>
<module>gcloud-session-manager</module>
</modules>
</project>

View File

@ -73,6 +73,7 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
private static final Logger LOG = Log.getLogger(ServletHolder.class);
private int _initOrder = -1;
private boolean _initOnStartup=false;
private boolean _initialized = false;
private Map<String, String> _roleMap;
private String _forcedPath;
private String _runAsRole;
@ -81,7 +82,6 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
private ServletRegistration.Dynamic _registration;
private JspContainer _jspContainer;
private transient Servlet _servlet;
private transient Config _config;
private transient long _unavailable;
@ -396,21 +396,24 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
public void initialize ()
throws Exception
{
super.initialize();
if (_extInstance || _initOnStartup)
{
try
if(!_initialized){
super.initialize();
if (_extInstance || _initOnStartup)
{
initServlet();
}
catch(Exception e)
{
if (_servletHandler.isStartWithUnavailable())
LOG.ignore(e);
else
throw e;
try
{
initServlet();
}
catch(Exception e)
{
if (_servletHandler.isStartWithUnavailable())
LOG.ignore(e);
else
throw e;
}
}
}
_initialized = true;
}
@ -443,6 +446,7 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
_servlet=null;
_config=null;
_initialized = false;
}
/* ------------------------------------------------------------ */

View File

@ -530,6 +530,7 @@
<module>jetty-rewrite</module>
<module>jetty-nosql</module>
<module>jetty-infinispan</module>
<module>jetty-gcloud</module>
<module>tests</module>
<module>examples</module>
<module>jetty-quickstart</module>

View File

@ -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>

View File

@ -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>

View File

@ -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();
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();}
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -84,6 +84,7 @@ public abstract class AbstractInvalidationSessionTest
// 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");
@ -91,12 +92,14 @@ public abstract class AbstractInvalidationSessionTest
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();
// Be sure on node2 we don't see the session anymore