Create module and being gcloud datastore session tests
This commit is contained in:
parent
dd2268dd67
commit
e5b5bea259
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.gcloud</groupId>
|
||||
<artifactId>gcloud-parent</artifactId>
|
||||
<version>9.3.3-SNAPSHOT</version>
|
||||
<version>9.3.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -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">
|
||||
<Args>
|
||||
<Arg><Property name="jetty.base" default="."/>/<Property name="jetty.gcloudSession.configFile" default="etc/gcloud.props"/></Arg>
|
||||
</Args>
|
||||
</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 refid="Server"/>
|
||||
</Arg>
|
||||
<Set name="workerName"><Property name="jetty.gcloudSession.workerName" default="node1"/></Set>
|
||||
<Set name="config"><Ref refid="gconf"/></Set>
|
||||
</New>
|
||||
</Set>
|
||||
|
||||
</Configure>
|
|
@ -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/RELEASE|lib/gcloud/joda-time-RELEASE.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=
|
|
@ -56,7 +56,7 @@ public class GCloudSessionTester
|
|||
|
||||
WebAppContext webapp = new WebAppContext();
|
||||
webapp.setContextPath("/");
|
||||
webapp.setResourceBase("../../jetty-distribution/target/distribution/demo-base/webapps/test/");
|
||||
webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
|
||||
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
|
||||
GCloudSessionManager mgr = new GCloudSessionManager();
|
||||
mgr.setSessionIdManager(idmgr);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<version>9.3.3-SNAPSHOT</version>
|
||||
<version>9.3.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -13,7 +13,7 @@
|
|||
<name>Jetty :: GCloud</name>
|
||||
|
||||
<properties>
|
||||
<gcloud.version>0.0.6</gcloud.version>
|
||||
<gcloud.version>0.0.7</gcloud.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,290 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.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.nio.file.Path;
|
||||
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.DatastoreOptions;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
System.err.println("SENTINEL FOUND");
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
for (String s:processBuilder.command())
|
||||
System.err.println(s);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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;
|
||||
|
||||
/**
|
||||
* GCloudTestServer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class GCloudTestServer extends AbstractTestServer
|
||||
{
|
||||
static int __workers=0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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(1);
|
||||
sessionManager.setScavengeInterval(_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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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.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()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
super.testRemoveSession();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSessionExpiry() throws Exception
|
||||
{
|
||||
super.testSessionExpiry();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue