-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Funqy Amazon Lambda support more Amazon events
Support for SQS, SNS, DynamoDB and Kinesis, with focus on the batching feature of AWS. Furthermore, add support for CloudEvents. Add tests for funqy amazon lambda
- Loading branch information
Showing
72 changed files
with
3,001 additions
and
41 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
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
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
43 changes: 43 additions & 0 deletions
43
...oyment/src/main/java/io/quarkus/funqy/deployment/bindings/FunqyAmazonLambdaProcessor.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,43 @@ | ||
package io.quarkus.funqy.deployment.bindings; | ||
|
||
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; | ||
import com.amazonaws.services.lambda.runtime.events.KinesisEvent; | ||
import com.amazonaws.services.lambda.runtime.events.SNSEvent; | ||
import com.amazonaws.services.lambda.runtime.events.SQSBatchResponse; | ||
import com.amazonaws.services.lambda.runtime.events.SQSEvent; | ||
import com.amazonaws.services.lambda.runtime.events.StreamsEventResponse; | ||
import com.amazonaws.services.lambda.runtime.events.models.kinesis.Record; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.deployment.pkg.steps.NativeBuild; | ||
|
||
public class FunqyAmazonLambdaProcessor { | ||
|
||
@BuildStep(onlyIf = NativeBuild.class) | ||
public void process(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { | ||
reflectiveClass.produce(ReflectiveClassBuildItem.builder( | ||
// SQS | ||
SQSEvent.class.getName(), | ||
SQSEvent.SQSMessage.class.getName(), | ||
SQSEvent.MessageAttribute.class.getName(), | ||
SQSBatchResponse.class.getName(), | ||
SQSBatchResponse.BatchItemFailure.class.getName(), | ||
// SNS | ||
SNSEvent.class.getName(), | ||
SNSEvent.SNSRecord.class.getName(), | ||
SNSEvent.SNS.class.getName(), | ||
// Kinesis | ||
KinesisEvent.class.getName(), | ||
KinesisEvent.KinesisEventRecord.class.getName(), | ||
Record.class.getName(), | ||
StreamsEventResponse.class.getName(), | ||
StreamsEventResponse.BatchItemFailure.class.getName(), | ||
// DynamoDB | ||
DynamodbEvent.class.getName(), | ||
DynamodbEvent.DynamodbStreamRecord.class.getName() | ||
).constructors().methods().fields().build() | ||
); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...y/funqy-amazon-lambda/deployment/src/test/java/io/quarkus/funqy/test/AnyFunctionTest.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,48 @@ | ||
package io.quarkus.funqy.test; | ||
|
||
import static io.quarkus.funqy.test.util.EventDataProvider.getData; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.funqy.test.util.EventDataProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class AnyFunctionTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("any-function.properties", "application.properties") | ||
.addAsResource("events/any", "events") | ||
.addClasses(TestFunctions.class, Item.class, | ||
EventDataProvider.class)); | ||
|
||
@Test | ||
public void should_return_no_failures_if_processing_is_ok() { | ||
// given | ||
var body = getData("ok.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
response.then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void should_return_one_failure_if_processing_fails() { | ||
// given | ||
var body = getData("fail.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
response.then().statusCode(500); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...n-lambda/deployment/src/test/java/io/quarkus/funqy/test/CloudEventsEventFunctionTest.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,62 @@ | ||
package io.quarkus.funqy.test; | ||
|
||
import static io.quarkus.funqy.test.util.EventDataProvider.getData; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.funqy.test.model.BatchItemFailures; | ||
import io.quarkus.funqy.test.model.ItemFailure; | ||
import io.quarkus.funqy.test.util.EventDataProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class CloudEventsEventFunctionTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.overrideRuntimeConfigKey("quarkus.funqy.export", "cloudevents-function") | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("item-function.properties", "application.properties") | ||
.addAsResource("events/cloudevents", "events") | ||
.addClasses(TestFunctions.class, Item.class, | ||
BatchItemFailures.class, ItemFailure.class, | ||
EventDataProvider.class)); | ||
|
||
@Test | ||
public void should_return_no_failures_if_processing_is_ok() { | ||
// given | ||
var body = getData("ok.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), is(empty())); | ||
} | ||
|
||
@Test | ||
public void should_return_one_failure_if_processing_fails() { | ||
// given | ||
var body = getData("fail.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), hasSize(1)); | ||
assertThat(respBody.batchItemFailures().stream().map(ItemFailure::itemIdentifier).toList(), hasItem("1")); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...amazon-lambda/deployment/src/test/java/io/quarkus/funqy/test/CloudEventsFunctionTest.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,61 @@ | ||
package io.quarkus.funqy.test; | ||
|
||
import static io.quarkus.funqy.test.util.EventDataProvider.getData; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.funqy.test.model.BatchItemFailures; | ||
import io.quarkus.funqy.test.model.ItemFailure; | ||
import io.quarkus.funqy.test.util.EventDataProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class CloudEventsFunctionTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("item-function.properties", "application.properties") | ||
.addAsResource("events/cloudevents", "events") | ||
.addClasses(TestFunctions.class, Item.class, | ||
BatchItemFailures.class, ItemFailure.class, | ||
EventDataProvider.class)); | ||
|
||
@Test | ||
public void should_return_no_failures_if_processing_is_ok() { | ||
// given | ||
var body = getData("ok.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), is(empty())); | ||
} | ||
|
||
@Test | ||
public void should_return_one_failure_if_processing_fails() { | ||
// given | ||
var body = getData("fail.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), hasSize(1)); | ||
assertThat(respBody.batchItemFailures().stream().map(ItemFailure::itemIdentifier).toList(), hasItem("1")); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...azon-lambda/deployment/src/test/java/io/quarkus/funqy/test/DynamoDbEventFunctionTest.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,95 @@ | ||
package io.quarkus.funqy.test; | ||
|
||
import static io.quarkus.funqy.test.util.EventDataProvider.getData; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.funqy.test.model.BatchItemFailures; | ||
import io.quarkus.funqy.test.model.ItemFailure; | ||
import io.quarkus.funqy.test.util.EventDataProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DynamoDbEventFunctionTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.overrideRuntimeConfigKey("quarkus.funqy.export", "dynamodb-function") | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("item-function.properties", "application.properties") | ||
.addAsResource("events/dynamodb", "events") | ||
.addClasses(TestFunctions.class, Item.class, | ||
BatchItemFailures.class, ItemFailure.class, | ||
EventDataProvider.class)); | ||
|
||
@Test | ||
public void should_return_no_failures_if_processing_is_ok() { | ||
// given | ||
var body = getData("ok.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), is(empty())); | ||
} | ||
|
||
@Test | ||
public void should_return_one_failure_if_processing_fails() { | ||
// given | ||
var body = getData("fail.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), hasSize(1)); | ||
assertThat(respBody.batchItemFailures().stream().map(ItemFailure::itemIdentifier).toList(), hasItem("1")); | ||
} | ||
|
||
@Test | ||
public void should_return_no_failures_if_processing_pipes_is_ok() { | ||
// given | ||
var body = getData("pipes-ok.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), is(empty())); | ||
} | ||
|
||
@Test | ||
public void should_return_one_failure_if_processing_pipes_fails() { | ||
// given | ||
var body = getData("pipes-fail.json"); | ||
|
||
// when | ||
var response = RestAssured.given().contentType("application/json") | ||
.body(body) | ||
.post("/"); | ||
|
||
// then | ||
var respBody = response.then().statusCode(200) | ||
.extract().body().as(BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), hasSize(1)); | ||
assertThat(respBody.batchItemFailures().stream().map(ItemFailure::itemIdentifier).toList(), hasItem("1")); | ||
} | ||
} |
Oops, something went wrong.