Skip to content

Commit

Permalink
Issue #8 - alternate /tests/ setup for 100% maven
Browse files Browse the repository at this point in the history
+ Deploys jetty9:testing (tagged) image in /jetty9/
  module during integration-test phase
+ Adds /tests/
+ Adds /tests/webapps/
+ Adds /tests/gcloud-testing-core/ for common testing lib
  • Loading branch information
joakime committed Sep 29, 2016
1 parent 8500b2e commit 3b7760a
Show file tree
Hide file tree
Showing 16 changed files with 812 additions and 8 deletions.
74 changes: 66 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyy-MM-dd_HH_mm</maven.build.timestamp.format>
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
<appengine.api.version>1.9.40</appengine.api.version>
<jetty9.minor.version>3</jetty9.minor.version>
<jetty9.dot.version>8</jetty9.dot.version>
Expand All @@ -42,6 +42,7 @@
<docker.tag.long>${docker.tag.prefix}9.${jetty9.minor.version}-${maven.build.timestamp}</docker.tag.long>

<docker.openjdk.image>openjdk:8</docker.openjdk.image>
<gcloud-projectId-file>${project.build.directory}/gcloud-projectid.properties</gcloud-projectId-file>
</properties>

<developers>
Expand Down Expand Up @@ -85,6 +86,7 @@
<modules>
<module>jetty9-base</module>
<module>jetty9</module>
<module>tests</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -137,7 +139,7 @@
<version>2.10</version>
</plugin>

<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
Expand Down Expand Up @@ -168,9 +170,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>

<plugin>
Expand Down Expand Up @@ -257,9 +259,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -305,5 +307,61 @@
</plugins>
</build>
</profile>
<profile>
<id>get-gcloud-project-id</id>
<activation>
<property>
<name>!app.deploy.project</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>find-app-deploy-project</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo file="${gcloud-projectId-file}" append="false">app.deploy.project=</echo>
<exec executable="gcloud" logError="true" append="true" output="${gcloud-projectId-file}">
<arg value="--quiet"/>
<arg value="config"/>
<arg value="list"/>
<arg value="--format=value(core.project)"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>read-gcloud-properties</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${gcloud-projectId-file}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
49 changes: 49 additions & 0 deletions tests/gcloud-testing-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<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>gcloud-testing-core</artifactId>
<name>Jetty-Runtime :: Testing Core Lib</name>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
</dependency>
<!--
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>0.3.0</version>
</dependency>
-->
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<version>4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.google.cloud.runtime.jetty.testing;

import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.yaml.snakeyaml.Yaml;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Objects;

public final class AppDeployment {
public static final String PROJECT_ID;
public static final String VERSION_ID;
public static final String MODULE_ID;
public static final URI SERVER_URI;

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");

PROJECT_ID = projectId;
VERSION_ID = version;

String moduleId = null;

Path appYamlPath = MavenTestingUtils.getProjectFilePath("src/main/appengine/app.yaml");
if (Files.exists(appYamlPath)) {
try (BufferedReader reader = Files.newBufferedReader(appYamlPath, StandardCharsets.UTF_8)) {
Yaml yaml = new Yaml();
Map map = (Map) yaml.load(reader);
moduleId = (String) map.get("module");
} catch (IOException e) {
throw new RuntimeException("Unable to parse app.yaml", e);
}
}

MODULE_ID = moduleId;

StringBuilder uri = new StringBuilder();
uri.append("https://");
uri.append(version).append("-dot-");
if (moduleId != null) {
uri.append(moduleId).append("-dot-");
}
uri.append(projectId);
uri.append(".appspot.com/");

SERVER_URI = URI.create(uri.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.google.cloud.runtime.jetty.testing;

import org.eclipse.jetty.toolchain.test.IO;

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;

public final class HttpURLUtil {
/**
* Open a new {@link HttpURLConnection} to the provided URI.
*
* <p>
* Note: will also set the 'User-Agent' to {@code jetty-runtime/gcloud-testing-core}
* </p>
*
* @param uri the URI to open to
* @return the open HttpURLConnection
* @throws IOException if unable to open the connection
*/
public static HttpURLConnection openTo(URI uri) throws IOException {
HttpURLConnection http = (HttpURLConnection) uri.toURL().openConnection();
http.setRequestProperty("User-Agent", "jetty-runtime/gcloud-testing-core");
return http;
}

/**
* Obtain the text (non-binary) response body from an {@link HttpURLConnection},
* using the response provided charset.
*
* <p>
* Note: Normal HttpURLConnection doesn't use the provided charset properly.
* </p>
*
* @param http the {@link HttpURLConnection} to obtain the response body from
* @return the text of the response body
* @throws IOException if unable to get the text of the response body
*/
public static 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.google.cloud.runtime.jetty.testing;

import org.eclipse.jetty.toolchain.test.IO;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
* Utilities for executing and collecting output from command line processes.
*/
public final class ProcessUtil {
private static final ExecutorService executor = Executors.newFixedThreadPool(5);

/**
* Execute a command line.
* <p>
* Report output from command line to Writer
* </p>
*
* @param output where to put the output from the execution of the command line
* @param args the command line arguments
* @return the exit code from the execution
*/
public static int exec(OutputStream output, String... args)
throws IOException, InterruptedException, ExecutionException {
System.out.printf("exec(%s)%n", Arrays.toString(args));
Process process = Runtime.getRuntime().exec(args);

InputStream in = process.getInputStream();

Future<Void> fut = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
IO.copy(in, output);
return null;
}
});

fut.get();

return process.waitFor();
}
}
Loading

0 comments on commit 3b7760a

Please sign in to comment.