Light, fluffy, and always free - The AWS Local Emulator alternative
feat(servicequotas): configure applied EC2 vCPU quota (#5926)
David Phillips1a80884f40b1
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.javaindex e507479f7b..21da6cbf0a 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.java@@ -1,5 +1,6 @@package com.floci.test;+import org.junit.jupiter.api.DisplayName;import org.junit.jupiter.api.Test;import software.amazon.awssdk.services.servicequotas.ServiceQuotasClient;import software.amazon.awssdk.services.servicequotas.model.ServiceQuota;@@ -20,6 +21,7 @@ class ServiceQuotasTest {ServiceQuota quota = client.getAWSDefaultServiceQuota(request -> request.serviceCode("ec2").quotaCode(STANDARD_CODE)).quota();assertStandardMetadata(quota);+ assertThat(quota.value()).isEqualTo(5.0);List<List<ServiceQuota>> pages = client.listAWSDefaultServiceQuotasPaginator(request -> request.serviceCode("ec2").maxResults(1)).stream().map(page -> page.quotas()).toList();assertCatalogPages(pages, quota);@@ -27,12 +29,17 @@ class ServiceQuotasTest {}@Test- void emulatedAppliedQuotaReportsTheStaticDefault() {+ @DisplayName("Applied EC2 quota reads and pagination use the configured value")+ void emulatedAppliedQuotaReportsConfiguredValue() {assumeFalse(TestFixtures.isRealAws(), "Real applied quotas can differ from catalog defaults");try (ServiceQuotasClient client = TestFixtures.serviceQuotasClient()) {ServiceQuota quota = client.getServiceQuota(request -> request.serviceCode("ec2").quotaCode(STANDARD_CODE)).quota();assertStandardMetadata(quota);+ assertThat(quota.value()).isNotNull().isGreaterThanOrEqualTo(0.0);+ String expectedValue = System.getenv().getOrDefault(+ "FLOCI_TEST_EXPECTED_STANDARD_ON_DEMAND_VCPUS", "5");+ assertThat(quota.value()).isEqualTo(Double.parseDouble(expectedValue));List<List<ServiceQuota>> pages = client.listServiceQuotasPaginator(request -> request.serviceCode("ec2").maxResults(1)).stream().map(page -> page.quotas()).toList();assertCatalogPages(pages, quota);@@ -53,7 +60,6 @@ class ServiceQuotasTest {assertThat(quota.quotaCode()).isEqualTo(STANDARD_CODE);assertThat(quota.quotaName()).isEqualTo("Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances");- assertThat(quota.value()).isEqualTo(5.0);assertThat(quota.adjustable()).isTrue();assertThat(quota.globalQuota()).isFalse();}diff --git a/docs/services/servicequotas.md b/docs/services/servicequotas.mdindex e0f0774251..a2598254df 100644--- a/docs/services/servicequotas.md+++ b/docs/services/servicequotas.md@@ -15,10 +15,15 @@ of 50. VPC's `L-FE5A380F` ("NAT gateways per Availability Zone", 5) and `L-2AEEBnetwork ACL", 20) carry their AWS default values, so tooling that compares a desired value againstthe default before requesting an increase takes the same path it would against AWS.EC2's `L-1216C47A` ("Running On-Demand Standard (A, C, D, H, I, M, R, T, Z)-instances") also reports its AWS default of 5. This catalog entry does not enforce-a vCPU admission limit on EC2.+instances") reports a configurable applied value through `GetServiceQuota` and+`ListServiceQuotas`. Set `FLOCI_SERVICES_SERVICEQUOTAS_STANDARD_ON_DEMAND_VCPUS` to+change that value for all local accounts and regions. Use a nonnegative integer;+negative values prevent Floci from starting, even when Service Quotas is disabled.+It defaults to 5. The AWS+default read actions always return 5. This setting does not enforce a vCPU+admission limit on EC2.-Applied quotas and AWS default quotas return the same data, and quota values are static.+All other applied quotas and AWS default quotas return the same catalog data.`RequestServiceQuotaIncrease` is accepted and validated, records the request, and lets you readit back with `GetRequestedServiceQuotaChange` or list it with`ListRequestedServiceQuotaChangeHistoryByQuota`, but it does not change any quota value. See@@ -31,8 +36,8 @@ Limitations.| --- | --- || `ListServiceQuotas` | Lists the quotas for a service code; generated quotas for unknown codes || `GetServiceQuota` | Returns one quota by service and quota code, else `NoSuchResourceException` |-| `GetAWSDefaultServiceQuota` | Same as GetServiceQuota; defaults equal applied values |-| `ListAWSDefaultServiceQuotas` | Same as ListServiceQuotas; defaults equal applied values |+| `GetAWSDefaultServiceQuota` | Returns the catalog default, independent of the configured applied EC2 value |+| `ListAWSDefaultServiceQuotas` | Lists catalog defaults, independent of the configured applied EC2 value || `RequestServiceQuotaIncrease` | Validates and stores an increase request as `PENDING`; a second open request for the same quota is refused with `ResourceAlreadyExistsException` || `GetRequestedServiceQuotaChange` | Returns a stored request by id, else `NoSuchResourceException` || `ListRequestedServiceQuotaChangeHistoryByQuota` | Lists the stored requests for a service/quota pair, newest first |@@ -55,8 +60,8 @@ Limitations.`[a-zA-Z][a-zA-Z0-9-]{1,63}` (max 63 characters) and a malformed one is rejected with`IllegalArgumentException` instead of returning invented quotas.- **A requested increase does not change the quota.** `GetServiceQuota` continues to return- the catalog value after a successful increase request. Quota values remain static by design- so pipelines never stall on an unenforced limit.+ configured applied value or catalog value after a successful increase request. Increase+ requests do not update local configuration or enforce capacity limits.- `ListRequestedServiceQuotaChangeHistory` (the account-wide variant without a quota filter) isnot implemented.- `CaseId` is never returned; no support case is opened. `SupportCaseAllowed` in the request is@@ -69,6 +74,7 @@ Limitations.| Environment variable | Default | Description || --- | --- | --- || `FLOCI_SERVICES_SERVICEQUOTAS_ENABLED` | `true` | Enables the service |+| `FLOCI_SERVICES_SERVICEQUOTAS_STANDARD_ON_DEMAND_VCPUS` | `5` | Applied EC2 Standard On-Demand vCPU quota reported for every local account and region; does not enforce EC2 admission |## Examplediff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex 196dbc7359..a256153c47 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -1094,6 +1094,9 @@ public interface EmulatorConfig {interface ServiceQuotasServiceConfig {@WithDefault("true")boolean enabled();++ @WithDefault("5")+ int standardOnDemandVcpus();}interface VerifiedPermissionsServiceConfig {diff --git a/src/main/java/io/github/hectorvent/floci/config/ServiceQuotasStartupValidator.java b/src/main/java/io/github/hectorvent/floci/config/ServiceQuotasStartupValidator.javanew file mode 100644index 0000000000..0f38cad1af--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/config/ServiceQuotasStartupValidator.java@@ -0,0 +1,28 @@+package io.github.hectorvent.floci.config;++import io.quarkus.runtime.StartupEvent;+import jakarta.enterprise.context.ApplicationScoped;+import jakarta.enterprise.event.Observes;+import jakarta.inject.Inject;++@ApplicationScoped+public class ServiceQuotasStartupValidator {++ private final EmulatorConfig config;++ @Inject+ public ServiceQuotasStartupValidator(EmulatorConfig config) {+ this.config = config;+ }++ void onStart(@Observes StartupEvent ignored) {+ validateStandardOnDemandVcpus(config.services().servicequotas().standardOnDemandVcpus());+ }++ public static void validateStandardOnDemandVcpus(int value) {+ if (value < 0) {+ throw new IllegalArgumentException(+ "floci.services.servicequotas.standard-on-demand-vcpus must be nonnegative");+ }+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasJsonHandler.javaindex 4a1f067310..bdbd2e91ef 100644--- a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasJsonHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasJsonHandler.java@@ -28,10 +28,10 @@ public class ServiceQuotasJsonHandler {public Response handle(String action, JsonNode request, String region, String accountId) {LOG.debugv("ServiceQuotas action: {0}", action);return switch (action) {- case "ListServiceQuotas" -> handleListServiceQuotas(request, region, accountId);- case "GetServiceQuota" -> handleGetServiceQuota(request, region, accountId);- case "GetAWSDefaultServiceQuota" -> handleGetServiceQuota(request, region, accountId);- case "ListAWSDefaultServiceQuotas" -> handleListServiceQuotas(request, region, accountId);+ case "ListServiceQuotas" -> handleListServiceQuotas(request, region, accountId, false);+ case "GetServiceQuota" -> handleGetServiceQuota(request, region, accountId, false);+ case "GetAWSDefaultServiceQuota" -> handleGetServiceQuota(request, region, accountId, true);+ case "ListAWSDefaultServiceQuotas" -> handleListServiceQuotas(request, region, accountId, true);case "RequestServiceQuotaIncrease" -> handleRequestServiceQuotaIncrease(request, region, accountId);case "GetRequestedServiceQuotaChange" ->Response.ok(service.getRequestedServiceQuotaChange(@@ -48,20 +48,22 @@ public class ServiceQuotasJsonHandler {};}- private Response handleListServiceQuotas(JsonNode request, String region, String accountId) {- return Response.ok(service.listServiceQuotas(- stringOrNull(request, "ServiceCode"),- stringOrNull(request, "QuotaCode"),- stringOrNull(request, "NextToken"),- integerOrNull(request, "MaxResults"),- region, accountId)).build();+ private Response handleListServiceQuotas(JsonNode request, String region, String accountId, boolean awsDefault) {+ String serviceCode = stringOrNull(request, "ServiceCode");+ String quotaCode = stringOrNull(request, "QuotaCode");+ String nextToken = stringOrNull(request, "NextToken");+ Integer maxResults = integerOrNull(request, "MaxResults");+ return Response.ok(awsDefault+ ? service.listAwsDefaultServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)+ : service.listServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)).build();}- private Response handleGetServiceQuota(JsonNode request, String region, String accountId) {- return Response.ok(service.getServiceQuota(- stringOrNull(request, "ServiceCode"),- stringOrNull(request, "QuotaCode"),- region, accountId)).build();+ private Response handleGetServiceQuota(JsonNode request, String region, String accountId, boolean awsDefault) {+ String serviceCode = stringOrNull(request, "ServiceCode");+ String quotaCode = stringOrNull(request, "QuotaCode");+ return Response.ok(awsDefault+ ? service.getAwsDefaultServiceQuota(serviceCode, quotaCode, region, accountId)+ : service.getServiceQuota(serviceCode, quotaCode, region, accountId)).build();}private static String stringOrNull(JsonNode node, String field) {diff --git a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.javaindex dcbdb369e1..4d2822836c 100644--- a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java+++ b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java@@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.type.TypeReference;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ArrayNode;import com.fasterxml.jackson.databind.node.ObjectNode;+import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.config.ServiceQuotasStartupValidator;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.Base64Url;@@ -31,7 +33,8 @@ import java.util.zip.CRC32;* executions"), plus a deterministic generic set for any other service code.* Unmodeled values are deliberately generous so local pipelines that gate on* quota headroom never stall on a limit the emulator does not enforce.- * Applied and default quotas return the same data.+ * Applied EC2 Standard On-Demand vCPU values use local configuration; AWS defaults+ * retain the catalog value.** @see <a href="https://docs.aws.amazon.com/servicequotas/2019-06-24/apireference/Welcome.html">Service Quotas API</a>*/@@ -81,12 +84,15 @@ public class ServiceQuotasService {"Concurrent operations");private final ObjectMapper objectMapper;+ private final int standardOnDemandVcpus;private final StorageBackend<String, ObjectNode> requestedQuotaStore;private final Object openRequestLock = new Object();@Inject- public ServiceQuotasService(StorageFactory storageFactory, ObjectMapper objectMapper) {+ public ServiceQuotasService(StorageFactory storageFactory, ObjectMapper objectMapper, EmulatorConfig config) {this.objectMapper = objectMapper;+ this.standardOnDemandVcpus = config.services().servicequotas().standardOnDemandVcpus();+ ServiceQuotasStartupValidator.validateStandardOnDemandVcpus(standardOnDemandVcpus);this.requestedQuotaStore = storageFactory.create("servicequotas","servicequotas-requested-changes.json",new TypeReference<Map<String, ObjectNode>>() {});@@ -94,6 +100,16 @@ public class ServiceQuotasService {public ObjectNode listServiceQuotas(String serviceCode, String quotaCodeFilter, String nextToken,Integer maxResults, String region, String accountId) {+ return listQuotas(serviceCode, quotaCodeFilter, nextToken, maxResults, region, accountId, true);+ }++ public ObjectNode listAwsDefaultServiceQuotas(String serviceCode, String quotaCodeFilter, String nextToken,+ Integer maxResults, String region, String accountId) {+ return listQuotas(serviceCode, quotaCodeFilter, nextToken, maxResults, region, accountId, false);+ }++ private ObjectNode listQuotas(String serviceCode, String quotaCodeFilter, String nextToken,+ Integer maxResults, String region, String accountId, boolean applied) {requireServiceCode(serviceCode);List<QuotaDefinition> quotas = quotasFor(serviceCode);if (quotaCodeFilter != null && !quotaCodeFilter.isEmpty()) {@@ -104,7 +120,7 @@ public class ServiceQuotasService {ObjectNode response = objectMapper.createObjectNode();ArrayNode array = response.putArray("Quotas");for (QuotaDefinition quota : page.items()) {- array.add(quotaNode(serviceCode, quota, region, accountId));+ array.add(quotaNode(serviceCode, quota, region, accountId, applied));}if (page.nextToken() != null) {response.put("NextToken", page.nextToken());@@ -113,6 +129,14 @@ public class ServiceQuotasService {}public ObjectNode getServiceQuota(String serviceCode, String quotaCode, String region, String accountId) {+ return getQuota(serviceCode, quotaCode, region, accountId, true);+ }++ public ObjectNode getAwsDefaultServiceQuota(String serviceCode, String quotaCode, String region, String accountId) {+ return getQuota(serviceCode, quotaCode, region, accountId, false);+ }++ private ObjectNode getQuota(String serviceCode, String quotaCode, String region, String accountId, boolean applied) {requireServiceCode(serviceCode);if (quotaCode == null || quotaCode.isEmpty()) {throw new AwsException("IllegalArgumentException",@@ -124,7 +148,7 @@ public class ServiceQuotasService {.orElseThrow(() -> new AwsException("NoSuchResourceException","The request failed because the specified service quota does not exist.", 400));ObjectNode response = objectMapper.createObjectNode();- response.set("Quota", quotaNode(serviceCode, quota, region, accountId));+ response.set("Quota", quotaNode(serviceCode, quota, region, accountId, applied));return response;}@@ -148,7 +172,8 @@ public class ServiceQuotasService {return "L-%08X".formatted(crc.getValue());}- private ObjectNode quotaNode(String serviceCode, QuotaDefinition quota, String region, String accountId) {+ private ObjectNode quotaNode(String serviceCode, QuotaDefinition quota, String region, String accountId,+ boolean applied) {ObjectNode node = objectMapper.createObjectNode();node.put("ServiceCode", serviceCode);node.put("ServiceName", SERVICE_NAMES.getOrDefault(serviceCode, serviceCode));@@ -156,7 +181,9 @@ public class ServiceQuotasService {serviceCode + "/" + quota.quotaCode()).toString());node.put("QuotaCode", quota.quotaCode());node.put("QuotaName", quota.quotaName());- node.put("Value", quota.value());+ double value = applied && "ec2".equals(serviceCode) && "L-1216C47A".equals(quota.quotaCode())+ ? standardOnDemandVcpus : quota.value();+ node.put("Value", value);node.put("Unit", "None");node.put("Adjustable", true);node.put("GlobalQuota", quota.globalQuota());diff --git a/src/main/resources/application.yml b/src/main/resources/application.ymlindex 7467be0b5c..740c75237d 100644--- a/src/main/resources/application.yml+++ b/src/main/resources/application.yml@@ -994,6 +994,7 @@ floci:enabled: trueservicequotas:enabled: true+ standard-on-demand-vcpus: 5verifiedpermissions:enabled: true# cedar-url: http://floci-cedar:8180 # set to skip sidecar container managementdiff --git a/src/test/java/io/github/hectorvent/floci/config/ServiceQuotasStartupValidatorTest.java b/src/test/java/io/github/hectorvent/floci/config/ServiceQuotasStartupValidatorTest.javanew file mode 100644index 0000000000..8404ef6ffa--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/config/ServiceQuotasStartupValidatorTest.java@@ -0,0 +1,38 @@+package io.github.hectorvent.floci.config;++import io.quarkus.runtime.StartupEvent;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.ValueSource;++import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;+import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertThrows;+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;+import static org.mockito.Mockito.mock;+import static org.mockito.Mockito.when;++class ServiceQuotasStartupValidatorTest {++ @ParameterizedTest+ @ValueSource(ints = {-1, Integer.MIN_VALUE})+ void negativeQuotaIsRejectedByStartupObserver(int value) {+ ServiceQuotasStartupValidator validator = validator(value);+ IllegalArgumentException error = assertThrows(IllegalArgumentException.class,+ () -> validator.onStart(new StartupEvent()));+ assertEquals("floci.services.servicequotas.standard-on-demand-vcpus must be nonnegative",+ error.getMessage());+ }++ @ParameterizedTest+ @ValueSource(ints = {0, 5, 7, Integer.MAX_VALUE})+ void nonnegativeQuotaIsAcceptedByStartupObserver(int value) {+ ServiceQuotasStartupValidator validator = validator(value);+ assertDoesNotThrow(() -> validator.onStart(new StartupEvent()));+ }++ private static ServiceQuotasStartupValidator validator(int value) {+ EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);+ when(config.services().servicequotas().standardOnDemandVcpus()).thenReturn(value);+ return new ServiceQuotasStartupValidator(config);+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasAppliedValueIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasAppliedValueIntegrationTest.javanew file mode 100644index 0000000000..375e80b0eb--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasAppliedValueIntegrationTest.java@@ -0,0 +1,100 @@+package io.github.hectorvent.floci.services.servicequotas;++import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;+import io.quarkus.test.junit.QuarkusTest;+import io.quarkus.test.junit.QuarkusTestProfile;+import io.quarkus.test.junit.TestProfile;+import io.restassured.response.Response;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.CsvSource;++import java.util.List;+import java.util.Map;++import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth;+import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.equalTo;+import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertNull;++@QuarkusTest+@TestProfile(ServiceQuotasAppliedValueIntegrationTest.AppliedQuotaProfile.class)+class ServiceQuotasAppliedValueIntegrationTest {++ private static final String CODE = "L-1216C47A";++ public static class AppliedQuotaProfile implements QuarkusTestProfile {+ @Override+ public Map<String, String> getConfigOverrides() {+ return Map.of("floci.services.servicequotas.standard-on-demand-vcpus", "7");+ }+ }++ @BeforeAll+ static void configureContentTypes() {+ RestAssuredJsonUtils.configureAwsContentTypes();+ }++ @ParameterizedTest+ @CsvSource({"us-east-1,aws", "cn-north-1,aws-cn"})+ void appliedGetReportsConfiguredValue(String region, String partition) {+ quotaRequest("GetServiceQuota", "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"" + CODE + "\"}", region)+ .then().statusCode(200)+ .body("Quota.Value", equalTo(7.0f))+ .body("Quota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region+ + ":111111111111:ec2/" + CODE));+ }++ @ParameterizedTest+ @CsvSource({"us-east-1,aws", "cn-north-1,aws-cn"})+ void appliedListReportsConfiguredValue(String region, String partition) {+ quotaRequest("ListServiceQuotas", "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"" + CODE + "\"}", region)+ .then().statusCode(200)+ .body("Quotas.size()", equalTo(1))+ .body("Quotas[0].Value", equalTo(7.0f))+ .body("Quotas[0].QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region+ + ":111111111111:ec2/" + CODE));+ }++ @ParameterizedTest+ @CsvSource({"us-east-1,aws", "cn-north-1,aws-cn"})+ void awsDefaultReadsKeepFive(String region, String partition) {+ quotaRequest("GetAWSDefaultServiceQuota", "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"" + CODE + "\"}", region)+ .then().statusCode(200).body("Quota.Value", equalTo(5.0f));+ quotaRequest("ListAWSDefaultServiceQuotas", "{\"ServiceCode\":\"ec2\"}", region)+ .then().statusCode(200).body("Quotas.size()", equalTo(4))+ .body("Quotas.find { it.QuotaCode == 'L-1216C47A' }.Value", equalTo(5.0f));+ }++ @ParameterizedTest+ @CsvSource({"ListServiceQuotas,7", "ListAWSDefaultServiceQuotas,5"})+ void bothListsRetainPaginationAndGenericRows(String action, float expectedValue) {+ Response first = quotaRequest(action, "{\"ServiceCode\":\"ec2\",\"MaxResults\":1}", "us-east-1")+ .then().statusCode(200).body("Quotas.size()", equalTo(1))+ .body("Quotas[0].QuotaCode", equalTo(CODE)).body("Quotas[0].Value", equalTo(expectedValue))+ .extract().response();+ String token = first.path("NextToken");+ Response rest = quotaRequest(action,+ "{\"ServiceCode\":\"ec2\",\"NextToken\":\"" + token + "\"}", "us-east-1")+ .then().statusCode(200).body("Quotas.size()", equalTo(3)).extract().response();+ assertEquals(List.of(5000.0f, 5000.0f, 5000.0f), rest.path("Quotas.Value"));+ assertNull(rest.path("NextToken"));+ }++ @ParameterizedTest+ @CsvSource({"GetServiceQuota", "GetAWSDefaultServiceQuota"})+ void unrelatedCuratedValuesAndErrorsRemainUnchanged(String action) {+ quotaRequest(action, "{\"ServiceCode\":\"vpc\",\"QuotaCode\":\"L-2AEEBF1A\"}", "us-east-1")+ .then().statusCode(200).body("Quota.Value", equalTo(20.0f));+ quotaRequest(action, "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"L-UNKNOWN\"}", "us-east-1")+ .then().statusCode(400).body("__type", equalTo("NoSuchResourceException"));+ }++ private Response quotaRequest(String action, String body, String region) {+ return given().contentType("application/x-amz-json-1.1")+ .header("X-Amz-Target", "ServiceQuotasV20190624." + action)+ .header("Authorization", auth("111111111111", "20261018", region, "servicequotas"))+ .body(body).when().post("/");+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.javaindex d4d2a6bd93..05b2307e28 100644--- a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java@@ -3,9 +3,13 @@ package io.github.hectorvent.floci.services.servicequotas;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ObjectNode;+import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.storage.StorageFactory;import io.github.hectorvent.floci.testing.InMemoryStorageFactory;import org.junit.jupiter.api.Test;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.ValueSource;import java.util.HashMap;import java.util.List;@@ -16,13 +20,53 @@ import static org.junit.jupiter.api.Assertions.assertEquals;import static org.junit.jupiter.api.Assertions.assertFalse;import static org.junit.jupiter.api.Assertions.assertThrows;import static org.junit.jupiter.api.Assertions.assertTrue;+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;+import static org.mockito.Mockito.mock;+import static org.mockito.Mockito.verifyNoInteractions;+import static org.mockito.Mockito.when;class ServiceQuotasServiceTest {private static final String ACCOUNT_ID = "000000000000";private final ServiceQuotasService service =- new ServiceQuotasService(new InMemoryStorageFactory(ACCOUNT_ID), new ObjectMapper());+ new ServiceQuotasService(new InMemoryStorageFactory(ACCOUNT_ID), new ObjectMapper(), defaultConfig());++ private static EmulatorConfig defaultConfig() {+ EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);+ when(config.services().servicequotas().standardOnDemandVcpus()).thenReturn(5);+ return config;+ }++ @ParameterizedTest+ @ValueSource(ints = {-1, Integer.MIN_VALUE})+ void rejectsNegativeVcpuSettingsBeforeOpeningStorage(int value) {+ EmulatorConfig config = defaultConfig();+ when(config.services().servicequotas().standardOnDemandVcpus()).thenReturn(value);+ StorageFactory storageFactory = mock(StorageFactory.class);+ IllegalArgumentException error = assertThrows(IllegalArgumentException.class,+ () -> new ServiceQuotasService(storageFactory, new ObjectMapper(), config));+ assertTrue(error.getMessage().contains("floci.services.servicequotas.standard-on-demand-vcpus"));+ verifyNoInteractions(storageFactory);+ }++ @ParameterizedTest+ @ValueSource(ints = {0, Integer.MAX_VALUE})+ void nonnegativeBoundarySettingsApplyWithoutChangingAwsDefaults(int value) {+ EmulatorConfig config = defaultConfig();+ when(config.services().servicequotas().standardOnDemandVcpus()).thenReturn(value);+ ServiceQuotasService configured = new ServiceQuotasService(+ new InMemoryStorageFactory(ACCOUNT_ID), new ObjectMapper(), config);+ String code = "L-1216C47A";+ assertEquals((double) value, configured.getServiceQuota("ec2", code, "us-east-1", ACCOUNT_ID)+ .path("Quota").path("Value").asDouble());+ assertEquals((double) value, configured.listServiceQuotas("ec2", code, null, null, "us-east-1", ACCOUNT_ID)+ .path("Quotas").get(0).path("Value").asDouble());+ assertEquals(5.0, configured.getAwsDefaultServiceQuota("ec2", code, "us-east-1", ACCOUNT_ID)+ .path("Quota").path("Value").asDouble());+ assertEquals(5.0, configured.listAwsDefaultServiceQuotas("ec2", code, null, null, "us-east-1", ACCOUNT_ID)+ .path("Quotas").get(0).path("Value").asDouble());+ }@Testvoid syntheticQuotaCodesAreStableAndWellFormed() {diff --git a/src/test/resources/application.yml b/src/test/resources/application.ymlindex 2b153cb899..612b78b584 100644--- a/src/test/resources/application.yml+++ b/src/test/resources/application.yml@@ -542,6 +542,7 @@ floci:enabled: trueservicequotas:enabled: true+ standard-on-demand-vcpus: 5verifiedpermissions:enabled: trueram: