-
Notifications
You must be signed in to change notification settings - Fork 33
Issue #8 - (phase 1) script based war deployment and testing #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2016 Google Inc. All Rights Reserved. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<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>com.google.cloud.runtimes</groupId> | ||
<artifactId>jetty-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>com.google.cloud.runtimes.jetty.tests</groupId> | ||
<artifactId>tests-parent</artifactId> | ||
<name>Jetty :: Tests Parent</name> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>test-war-hello</module> | ||
</modules> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.toolchain</groupId> | ||
<artifactId>jetty-test-helper</artifactId> | ||
<version>4.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/docker</directory> | ||
<filtering>true</filtering> | ||
<targetPath>${project.build.directory}/docker</targetPath> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<configuration> | ||
<!-- | ||
Tests cannot and should not be validated with checkstyle. | ||
these tests need to be flexible enough for good, bad, quirky | ||
and everything in between with regards to compliance and | ||
validity. | ||
Having them pass checkstyle makes them invalid for integration | ||
test cases | ||
--> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>2.19.1</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-junit47</artifactId> | ||
<version>2.19.1</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.google.cloud.tools</groupId> | ||
<artifactId>appengine-maven-plugin</artifactId> | ||
<version>0.1.1-beta</version> | ||
<configuration> | ||
<dockerDirectory>${project.build.directory}/docker</dockerDirectory> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
function appengine_deploy() | ||
{ | ||
module="$1" | ||
|
||
pushd "${module}" | ||
|
||
mvn clean appengine:deploy verify \ | ||
-Dapp.deploy.project="${gcloud_projectid}" \ | ||
-Dapp.deploy.version="${test_runid}" \ | ||
-Dapp.deploy.promote=false | ||
|
||
ret=$? | ||
|
||
popd | ||
|
||
return ${ret} | ||
} | ||
|
||
gcloud info | ||
gcloud auth list | ||
|
||
gcloud_projectid=$(gcloud info | sed -rn 's/Project: \[(.*)\]/\1/p') | ||
test_runid=$(date +%Y%m%d-%H%M%S) | ||
|
||
echo "GCloud Project: $gcloud_projectid" | ||
|
||
# Push the as-built jetty9:latest to gcr.io/${gcloud_projectid}/jetty9:testing" | ||
|
||
docker tag "jetty9:latest" "gcr.io/${gcloud_projectid}/jetty9:testing" | ||
gcloud docker push "gcr.io/${gcloud_projectid}/jetty9:testing" | ||
|
||
# Deploy and Execute the individual test-war-* tests | ||
|
||
for module in test-war-* | ||
do | ||
echo "module: $module" | ||
appengine_deploy "${module}" | ||
done | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to remove the deployed version after the tests have run.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. Do you know how to create an machine/instance (or whatever the correct name is) with a specific environment configurations? (like say 2GB or 5GB for the webapp?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible to tweak the VMs via some settings in app.yaml. See docs. Is that what you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try the resources:
cpu: .5
memory_gb: 1.3
disk_size_gb: 10 This would be good for testing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, though if you just wanted to test that the jetty runtime obeys the I don't think we need to worry about testing that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that we don't need to verify the value of GAE_MEMORY_MB because that may change. We just want to make sure that it is set, and that we are assigning 80% of it to JVM heap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point is, we need to test the environment behavior as well. If we deploy in flex or not, the behavior is different, and is dependent on the memory_gb setting, so having at least the 4 different memory configurations is a good thing to test and ensure that we dont have a regression (which is the root goal of this issue and initial PR) |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<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>com.google.cloud.runtimes.jetty.tests</groupId> | ||
<artifactId>tests-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>test-war-hello</artifactId> | ||
<packaging>war</packaging> | ||
<name>Jetty-Runtime :: Tests :: Hello (Servlet 3.1) WebApp</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.toolchain</groupId> | ||
<artifactId>jetty-test-helper</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>1.8</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<phase>package</phase> | ||
<configuration> | ||
<target> | ||
<unjar src="${project.build.directory}/${project.build.finalName}.war" | ||
dest="${project.build.directory}/docker/root"/> | ||
</target> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
runtime: custom | ||
vm: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM gcr.io/${app.deploy.project}/jetty9:testing | ||
ADD root /app |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.google.cloud.runtimes.jetty.tests; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet(urlPatterns = {"/hello/*"}) | ||
public class HelloServlet extends HttpServlet | ||
{ | ||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException | ||
{ | ||
resp.setContentType("text/plain"); | ||
resp.getWriter().println("Hello from Servlet 3.1"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee | ||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
version="3.1"> | ||
<display-name>Web Application for Servlet 3.1</display-name> | ||
</web-app> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.google.cloud.runtimes.jetty.tests; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.StringWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.URI; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.jetty.toolchain.test.IO; | ||
import org.junit.Test; | ||
|
||
public class DeploymentITCase | ||
{ | ||
private static final URI serverURI; | ||
|
||
static | ||
{ | ||
String projectId = System.getProperty("app.deploy.project"); | ||
String version = System.getProperty("app.deploy.version"); | ||
|
||
Objects.requireNonNull(projectId, "app.deploy.project"); | ||
Objects.requireNonNull(version, "app.deploy.version"); | ||
|
||
serverURI = URI.create(String.format("https://%s-dot-%s.appspot.com/", version, projectId)); | ||
} | ||
|
||
private String getResponseBody(HttpURLConnection http) throws IOException | ||
{ | ||
Charset responseEncoding = StandardCharsets.UTF_8; | ||
if (http.getContentEncoding() != null) | ||
{ | ||
responseEncoding = Charset.forName(http.getContentEncoding()); | ||
} | ||
|
||
try (InputStream in = http.getInputStream(); | ||
InputStreamReader reader = new InputStreamReader(in, responseEncoding); | ||
StringWriter writer = new StringWriter()) | ||
{ | ||
IO.copy(reader, writer); | ||
return writer.toString(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGet() throws IOException | ||
{ | ||
HttpURLConnection http = (HttpURLConnection) serverURI.resolve("/hello/").toURL().openConnection(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you envision that all test webapps will implement all the same routes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a P.o.C. I plan on using maven for it all (no shell scripts), and the integration-testing phase across each test-webapp, and will share a common testing core. |
||
assertThat(http.getResponseCode(), is(200)); | ||
|
||
String responseBody = getResponseBody(http); | ||
assertThat(responseBody, containsString("Hello from Servlet 3.1")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest version is 0.1.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will be a separate PR for issue #22