-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Lambda and remote container packaging
- Loading branch information
Showing
8 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
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,125 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-integration-tests-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-integration-test-awt-packaging</artifactId> | ||
<name>Quarkus - Integration Tests - AWT Packaging</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jaxb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-awt</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-amazon-lambda</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-mockito</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-test-amazon-lambda</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jaxb-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-awt-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-amazon-lambda-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
integration-tests/awt-packaging/src/main/java/io/quarkus/it/jaxb/Book.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,36 @@ | ||
package io.quarkus.it.jaxb; | ||
|
||
import java.awt.Image; | ||
|
||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement | ||
public class Book { | ||
|
||
private String title; | ||
private Image cover; | ||
|
||
public Book() { | ||
} | ||
|
||
public Book(String title, Image cover) { | ||
this.title = title; | ||
this.cover = cover; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public Image getCover() { | ||
return cover; | ||
} | ||
|
||
public void setCover(Image cover) { | ||
this.cover = cover; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
integration-tests/awt-packaging/src/main/java/io/quarkus/it/jaxb/Lambda.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,31 @@ | ||
package io.quarkus.it.jaxb; | ||
|
||
import java.io.StringReader; | ||
|
||
import jakarta.inject.Named; | ||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBException; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
|
||
@Named("test") | ||
public class Lambda implements RequestHandler<String, String> { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(Lambda.class); | ||
|
||
@Override | ||
public String handleRequest(String input, Context context) { | ||
try { | ||
final JAXBContext jaxbContext = JAXBContext.newInstance(Book.class); | ||
final Book book = (Book) jaxbContext.createUnmarshaller().unmarshal(new StringReader(input)); | ||
return String.valueOf(book.getCover().getHeight(null)); | ||
} catch (JAXBException e) { | ||
context.getLogger().log("Error: " + e.getMessage()); | ||
LOGGER.error(e); | ||
} | ||
return null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
integration-tests/awt-packaging/src/main/java/io/quarkus/it/jaxb/Resource.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,33 @@ | ||
package io.quarkus.it.jaxb; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
@Path("/jaxb") | ||
@ApplicationScoped | ||
public class Resource { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(Resource.class); | ||
|
||
@Path("/book") | ||
@POST | ||
@Consumes(MediaType.APPLICATION_XML) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Response postBook(Book book) { | ||
LOGGER.info("Received book: " + book); | ||
try { | ||
return Response.accepted().entity(book.getCover().getHeight(null)).build(); | ||
} catch (Exception e) { | ||
LOGGER.error(e); | ||
return Response.serverError().entity(e.getMessage()).build(); | ||
} | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
integration-tests/awt-packaging/src/main/resources/application.properties
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,2 @@ | ||
quarkus.lambda.handler=true | ||
quarkus.native.remote-container-build=true |
50 changes: 50 additions & 0 deletions
50
integration-tests/awt-packaging/src/test/java/io/quarkus/it/jaxb/AwtJaxbTest.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,50 @@ | ||
package io.quarkus.it.jaxb; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static jakarta.ws.rs.core.MediaType.APPLICATION_XML; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.amazon.lambda.test.LambdaClient; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class AwtJaxbTest { | ||
|
||
public static final String BOOK_WITH_IMAGE = "<book>" + | ||
"<cover>iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAIElEQVR4XmNgGCngPxSgi6MAZAU4FeOUQAdEKwQBdKsBOgof4SXid6kAAAAASUVORK5CYII=</cover>" | ||
+ | ||
"<title>Foundation</title>" + | ||
"</book>"; | ||
|
||
/** | ||
* Smoke tests that we have .so files | ||
* copied over from the remote build container. | ||
*/ | ||
@Test | ||
public void book() { | ||
given() | ||
.when() | ||
.header("Content-Type", APPLICATION_XML) | ||
.body(BOOK_WITH_IMAGE) | ||
.when() | ||
.post("/jaxb/book") | ||
.then() | ||
.statusCode(HttpStatus.SC_ACCEPTED) | ||
// The height in pixels of the book's cover image. | ||
.body(is("10")); | ||
} | ||
|
||
/** | ||
* Smoke tests that our Lambda function makes at | ||
* least some sense, but it doesn't talk to real AWS API. | ||
*/ | ||
@Test | ||
public void testLambdaStream() { | ||
assertEquals("10", LambdaClient.invoke(String.class, BOOK_WITH_IMAGE)); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
integration-tests/awt-packaging/src/test/java/io/quarkus/it/jaxb/AwtJaxbTestIT.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,59 @@ | ||
package io.quarkus.it.jaxb; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class AwtJaxbTestIT extends AwtJaxbTest { | ||
|
||
/** | ||
* Test is native image only, we need all artifacts to be packaged | ||
* already, e.g. function.zip | ||
* </br> | ||
* Tests that the same set of .so files that was copied over | ||
* from the remote build container is also packaged into the | ||
* zip file that will be deployed to AWS Lambda. | ||
* | ||
* @throws java.io.IOException | ||
*/ | ||
@Test | ||
public void testPackaging() throws IOException { | ||
final Path targetPath = Paths.get(".", "target").toAbsolutePath(); | ||
final Set<String> localLibs = new HashSet<>(); | ||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(targetPath, "*.so")) { | ||
for (Path entry : stream) { | ||
localLibs.add(entry.getFileName().toString()); | ||
} | ||
} | ||
|
||
final Path zipPath = targetPath.resolve("function.zip").toAbsolutePath(); | ||
assertTrue(Files.exists(zipPath), "Expected " + zipPath + " to exist"); | ||
final Set<String> awsLambdaLibs = new HashSet<>(); | ||
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipPath))) { | ||
ZipEntry entry; | ||
while ((entry = zipInputStream.getNextEntry()) != null) { | ||
if (entry.getName().endsWith(".so")) { | ||
awsLambdaLibs.add(entry.getName()); | ||
} | ||
zipInputStream.closeEntry(); | ||
} | ||
} | ||
assertEquals(localLibs, awsLambdaLibs, | ||
"The sets of .so libs produced by the build and the set in .zip file MUST be the same. It was: " | ||
+ localLibs + " vs. " + awsLambdaLibs); | ||
} | ||
} |
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