diff --git a/VERSION.txt b/VERSION.txt index 6c459582201..84878d80d47 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,5 +1,12 @@ jetty-9.4.0-SNAPSHOT +jetty-9.3.5.v20151012 - 12 October 2015 + + 479343 calls to MetaData#orderFragments() with relative ordering adds + duplicate jars + + 479537 Server preface sent after client preface reply. + + 479584 WS Session does not contain UpgradeRequest information in + WebSocketAdapter.onWebSocketConnect callback + jetty-9.3.4.v20151007 - 07 October 2015 + 428474 Expose batch mode in the Jetty WebSocket API + 472082 isOpen returns true on CLOSING Connection diff --git a/jetty-gcloud/gcloud-session-manager/src/main/config/etc/jetty-gcloud-sessions.xml b/jetty-gcloud/gcloud-session-manager/src/main/config/etc/jetty-gcloud-sessions.xml index 75caeb1f9ef..72f9da6a513 100644 --- a/jetty-gcloud/gcloud-session-manager/src/main/config/etc/jetty-gcloud-sessions.xml +++ b/jetty-gcloud/gcloud-session-manager/src/main/config/etc/jetty-gcloud-sessions.xml @@ -4,27 +4,18 @@ - - + + - - / - - - - - - - - + ---> diff --git a/jetty-gcloud/gcloud-session-manager/src/main/config/modules/gcloud-sessions.mod b/jetty-gcloud/gcloud-session-manager/src/main/config/modules/gcloud-sessions.mod index df1a13e6552..0780a60ba91 100644 --- a/jetty-gcloud/gcloud-session-manager/src/main/config/modules/gcloud-sessions.mod +++ b/jetty-gcloud/gcloud-session-manager/src/main/config/modules/gcloud-sessions.mod @@ -53,23 +53,39 @@ 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 +## GCloudDatastore Session config +## If running inside Google cloud all configuration is provided by +## environment variables and you do not need to set anything in this file. +## +## If running externally to Google: +## To contact the remote gcloud datastore: +## 1. set the DATASTORE_DATASET System property/environment variable to the name of your project +## or alternatively set the jetty.gcloudSession.projectId property below. +## 2. set the jetty.gcloudSession.p12File, jetty.gcloudSession.serviceAccount and +## jetty.gcloudSession.password (supports obfuscation) below. +## +## To contact a local dev gcloud datastore server: +## 1. set the DATASTORE_DATASET System property/environment variable to the name of your project. +## 2. set the DATASTORE_HOST System property/environment variable to the url of the dev server +## as described at https://cloud.google.com/datastore/docs/tools/devserver#setting_environment_variables + +## The gcloud projectId +## Set this property to connect to remote gcloud datastore. +## Or, set the DATASTORE_DATASET System property/env variable instead. #jetty.gcloudSession.projectId= -## the p12 file associated with the project +## The p12 file associated with the project. +## Set this property to connect to remote gcloud datastore #jetty.gcloudSession.p12File= -## the serviceAccount for the Datastore +## The serviceAccount for the Datastore. +## Set this property to connect to to remote gcloud datastore #jetty.gcloudSession.serviceAccount= -## the password (can be obfuscated) +## The password (can be obfuscated). +## Set this property to connect to remote gcloud datastore #jetty.gcloudSession.password= diff --git a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudConfiguration.java b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudConfiguration.java index c1a95961d47..3ce4acb47d1 100644 --- a/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudConfiguration.java +++ b/jetty-gcloud/gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudConfiguration.java @@ -46,8 +46,10 @@ public class GCloudConfiguration public static final String SERVICE_ACCOUNT = "serviceAccount"; private String _projectId; + private String _p12Filename; private File _p12File; private String _serviceAccount; + private String _passwordSet; private String _password; private AuthCredentials _authCredentials; private DatastoreOptions _options; @@ -109,7 +111,8 @@ public class GCloudConfiguration public void setP12File (String file) { checkForModification(); - _p12File = new File(file); + _p12Filename = file; + } @@ -119,12 +122,12 @@ public class GCloudConfiguration _serviceAccount = serviceAccount; } - + public void setPassword (String pwd) { checkForModification(); - Password p = new Password(pwd); - _password = p.toString(); + _passwordSet = pwd; + } @@ -133,10 +136,29 @@ public class GCloudConfiguration { if (_options == null) { - _options = DatastoreOptions.builder() - .projectId(_projectId) - .authCredentials(getAuthCredentials()) - .build(); + if (_passwordSet == null && _p12Filename == null && _serviceAccount == null) + { + //When no values are explicitly presented for auth info, we are either running + //1. inside GCE environment, in which case all auth info is derived from the environment + //2. outside the GCE environment, but using a local gce dev server, in which case you + // need to set the following 2 environment/system properties + // DATASTORE_HOST: eg http://localhost:9999 - this is the host and port of a local development server + // DATASTORE_DATASET: eg myProj - this is the name of your project + _options = DatastoreOptions.defaultInstance(); + } + else + { + //When running externally to GCE, you need to provide + //explicit auth info. You can either set the projectId explicitly, or you can set the + //DATASTORE_DATASET env/system property + _p12File = new File(_p12Filename); + Password p = new Password(_passwordSet); + _password = p.toString(); + _options = DatastoreOptions.builder() + .projectId(_projectId) + .authCredentials(getAuthCredentials()) + .build(); + } } return _options; } @@ -152,11 +174,6 @@ public class GCloudConfiguration { 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())); diff --git a/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java b/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java index f0388955387..6256a6d2c40 100644 --- a/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java +++ b/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java @@ -26,13 +26,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; import org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory; -import org.eclipse.jetty.http2.ErrorCode; -import org.eclipse.jetty.http2.ISession; import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ClientConnectionFactory; @@ -43,7 +39,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.io.ssl.SslClientConnectionFactory; -import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -117,7 +112,6 @@ public class HTTP2Client extends ContainerLifeCycle private Scheduler scheduler; private ByteBufferPool bufferPool; private ClientConnectionFactory connectionFactory; - private Queue sessions; private SelectorManager selector; private int selectors = 1; private long idleTimeout = 30000; @@ -150,12 +144,6 @@ public class HTTP2Client extends ContainerLifeCycle }); } - if (sessions == null) - { - sessions = new ConcurrentLinkedQueue<>(); - addBean(sessions); - } - if (selector == null) { selector = newSelectorManager(); @@ -171,13 +159,6 @@ public class HTTP2Client extends ContainerLifeCycle return new ClientSelectorManager(getExecutor(), getScheduler(), getSelectors()); } - @Override - protected void doStop() throws Exception - { - closeConnections(); - super.doStop(); - } - public Executor getExecutor() { return executor; @@ -329,23 +310,6 @@ public class HTTP2Client extends ContainerLifeCycle channel.socket().setTcpNoDelay(true); } - private void closeConnections() - { - for (ISession session : sessions) - session.close(ErrorCode.NO_ERROR.code, null, Callback.NOOP); - sessions.clear(); - } - - public boolean addSession(ISession session) - { - return sessions.offer(session); - } - - public boolean removeSession(ISession session) - { - return sessions.remove(session); - } - private class ClientSelectorManager extends SelectorManager { private ClientSelectorManager(Executor executor, Scheduler scheduler, int selectors) diff --git a/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java b/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java index e630517d9a0..eda74e35c2d 100644 --- a/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java +++ b/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java @@ -125,17 +125,9 @@ public class HTTP2ClientConnectionFactory implements ClientConnectionFactory super.onOpen(); } - @Override - public void onClose() - { - super.onClose(); - client.removeSession(getSession()); - } - @Override public void succeeded() { - client.addSession(getSession()); promise.succeeded(getSession()); } diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/HTTP2Test.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/HTTP2Test.java index 4cf327a7311..03ad6b23c60 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/HTTP2Test.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/HTTP2Test.java @@ -37,7 +37,9 @@ import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.http2.api.Stream; +import org.eclipse.jetty.http2.api.server.ServerSessionListener; import org.eclipse.jetty.http2.frames.DataFrame; +import org.eclipse.jetty.http2.frames.GoAwayFrame; import org.eclipse.jetty.http2.frames.HeadersFrame; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Jetty; @@ -239,4 +241,48 @@ public class HTTP2Test extends AbstractTest Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); } + + @Test + public void testServerSendsGoAwayOnStop() throws Exception + { + start(new ServerSessionListener.Adapter()); + + CountDownLatch closeLatch = new CountDownLatch(1); + newClient(new Session.Listener.Adapter() + { + @Override + public void onClose(Session session, GoAwayFrame frame) + { + closeLatch.countDown(); + } + }); + + Thread.sleep(1000); + + server.stop(); + + Assert.assertTrue(closeLatch.await(5, TimeUnit.SECONDS)); + } + + @Test + public void testClientSendsGoAwayOnStop() throws Exception + { + CountDownLatch closeLatch = new CountDownLatch(1); + start(new ServerSessionListener.Adapter() + { + @Override + public void onClose(Session session, GoAwayFrame frame) + { + closeLatch.countDown(); + } + }); + + newClient(new Session.Listener.Adapter()); + + Thread.sleep(1000); + + client.stop(); + + Assert.assertTrue(closeLatch.await(5, TimeUnit.SECONDS)); + } } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java index 5b9c8f773a4..48d5d9ce3ae 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.ConcurrentArrayQueue; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -129,6 +130,14 @@ public class HTTP2Connection extends AbstractConnection executionStrategy.execute(); } + @Override + public void close() + { + // We don't call super from here, otherwise we close the + // endPoint and we're not able to read or write anymore. + session.close(ErrorCode.NO_ERROR.code, "close", Callback.NOOP); + } + protected class HTTP2Producer implements ExecutionStrategy.Producer { private ByteBuffer buffer; diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index ab4eb5f2392..17b6e0bbafd 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -537,8 +537,6 @@ public abstract class HTTP2Session implements ISession, Parser.Listener { byte[] payload = reason == null ? null : reason.getBytes(StandardCharsets.UTF_8); GoAwayFrame frame = new GoAwayFrame(lastStreamId.get(), error, payload); - if (LOG.isDebugEnabled()) - LOG.debug("Sending {}", frame); control(null, callback, frame); return true; } diff --git a/jetty-runner/pom.xml b/jetty-runner/pom.xml index c7eb427888e..caae6234d8a 100644 --- a/jetty-runner/pom.xml +++ b/jetty-runner/pom.xml @@ -37,33 +37,33 @@ - org.apache.felix - maven-bundle-plugin - true - - - bundle-manifest - process-classes - - manifest - - - - - - org.eclipse.jetty.runner.Runner - !* - - - - + org.apache.felix + maven-bundle-plugin + true + + + bundle-manifest + process-classes + + manifest + + + + + + org.eclipse.jetty.runner.Runner + !* + + + + org.apache.maven.plugins maven-jar-plugin - + ${project.build.outputDirectory}/META-INF/MANIFEST.MF - + diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 731ca71a382..134bd109bc4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -212,7 +212,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http public void onFillable() { if (LOG.isDebugEnabled()) - LOG.debug("{} onFillable enter {}", this, _channel.getState()); + LOG.debug("{} onFillable enter {} {}", this, _channel.getState(),BufferUtil.toDetailString(_requestBuffer)); HttpConnection last=setCurrentConnection(this); try @@ -259,7 +259,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http { setCurrentConnection(last); if (LOG.isDebugEnabled()) - LOG.debug("{} onFillable exit {}", this, _channel.getState()); + LOG.debug("{} onFillable exit {} {}", this, _channel.getState(),BufferUtil.toDetailString(_requestBuffer)); } } @@ -272,8 +272,6 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http boolean handled=false; while (_parser.inContentState()) { - if (LOG.isDebugEnabled()) - LOG.debug("{} parseContent",this); int filled = fillRequestBuffer(); boolean handle = parseRequestBuffer(); handled|=handle; @@ -300,7 +298,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http // No pretend we read -1 _parser.atEOF(); if (LOG.isDebugEnabled()) - LOG.debug("{} filled -1",this); + LOG.debug("{} filled -1 {}",this,BufferUtil.toDetailString(_requestBuffer)); return -1; } @@ -321,7 +319,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http _parser.atEOF(); if (LOG.isDebugEnabled()) - LOG.debug("{} filled {}",this,filled); + LOG.debug("{} filled {} {}",this,filled,BufferUtil.toDetailString(_requestBuffer)); return filled; } @@ -559,8 +557,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http super.toString(), _parser, _generator, - _channel, - BufferUtil.toDetailString(_requestBuffer)); + _channel); } private class Content extends HttpInput.Content diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java index 6e5c85b4e92..49377144e13 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java @@ -32,6 +32,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.resource.Resource; @@ -1027,38 +1028,46 @@ public class BufferUtil private static void appendDebugString(StringBuilder buf,ByteBuffer buffer) { - for (int i = 0; i < buffer.position(); i++) + try { - appendContentChar(buf,buffer.get(i)); - if (i == 16 && buffer.position() > 32) + for (int i = 0; i < buffer.position(); i++) { - buf.append("..."); - i = buffer.position() - 16; + appendContentChar(buf,buffer.get(i)); + if (i == 16 && buffer.position() > 32) + { + buf.append("..."); + i = buffer.position() - 16; + } } + buf.append("<<<"); + for (int i = buffer.position(); i < buffer.limit(); i++) + { + appendContentChar(buf,buffer.get(i)); + if (i == buffer.position() + 16 && buffer.limit() > buffer.position() + 32) + { + buf.append("..."); + i = buffer.limit() - 16; + } + } + buf.append(">>>"); + int limit = buffer.limit(); + buffer.limit(buffer.capacity()); + for (int i = limit; i < buffer.capacity(); i++) + { + appendContentChar(buf,buffer.get(i)); + if (i == limit + 16 && buffer.capacity() > limit + 32) + { + buf.append("..."); + i = buffer.capacity() - 16; + } + } + buffer.limit(limit); } - buf.append("<<<"); - for (int i = buffer.position(); i < buffer.limit(); i++) + catch(Throwable x) { - appendContentChar(buf,buffer.get(i)); - if (i == buffer.position() + 16 && buffer.limit() > buffer.position() + 32) - { - buf.append("..."); - i = buffer.limit() - 16; - } + Log.getRootLogger().ignore(x); + buf.append("!!concurrent mod!!"); } - buf.append(">>>"); - int limit = buffer.limit(); - buffer.limit(buffer.capacity()); - for (int i = limit; i < buffer.capacity(); i++) - { - appendContentChar(buf,buffer.get(i)); - if (i == limit + 16 && buffer.capacity() > limit + 32) - { - buf.append("..."); - i = buffer.capacity() - 16; - } - } - buffer.limit(limit); } private static void appendContentChar(StringBuilder buf, byte b) diff --git a/tests/test-sessions/test-gcloud-sessions/pom.xml b/tests/test-sessions/test-gcloud-sessions/pom.xml index 1c487b7f3bc..6d14ea6f50b 100644 --- a/tests/test-sessions/test-gcloud-sessions/pom.xml +++ b/tests/test-sessions/test-gcloud-sessions/pom.xml @@ -21,7 +21,7 @@ org.eclipse.jetty.tests test-sessions-parent - 9.3.4-SNAPSHOT + 9.3.6-SNAPSHOT test-gcloud-sessions Jetty Tests :: Sessions :: GCloud @@ -97,8 +97,8 @@ false - jetty9-work - 8088 + jetty9-work + http://localhost:8088 diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java index 5d05a3f698e..4c463084248 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ClientCrossContextSessionTest.java @@ -37,11 +37,7 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java index 20109ae51fe..c4b06358e52 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ForwardedSessionTest.java @@ -36,11 +36,7 @@ public class ForwardedSessionTest extends AbstractForwardedSessionTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java index adfdf9b7a59..f30996be174 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java @@ -38,18 +38,16 @@ 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.Key; import com.google.gcloud.datastore.ProjectionEntity; import com.google.gcloud.datastore.Query; import com.google.gcloud.datastore.Query.ResultType; @@ -65,34 +63,6 @@ import com.google.gcloud.datastore.StructuredQuery.Projection; 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; @@ -138,40 +108,55 @@ public class GCloudSessionTestSupport public static String DEFAULT_PROJECTID = "jetty9-work"; - public static int DEFAULT_PORT = 8088; + public static String DEFAULT_PORT = "8088"; + public static String DEFAULT_HOST = "http://localhost:"+DEFAULT_PORT; 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; + String _testServerUrl; + String _testPort; File _datastoreDir; File _gcdInstallDir; File _gcdUnpackedDir; Datastore _ds; - public GCloudSessionTestSupport (String projectId, int port, File gcdInstallDir) + public GCloudSessionTestSupport (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")); + + _projectId = System.getProperty("DATASTORE_DATASET", System.getenv("DATASTORE_DATASET")); + if (_projectId == null) + { + _projectId = DEFAULT_PROJECTID; + System.setProperty("DATASTORE_DATASET", _projectId); + } + _testServerUrl = System.getProperty("DATASTORE_HOST", System.getenv("DATASTORE_HOST")); + if (_testServerUrl == null) + { + _testServerUrl = DEFAULT_HOST; + _testPort = DEFAULT_PORT; + System.setProperty("DATASTORE_HOST", _testServerUrl); + } + else + { + int i = _testServerUrl.lastIndexOf(':'); + _testPort = _testServerUrl.substring(i+1); + } } public GCloudSessionTestSupport () { - this(null,0, null); + this(null); } public GCloudConfiguration getConfiguration () { - return new GCloudTestConfiguration(_projectId, _port); + return new GCloudConfiguration(); } @@ -251,11 +236,11 @@ public class GCloudSessionTestSupport 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); + processBuilder.command("cmd", "/C", new File(_gcdUnpackedDir, "gcd.cmd").getAbsolutePath(), "start", "--testing", "--allow_remote_shutdown","--port="+_testPort, _projectId); } else { - processBuilder.command("bash", new File(_gcdUnpackedDir, "gcd.sh").getAbsolutePath(), "start", "--testing", "--allow_remote_shutdown", "--port="+String.valueOf(_port), _projectId); + processBuilder.command("bash", new File(_gcdUnpackedDir, "gcd.sh").getAbsolutePath(), "start", "--testing", "--allow_remote_shutdown", "--port="+_testPort, _projectId); } System.err.println("Starting datastore"); @@ -270,7 +255,7 @@ public class GCloudSessionTestSupport throws Exception { //Send request to terminate test datastore - URL url = new URL("http", "localhost", _port, "/_ah/admin/quit"); + URL url = new URL("http", "localhost", Integer.parseInt(_testPort.trim()), "/_ah/admin/quit"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java index 84c3840d21e..54e983eba6f 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ImmortalSessionTest.java @@ -34,14 +34,13 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest { static GCloudSessionTestSupport _testSupport; + /** + * @throws Exception + */ @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java index 6cc875cb71f..81be68ce6af 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/InvalidationSessionTest.java @@ -36,11 +36,7 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java index d4f42fe78de..299278aa24e 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LastAccessTimeTest.java @@ -37,11 +37,7 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java index ca39661a309..bcdfa0aed45 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/LocalSessionScavengingTest.java @@ -37,11 +37,7 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java index 1dc256b74b1..68db7ff50c7 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/NewSessionTest.java @@ -42,11 +42,7 @@ public class NewSessionTest extends AbstractNewSessionTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java index ffaaaec0da3..bb3f51b228f 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/OrphanedSessionTest.java @@ -37,11 +37,7 @@ public class OrphanedSessionTest extends AbstractOrphanedSessionTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java index e8216187a57..9cfa9f67415 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ReentrantRequestSessionTest.java @@ -37,11 +37,7 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java index 5b7f99b3d93..ca45cb9423e 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/RemoveSessionTest.java @@ -39,11 +39,7 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java index e230f43d67a..70ac90b8d86 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SameNodeLoadTest.java @@ -37,11 +37,7 @@ public class SameNodeLoadTest extends AbstractSameNodeLoadTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java index 59f366b6c73..7f8d73ec20f 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/ServerCrossContextSessionTest.java @@ -38,11 +38,7 @@ public class ServerCrossContextSessionTest extends AbstractServerCrossContextSes @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java index 785a2a19ec7..ec2a9e0cb33 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionExpiryTest.java @@ -40,11 +40,7 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java index b56a13ea547..8222ed4386f 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionInvalidateAndCreateTest.java @@ -38,11 +38,7 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java index 5ed5740746b..7d8bc6521c0 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionMigrationTest.java @@ -37,11 +37,7 @@ public class SessionMigrationTest extends AbstractSessionMigrationTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java index c7b0c878bd5..01d9a4b490b 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionRenewTest.java @@ -37,11 +37,7 @@ public class SessionRenewTest extends AbstractSessionRenewTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java index 54bf8ffac4d..9bbee076728 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/SessionValueSavingTest.java @@ -38,11 +38,7 @@ public class SessionValueSavingTest extends AbstractSessionValueSavingTest @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); } diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java index 97b656fbd20..0b811d9e8b8 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/StopSessionManagerPreserveSessionTest.java @@ -39,11 +39,7 @@ public class StopSessionManagerPreserveSessionTest extends AbstractStopSessionMa @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 = new GCloudSessionTestSupport(); _testSupport.setUp(); }