mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(lambda): add PutFunctionConcurrency stub (#325)
* feat(lambda): add PutFunctionConcurrency stub
Add PutFunctionConcurrency, GetFunctionConcurrency, and
DeleteFunctionConcurrency endpoints:
PUT /2017-10-31/functions/{FunctionName}/concurrency
DELETE /2017-10-31/functions/{FunctionName}/concurrency
GET /2019-09-30/functions/{FunctionName}/concurrency
The stored ReservedConcurrentExecutions value is persisted on
LambdaFunction and echoed back, but it is not enforced at invocation
time — invocation slots in LambdaExecutorService / WarmPool are not
bounded, and the account-level concurrent execution limit is not
validated.
* fix(lambda): tighten PutFunctionConcurrency validation
This commit is contained in:
1 parent
a32b7f1f3b
commit
3b6b5fb687
5 files changed
+287
-1
No files matched your search
+138
@@ -0,0 +1,138 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.lambda.model.*;
|
||||
import software.amazon.awssdk.services.lambda.model.Runtime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Lambda - Function concurrency")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class LambdaConcurrencyTest {
|
||||
|
||||
private static final String FUNCTION_NAME = "sdk-test-concurrency-fn";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/lambda-role";
|
||||
|
||||
private static LambdaClient lambda;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
lambda = TestFixtures.lambdaClient();
|
||||
lambda.createFunction(CreateFunctionRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.runtime(Runtime.NODEJS20_X)
|
||||
.role(ROLE)
|
||||
.handler("index.handler")
|
||||
.code(FunctionCode.builder()
|
||||
.zipFile(SdkBytes.fromByteArray(LambdaUtils.minimalZip()))
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (lambda != null) {
|
||||
try {
|
||||
lambda.deleteFunction(DeleteFunctionRequest.builder()
|
||||
.functionName(FUNCTION_NAME).build());
|
||||
} catch (Exception ignored) {}
|
||||
lambda.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void getFunctionConcurrency_unset_returnsEmpty() {
|
||||
GetFunctionConcurrencyResponse response = lambda.getFunctionConcurrency(
|
||||
GetFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.build());
|
||||
|
||||
assertThat(response.reservedConcurrentExecutions()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void putFunctionConcurrency_setsAndReturnsValue() {
|
||||
PutFunctionConcurrencyResponse response = lambda.putFunctionConcurrency(
|
||||
PutFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.reservedConcurrentExecutions(5)
|
||||
.build());
|
||||
|
||||
assertThat(response.reservedConcurrentExecutions()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getFunctionConcurrency_afterPut_returnsValue() {
|
||||
GetFunctionConcurrencyResponse response = lambda.getFunctionConcurrency(
|
||||
GetFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.build());
|
||||
|
||||
assertThat(response.reservedConcurrentExecutions()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void putFunctionConcurrency_updatesExistingValue() {
|
||||
PutFunctionConcurrencyResponse response = lambda.putFunctionConcurrency(
|
||||
PutFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.reservedConcurrentExecutions(10)
|
||||
.build());
|
||||
|
||||
assertThat(response.reservedConcurrentExecutions()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void putFunctionConcurrency_zeroIsAllowed() {
|
||||
PutFunctionConcurrencyResponse response = lambda.putFunctionConcurrency(
|
||||
PutFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.reservedConcurrentExecutions(0)
|
||||
.build());
|
||||
|
||||
assertThat(response.reservedConcurrentExecutions()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteFunctionConcurrency_clearsValue() {
|
||||
lambda.deleteFunctionConcurrency(DeleteFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.build());
|
||||
|
||||
GetFunctionConcurrencyResponse response = lambda.getFunctionConcurrency(
|
||||
GetFunctionConcurrencyRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.build());
|
||||
|
||||
assertThat(response.reservedConcurrentExecutions()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void putFunctionConcurrency_unknownFunction_throws404() {
|
||||
assertThatThrownBy(() -> lambda.putFunctionConcurrency(
|
||||
PutFunctionConcurrencyRequest.builder()
|
||||
.functionName("does-not-exist")
|
||||
.reservedConcurrentExecutions(5)
|
||||
.build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void getFunctionConcurrency_unknownFunction_throws404() {
|
||||
assertThatThrownBy(() -> lambda.getFunctionConcurrency(
|
||||
GetFunctionConcurrencyRequest.builder()
|
||||
.functionName("does-not-exist")
|
||||
.build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user