-
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.
Merge pull request #40396 from holomekc/main
Funqy Amazon Lambda should support more Amazon events
- Loading branch information
Showing
74 changed files
with
3,264 additions
and
12 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
46 changes: 46 additions & 0 deletions
46
...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,46 @@ | ||
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; | ||
import io.quarkus.funqy.lambda.model.cloudevents.CloudEventDataV1; | ||
import io.quarkus.funqy.lambda.model.cloudevents.CloudEventV1; | ||
|
||
public class FunqyAmazonLambdaProcessor { | ||
|
||
@BuildStep(onlyIf = NativeBuild.class) | ||
public void process(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { | ||
reflectiveClass.produce(ReflectiveClassBuildItem.builder( | ||
// io CloudEvents | ||
CloudEventV1.class.getName(), | ||
CloudEventDataV1.class.getName(), | ||
// 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
52 changes: 52 additions & 0 deletions
52
...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,52 @@ | ||
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; | ||
|
||
/** | ||
* Testing that the item-function can handle an event, which just represents the item itself. So no special aws event | ||
* is used as envelope | ||
*/ | ||
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); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...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,69 @@ | ||
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 jakarta.inject.Inject; | ||
|
||
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.BodyDeserializer; | ||
import io.quarkus.funqy.test.util.EventDataProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* Testing that the cloudevents-function with a cloud events specific model can handle events. | ||
*/ | ||
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, BodyDeserializer.class)); | ||
|
||
@Inject | ||
BodyDeserializer deserializer; | ||
|
||
@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 = deserializer.getBodyAs(response.then().statusCode(200), 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 = deserializer.getBodyAs(response.then().statusCode(200), BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), hasSize(1)); | ||
assertThat(respBody.batchItemFailures().stream().map(ItemFailure::itemIdentifier).toList(), hasItem("1")); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...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,68 @@ | ||
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 jakarta.inject.Inject; | ||
|
||
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.BodyDeserializer; | ||
import io.quarkus.funqy.test.util.EventDataProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* Testing that the item-function with a customer model can handle cloud events. | ||
*/ | ||
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, BodyDeserializer.class)); | ||
|
||
@Inject | ||
BodyDeserializer deserializer; | ||
|
||
@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 = deserializer.getBodyAs(response.then().statusCode(200), 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 = deserializer.getBodyAs(response.then().statusCode(200), BatchItemFailures.class); | ||
assertThat(respBody.batchItemFailures(), hasSize(1)); | ||
assertThat(respBody.batchItemFailures().stream().map(ItemFailure::itemIdentifier).toList(), hasItem("1")); | ||
} | ||
} |
Oops, something went wrong.