-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a066473
commit b11dad5
Showing
12 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/SendErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.google.apphosting.runtime.jetty9; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.TimeUnit; | ||
import org.eclipse.jetty.client.api.ContentResponse; | ||
import org.eclipse.jetty.client.api.Result; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.eclipse.jetty.client.HttpClient; | ||
|
||
|
||
@RunWith(Parameterized.class) | ||
public class SendErrorTest extends JavaRuntimeViaHttpBase { | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> parameters() { | ||
return Arrays.asList( | ||
new Object[][] { | ||
{"jetty94", false}, | ||
{"jetty94", true}, | ||
{"ee8", false}, | ||
{"ee8", true}, | ||
{"ee10", false}, | ||
{"ee10", true}, | ||
}); | ||
} | ||
|
||
@Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
private final HttpClient httpClient = new HttpClient(); | ||
private final boolean httpMode; | ||
private final String environment; | ||
private RuntimeContext<?> runtime; | ||
|
||
|
||
public SendErrorTest(String environment, boolean httpMode) { | ||
this.environment = environment; | ||
this.httpMode = httpMode; | ||
System.setProperty("appengine.use.HttpConnector", Boolean.toString(httpMode)); | ||
} | ||
|
||
@Before | ||
public void start() throws Exception { | ||
String app = "senderror" + environment; | ||
copyAppToDir(app, temp.getRoot().toPath()); | ||
runtime = runtimeContext(); | ||
System.err.println("==== Using Environment: " + environment + " " + httpMode + " ===="); | ||
} | ||
|
||
@After | ||
public void after() throws Exception { | ||
if (runtime != null) { | ||
runtime.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSendError() throws Exception { | ||
String url = runtime.jettyUrl("/senderror"); | ||
CompletableFuture<Result> completionListener = new CompletableFuture<>(); | ||
httpClient.newRequest(url).send(completionListener::complete); | ||
|
||
Result result = completionListener.get(5, TimeUnit.SECONDS); | ||
ContentResponse response = result.getRequest().send(); | ||
assertEquals(500, response.getStatus()); | ||
assertThat(response.getContentAsString(), containsString("Something went wrong.")); | ||
} | ||
|
||
private RuntimeContext<?> runtimeContext() throws Exception { | ||
RuntimeContext.Config<?> config = | ||
RuntimeContext.Config.builder().setApplicationPath(temp.getRoot().toString()).build(); | ||
return RuntimeContext.create(config); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/404.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>404</title> | ||
</head> | ||
<body> | ||
<p>You look lost.</p> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/500.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>500</title> | ||
</head> | ||
<body> | ||
<p>We encountered an error on our end. Sorry.</p> | ||
</body> | ||
</html> |
35 changes: 35 additions & 0 deletions
35
...pps/src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/SendErrorServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.google.apphosting.runtime.jetty9.senderrorapp; | ||
|
||
import java.io.IOException; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.annotation.WebServlet; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet("/send-error") | ||
public class SendErrorServlet extends HttpServlet { | ||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
int errorCode; | ||
if (req.getParameter("errorCode") == null) { | ||
errorCode = 0; | ||
} else { | ||
try { | ||
errorCode = Integer.parseInt(req.getParameter("errorCode")); | ||
} catch (NumberFormatException e) { | ||
errorCode = -1; | ||
} | ||
} | ||
switch (errorCode) { | ||
case -1: | ||
throw new RuntimeException("try to handle me"); | ||
case 0: | ||
req.getRequestDispatcher("/hello.html").forward(req, resp); | ||
break; | ||
default: | ||
resp.sendError(errorCode); | ||
break; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/hello.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Hello</title> | ||
</head> | ||
<body> | ||
<p>Hello.</p> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
...pps/src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/unhandled-error.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Unexpected Error</title> | ||
</head> | ||
<body> | ||
<p>This is embarrassing—we don't know what happened :(</p> | ||
</body> | ||
</html> |
16 changes: 16 additions & 0 deletions
16
...n/resources/com/google/apphosting/runtime/jetty9/senderroree10.WEB-INF/appengine-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
<module>default</module> | ||
<runtime>java21</runtime> | ||
<instance-class>B1</instance-class> | ||
<basic-scaling> | ||
<max-instances>1</max-instances> | ||
<idle-timeout>10m</idle-timeout> | ||
</basic-scaling> | ||
<static-files> | ||
<include path="/404.html"/> | ||
<include path="/500.html"/> | ||
<include path="/unhandled-error.html"/> | ||
<include path="/hello.html"/> | ||
</static-files> | ||
</appengine-web-app> |
32 changes: 32 additions & 0 deletions
32
...pps/src/main/resources/com/google/apphosting/runtime/jetty9/senderroree10.WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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_4_0.xsd" | ||
version="4.0"> | ||
<servlet> | ||
<servlet-name>SendErrorServlet</servlet-name> | ||
<servlet-class>com.google.apphosting.runtime.jetty9.senderrorapp</servlet-class> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>SendErrorServlet</servlet-name> | ||
<url-pattern>/senderror</url-pattern> | ||
</servlet-mapping> | ||
|
||
<error-page> | ||
<error-code>404</error-code> | ||
<location>/404.html</location> | ||
</error-page> | ||
<error-page> | ||
<error-code>500</error-code> | ||
<location>/500.html</location> | ||
</error-page> | ||
<error-page> | ||
<exception-type>java.lang.Throwable</exception-type> | ||
<location>/exception</location> | ||
</error-page> | ||
<error-page> | ||
<!-- No error-code or exception-type, i.e. this will match any other HTTP status than defined above --> | ||
<location>/unhandled-error.html</location> | ||
</error-page> | ||
</web-app> |
16 changes: 16 additions & 0 deletions
16
...in/resources/com/google/apphosting/runtime/jetty9/senderroree8.WEB-INF/appengine-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
<module>default</module> | ||
<runtime>java21</runtime> | ||
<instance-class>B1</instance-class> | ||
<basic-scaling> | ||
<max-instances>1</max-instances> | ||
<idle-timeout>10m</idle-timeout> | ||
</basic-scaling> | ||
<static-files> | ||
<include path="/404.html"/> | ||
<include path="/500.html"/> | ||
<include path="/unhandled-error.html"/> | ||
<include path="/hello.html"/> | ||
</static-files> | ||
</appengine-web-app> |
32 changes: 32 additions & 0 deletions
32
...apps/src/main/resources/com/google/apphosting/runtime/jetty9/senderroree8.WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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_4_0.xsd" | ||
version="4.0"> | ||
<servlet> | ||
<servlet-name>SendErrorServlet</servlet-name> | ||
<servlet-class>com.google.apphosting.runtime.jetty9.senderrorapp</servlet-class> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>SendErrorServlet</servlet-name> | ||
<url-pattern>/senderror</url-pattern> | ||
</servlet-mapping> | ||
|
||
<error-page> | ||
<error-code>404</error-code> | ||
<location>/404.html</location> | ||
</error-page> | ||
<error-page> | ||
<error-code>500</error-code> | ||
<location>/500.html</location> | ||
</error-page> | ||
<error-page> | ||
<exception-type>java.lang.Throwable</exception-type> | ||
<location>/exception</location> | ||
</error-page> | ||
<error-page> | ||
<!-- No error-code or exception-type, i.e. this will match any other HTTP status than defined above --> | ||
<location>/unhandled-error.html</location> | ||
</error-page> | ||
</web-app> |
16 changes: 16 additions & 0 deletions
16
...resources/com/google/apphosting/runtime/jetty9/senderrorjetty94.WEB-INF/appengine-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
<module>default</module> | ||
<runtime>java21</runtime> | ||
<instance-class>B1</instance-class> | ||
<basic-scaling> | ||
<max-instances>1</max-instances> | ||
<idle-timeout>10m</idle-timeout> | ||
</basic-scaling> | ||
<static-files> | ||
<include path="/404.html"/> | ||
<include path="/500.html"/> | ||
<include path="/unhandled-error.html"/> | ||
<include path="/hello.html"/> | ||
</static-files> | ||
</appengine-web-app> |
32 changes: 32 additions & 0 deletions
32
.../src/main/resources/com/google/apphosting/runtime/jetty9/senderrorjetty94.WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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_4_0.xsd" | ||
version="4.0"> | ||
<servlet> | ||
<servlet-name>SendErrorServlet</servlet-name> | ||
<servlet-class>com.google.apphosting.runtime.jetty9.senderrorapp</servlet-class> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>SendErrorServlet</servlet-name> | ||
<url-pattern>/senderror</url-pattern> | ||
</servlet-mapping> | ||
|
||
<error-page> | ||
<error-code>404</error-code> | ||
<location>/404.html</location> | ||
</error-page> | ||
<error-page> | ||
<error-code>500</error-code> | ||
<location>/500.html</location> | ||
</error-page> | ||
<error-page> | ||
<exception-type>java.lang.Throwable</exception-type> | ||
<location>/exception</location> | ||
</error-page> | ||
<error-page> | ||
<!-- No error-code or exception-type, i.e. this will match any other HTTP status than defined above --> | ||
<location>/unhandled-error.html</location> | ||
</error-page> | ||
</web-app> |