feat(appsync): Phase 6 — Query Execution + HTTP Endpoint (#1884)

* feat(appsync): Phase 6 GraphQL HTTP execute endpoint

Expose POST /v1/apis/{apiId}/graphql with AppSync-compatible error
mapping, dual Content-Type, schema rehydrate on boot, and smoke
execution without Phase 8 DataFetchers.

* fix(appsync): initialize graphql IdGenerator at native runtime

Query execution pulls graphql.util.IdGenerator into the native image
reachability graph; its static Random must not be frozen in the heap.

* fix(appsync): cache GraphQL engines and always set x-amzn-errortype

Cache graphql-java GraphQL wrappers per apiId in SchemaRegistry (invalidate
on register/remove/rehydrate), and emit x-amzn-errortype on all data-plane
non-2xx responses for AWS parity with AppSync transport errors.

* fix(appsync): hide unexpected exception details on GraphQL 500

AppSync returns a fixed InternalFailure message for unexpected
errors; keep the real cause in server logs only.

* chore(appsync): drop redundant native-init comment

* fix(appsync): rehydrate schemas across all accounts on boot

Startup has no request context, so keys()/get() only saw the default
account. Mirror recoverOrphans with scanAllAccountsAsMap, persist SDL via
putForAccount in the worker, and drop the shared .atl/ gitignore entry.

* fix(appsync): keep non-404 AwsException on data-plane envelope

Avoid rethrowing AwsException from the GraphQL execute endpoint into
AwsExceptionMapper (__type). Map unexpected lookup failures to
InternalFailure with the AppSync errors[] shape instead.

* docs(appsync): point error formatter @see at $util.error docs

security-authz.html covers authorization types, not errorType/errorInfo.
Cite built-in-util-js.html where $util.error documents those fields.

* refactor(storage): type StorageFactory.create as AccountAwareStorageBackend

The factory always wraps every mode in AccountAwareStorageBackend; declaring
that return type removes unsafe casts at AppSync/CodePipeline/CloudFormation
call sites and updates test overrides/mocks to match production.

* fix(test): stub StorageFactory.create with AccountAware backends

thenAnswer stubs that returned bare InMemoryStorage ClassCast after
create() was typed as AccountAwareStorageBackend; align the remaining
service unit tests with the production return type.
This commit is contained in:
AgustinBertagna authored and GitHub committed 2026-08-12 09:32:03 -04:00
1 parent a803626c17
commit 819bfedc6c
58 files changed
+1529 -131

No files matched your search

@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.core.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.eks.EksOidcService;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -38,9 +39,9 @@ class WebIdentityTokenVerifierTest {
verifier = new WebIdentityTokenVerifier(objectMapper);
oidcService = new EksOidcService(new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}, objectMapper);
oidcService.ensureKey(CLUSTER, ISSUER);
@@ -164,6 +164,21 @@ class EmulatorLifecycleTest {
Mockito.verify(elbV2Service, Mockito.never()).restorePersistedRuntime();
}
@Test
@DisplayName("Should rehydrate AppSync schemas after orphan recovery on startup")
void shouldRehydrateAppSyncSchemasAfterOrphanRecovery() {
stubStorageConfig();
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(false);
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
emulatorLifecycle.onStart(Mockito.mock(StartupEvent.class));
var inOrder = Mockito.inOrder(storageFactory, schemaCreationWorker);
inOrder.verify(storageFactory).loadAll();
inOrder.verify(schemaCreationWorker).recoverOrphans();
inOrder.verify(schemaCreationWorker).rehydrateSchemas();
}
@Test
@DisplayName("Should validate the persistent path after BOOT hooks and before loading storage")
void shouldValidatePersistentPathBeforeStorageLoad() {
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager;
import io.github.hectorvent.floci.services.amazonmq.model.Broker;
@@ -26,7 +27,7 @@ class AmazonMqServiceTest {
void setUp() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -173,7 +174,7 @@ class AmazonMqServiceTest {
private AmazonMqService realModeServiceWithFailingManager() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -0,0 +1,371 @@
package io.github.hectorvent.floci.services.appsync;
import io.github.hectorvent.floci.services.appsync.graphql.AppSyncErrorFormatter;
import io.github.hectorvent.floci.services.appsync.graphql.SchemaRegistry;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
@QuarkusTest
class AppSyncExecutionIntegrationTest {
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/appsync/aws4_request";
@Inject
SchemaRegistry schemaRegistry;
private String apiId;
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@BeforeEach
void createApiWithSchema() {
apiId = createApi("exec-" + UUID.randomUUID().toString().substring(0, 8));
startSchema(apiId, "type Query { hello: String }");
awaitSchemaSuccess(apiId);
}
@Test
void dualContentTypeJsonReturnsNullHello() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(200)
.contentType(containsString("application/json"))
.body("data.hello", nullValue())
.body("errors", nullValue());
}
@Test
void dualContentTypeGraphqlReturnsNullHello() {
given()
.header("Authorization", AUTH)
.contentType("application/graphql")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(200)
.body("data.hello", nullValue());
}
@Test
void missingContentTypeReturns400GraphqlErrors() {
given()
.header("Authorization", AUTH)
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(400)
.body("errors[0].errorType", equalTo("MalformedHttpRequestException"))
.body("__type", nullValue());
}
@Test
void unsupportedContentTypeReturns400GraphqlErrors() {
given()
.header("Authorization", AUTH)
.contentType("text/plain")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(400)
.body("errors[0].errorType", equalTo("MalformedHttpRequestException"))
.body("__type", nullValue());
}
@Test
void emptyBodyReturns400MalformedWithEmptyMessage() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(400)
.header("x-amzn-errortype", containsString("MalformedHttpRequestException"))
.body("errors[0].errorType", equalTo("MalformedHttpRequestException"))
.body("errors[0].message", equalTo(AppSyncErrorFormatter.MSG_EMPTY_BODY));
}
@Test
void emptyObjectBodyReturns400UnableToParse() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(400)
.body("errors[0].errorType", equalTo("MalformedHttpRequestException"))
.body("errors[0].message", equalTo(AppSyncErrorFormatter.MSG_UNABLE_TO_PARSE));
}
@Test
void arrayBodyReturns400UnableToParse() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("[{\"query\":\"{ hello }\"}]")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(400)
.body("errors[0].errorType", equalTo("MalformedHttpRequestException"))
.body("errors[0].message", equalTo(AppSyncErrorFormatter.MSG_UNABLE_TO_PARSE));
}
@Test
void unparseableBodyReturns400UnableToParse() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("meow")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(400)
.body("errors[0].errorType", equalTo("MalformedHttpRequestException"))
.body("errors[0].message", equalTo(AppSyncErrorFormatter.MSG_UNABLE_TO_PARSE));
}
@Test
void unknownApiIdReturns404() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/does-not-exist-xyz/graphql")
.then()
.statusCode(404)
.header("x-amzn-errortype", containsString("NotFoundException"));
}
@Test
void apiWithoutSchemaReturns502GraphQLSchemaException() {
String bareApiId = createApi("bare-" + UUID.randomUUID().toString().substring(0, 8));
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + bareApiId + "/graphql")
.then()
.statusCode(502)
.header("x-amzn-errortype", containsString("GraphQLSchemaException"))
.body("errors[0].errorType", equalTo("GraphQLSchemaException"))
.body("errors[0].message", equalTo(AppSyncErrorFormatter.MSG_NO_SCHEMA));
}
@Test
void validationErrorReturns200WithTopLevelErrorType() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ nope }\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(200)
.body("errors[0].errorType", equalTo("ValidationError"))
.body("errors[0].extensions", nullValue());
}
@Test
void syntaxErrorReturns200WithSyntaxError() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ hello\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(200)
.body("errors[0].errorType", equalTo("SyntaxError"));
}
@Test
void introspectionReturnsNonEmptyTypes() {
Map<String, Object> body = given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ __schema { types { name } } }\"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(200)
.extract().jsonPath().getMap("");
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) body.get("data");
@SuppressWarnings("unchecked")
Map<String, Object> schema = (Map<String, Object>) data.get("__schema");
@SuppressWarnings("unchecked")
List<?> types = (List<?>) schema.get("types");
assertThat(types, hasSize(greaterThan(0)));
}
@Test
void variablesAndOperationNameExecuteSelectedOp() {
String multiApi = createApi("multi-" + UUID.randomUUID().toString().substring(0, 8));
startSchema(multiApi, "type Query { hello(id: String): String }");
awaitSchemaSuccess(multiApi);
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("""
{
"query": "query GetHello($id: String) { hello(id: $id) } query Other { hello }",
"variables": {"id": "x"},
"operationName": "GetHello"
}
""")
.when()
.post("/v1/apis/" + multiApi + "/graphql")
.then()
.statusCode(200)
.body("data.hello", nullValue());
}
@Test
void httpSubscriptionReturns200OperationNotSupported() {
String subApi = createApi("sub-" + UUID.randomUUID().toString().substring(0, 8));
startSchema(subApi, """
type Query { hello: String }
type Subscription { onHello: String }
""");
awaitSchemaSuccess(subApi);
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"subscription { onHello }\"}")
.when()
.post("/v1/apis/" + subApi + "/graphql")
.then()
.statusCode(200)
.body("errors[0].errorType", equalTo("OperationNotSupported"));
}
@Test
void whitespaceOnlyQueryReturns200SyntaxError() {
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\" \"}")
.when()
.post("/v1/apis/" + apiId + "/graphql")
.then()
.statusCode(200)
.body("errors[0].errorType", equalTo("SyntaxError"));
}
@Test
void rehydrateFromSchemaStoreEnablesExecute() {
String hydrateApi = createApi("hydrate-" + UUID.randomUUID().toString().substring(0, 8));
startSchema(hydrateApi, "type Query { hello: String }");
awaitSchemaSuccess(hydrateApi);
schemaRegistry.remove(hydrateApi);
assertTrue(schemaRegistry.getSchema(hydrateApi).isEmpty());
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + hydrateApi + "/graphql")
.then()
.statusCode(502);
// invoke rehydrate via worker (package-visible through CDI bean)
rehydrateWorker().rehydrateSchemas();
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"query\":\"{ hello }\"}")
.when()
.post("/v1/apis/" + hydrateApi + "/graphql")
.then()
.statusCode(200)
.body("data.hello", nullValue());
}
@Inject
io.github.hectorvent.floci.services.appsync.graphql.SchemaCreationWorker schemaCreationWorker;
private io.github.hectorvent.floci.services.appsync.graphql.SchemaCreationWorker rehydrateWorker() {
return schemaCreationWorker;
}
private static String createApi(String name) {
return given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("""
{"name": "%s", "authenticationType": "API_KEY"}
""".formatted(name))
.when()
.post("/v1/apis")
.then()
.statusCode(200)
.extract().path("graphqlApi.apiId");
}
private static void startSchema(String apiId, String definition) {
String escaped = definition.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n");
given()
.header("Authorization", AUTH)
.contentType("application/json")
.body("{\"definition\": \"" + escaped + "\"}")
.when()
.post("/v1/apis/" + apiId + "/schemacreation")
.then()
.statusCode(200)
.body("status", equalTo("PROCESSING"));
}
private static void awaitSchemaSuccess(String apiId) {
await().atMost(Duration.ofSeconds(10))
.pollInterval(Duration.ofMillis(25))
.until(() -> {
String status = given()
.header("Authorization", AUTH)
.when()
.get("/v1/apis/" + apiId + "/schemacreation")
.then()
.statusCode(200)
.extract().path("status");
return "SUCCESS".equals(status);
});
}
}
@@ -0,0 +1,119 @@
package io.github.hectorvent.floci.services.appsync.graphql;
import graphql.ErrorType;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQLError;
import graphql.GraphqlErrorBuilder;
import graphql.language.SourceLocation;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class AppSyncErrorFormatterTest {
private final AppSyncErrorFormatter formatter = new AppSyncErrorFormatter();
@Test
void invalidSyntaxMapsToTopLevelSyntaxError() {
GraphQLError syntaxError = GraphqlErrorBuilder.newError()
.message("Invalid syntax near '{'")
.errorType(ErrorType.InvalidSyntax)
.location(new SourceLocation(1, 1))
.build();
ExecutionResult result = ExecutionResultImpl.newExecutionResult()
.addError(syntaxError)
.build();
Map<String, Object> response = formatter.format(result);
assertFalse(response.containsKey("data"));
@SuppressWarnings("unchecked")
List<Map<String, Object>> errors = (List<Map<String, Object>>) response.get("errors");
assertEquals(1, errors.size());
Map<String, Object> error = errors.get(0);
assertEquals("Invalid syntax near '{'", error.get("message"));
assertEquals("SyntaxError", error.get("errorType"));
assertTrue(error.containsKey("errorInfo"));
assertNull(error.get("errorInfo"));
assertFalse(error.containsKey("extensions"));
}
@Test
void validationErrorUsesTopLevelErrorTypeNotExtensionsOnly() {
GraphQLError validationError = GraphqlErrorBuilder.newError()
.message("Validation error of type FieldUndefined: Field 'nope' is undefined")
.errorType(ErrorType.ValidationError)
.location(new SourceLocation(1, 3))
.path(List.of("nope"))
.build();
ExecutionResult result = ExecutionResultImpl.newExecutionResult()
.data(null)
.addError(validationError)
.build();
Map<String, Object> response = formatter.format(result);
@SuppressWarnings("unchecked")
List<Map<String, Object>> errors = (List<Map<String, Object>>) response.get("errors");
Map<String, Object> error = errors.get(0);
assertEquals("ValidationError", error.get("errorType"));
assertTrue(error.containsKey("errorInfo"));
assertNull(error.get("errorInfo"));
assertEquals(List.of("nope"), error.get("path"));
assertFalse(error.containsKey("extensions"),
"AppSync wire uses top-level errorType, not extensions-only classification");
}
@Test
void emptyBodyMessageMatchesAppSyncSample() {
Map<String, Object> response = formatter.transportError(
"MalformedHttpRequestException",
AppSyncErrorFormatter.MSG_EMPTY_BODY);
@SuppressWarnings("unchecked")
List<Map<String, Object>> errors = (List<Map<String, Object>>) response.get("errors");
assertEquals(1, errors.size());
assertEquals("MalformedHttpRequestException", errors.get(0).get("errorType"));
assertEquals("Request body is empty.", errors.get(0).get("message"));
}
@Test
void unparseableBodyMessageMatchesAppSyncSample() {
Map<String, Object> forBraces = formatter.transportError(
"MalformedHttpRequestException",
AppSyncErrorFormatter.MSG_UNABLE_TO_PARSE);
Map<String, Object> forArray = formatter.transportError(
"MalformedHttpRequestException",
AppSyncErrorFormatter.MSG_UNABLE_TO_PARSE);
assertEquals("Unable to parse GraphQL query.",
((List<?>) forBraces.get("errors")).isEmpty() ? null
: ((Map<?, ?>) ((List<?>) forBraces.get("errors")).get(0)).get("message"));
assertEquals("Unable to parse GraphQL query.",
((Map<?, ?>) ((List<?>) forArray.get("errors")).get(0)).get("message"));
}
@Test
void successfulDataIncludedWithoutErrors() {
Map<String, Object> data = new java.util.LinkedHashMap<>();
data.put("hello", null);
ExecutionResult result = ExecutionResultImpl.newExecutionResult()
.data(data)
.build();
Map<String, Object> response = formatter.format(result);
@SuppressWarnings("unchecked")
Map<String, Object> responseData = (Map<String, Object>) response.get("data");
assertNull(responseData.get("hello"));
assertTrue(responseData.containsKey("hello"));
assertFalse(response.containsKey("errors"));
}
}
@@ -0,0 +1,121 @@
package io.github.hectorvent.floci.services.appsync.graphql;
import com.fasterxml.jackson.databind.ObjectMapper;
import graphql.GraphQL;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.appsync.AppSyncService;
import io.github.hectorvent.floci.services.appsync.model.GraphqlApi;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class AppSyncExecutionControllerTest {
@Mock
AppSyncService appSyncService;
@Mock
SchemaRegistry schemaRegistry;
@Mock
QueryExecutor queryExecutor;
private AppSyncExecutionController controller;
private HttpHeaders jsonHeaders;
@BeforeEach
void setUp() {
controller = new AppSyncExecutionController(
appSyncService,
schemaRegistry,
queryExecutor,
new AppSyncErrorFormatter(),
new ObjectMapper());
jsonHeaders = mock(HttpHeaders.class);
when(jsonHeaders.getHeaderString(HttpHeaders.CONTENT_TYPE)).thenReturn("application/json");
}
@Test
void unexpectedExecutorFailureReturns500InternalFailure() {
when(appSyncService.getGraphqlApi("api-1")).thenReturn(new GraphqlApi());
when(schemaRegistry.getGraphQL("api-1")).thenReturn(Optional.of(mock(GraphQL.class)));
when(queryExecutor.execute(any(GraphQL.class), eq("{ hello }"), isNull(), isNull()))
.thenThrow(new RuntimeException("boom"));
Response response = controller.execute("api-1", jsonHeaders, "{\"query\":\"{ hello }\"}");
assertEquals(500, response.getStatus());
assertEquals("InternalFailure", response.getHeaderString("x-amzn-errortype"));
@SuppressWarnings("unchecked")
Map<String, Object> body = (Map<String, Object>) response.getEntity();
assertNotNull(body.get("errors"));
@SuppressWarnings("unchecked")
Map<String, Object> error = ((List<Map<String, Object>>) body.get("errors")).get(0);
assertEquals("InternalFailure", error.get("errorType"));
assertEquals("InternalFailure", error.get("message"));
}
@Test
void emptyBodyReturns400WithErrorTypeHeader() {
Response response = controller.execute("api-1", jsonHeaders, "");
assertEquals(400, response.getStatus());
assertEquals("MalformedHttpRequestException", response.getHeaderString("x-amzn-errortype"));
@SuppressWarnings("unchecked")
Map<String, Object> body = (Map<String, Object>) response.getEntity();
@SuppressWarnings("unchecked")
Map<String, Object> error = ((List<Map<String, Object>>) body.get("errors")).get(0);
assertEquals("MalformedHttpRequestException", error.get("errorType"));
assertEquals(AppSyncErrorFormatter.MSG_EMPTY_BODY, error.get("message"));
}
@Test
void unknownApiReturns404WithErrorTypeHeader() {
when(appSyncService.getGraphqlApi("missing"))
.thenThrow(new AwsException("NotFoundException", "API not found", 404));
Response response = controller.execute("missing", jsonHeaders, "{\"query\":\"{ hello }\"}");
assertEquals(404, response.getStatus());
assertEquals("NotFoundException", response.getHeaderString("x-amzn-errortype"));
@SuppressWarnings("unchecked")
Map<String, Object> body = (Map<String, Object>) response.getEntity();
@SuppressWarnings("unchecked")
Map<String, Object> error = ((List<Map<String, Object>>) body.get("errors")).get(0);
assertEquals("NotFoundException", error.get("errorType"));
}
@Test
void non404AwsExceptionFromLookupReturnsDataPlaneInternalFailure() {
when(appSyncService.getGraphqlApi("api-1"))
.thenThrow(new AwsException("BadRequestException", "unexpected management error", 400));
Response response = controller.execute("api-1", jsonHeaders, "{\"query\":\"{ hello }\"}");
assertEquals(500, response.getStatus());
assertEquals("InternalFailure", response.getHeaderString("x-amzn-errortype"));
@SuppressWarnings("unchecked")
Map<String, Object> body = (Map<String, Object>) response.getEntity();
assertNotNull(body.get("errors"));
@SuppressWarnings("unchecked")
Map<String, Object> error = ((List<Map<String, Object>>) body.get("errors")).get(0);
assertEquals("InternalFailure", error.get("errorType"));
assertEquals("InternalFailure", error.get("message"));
}
}
@@ -0,0 +1,115 @@
package io.github.hectorvent.floci.services.appsync.graphql;
import graphql.schema.GraphQLSchema;
import io.github.hectorvent.floci.services.appsync.graphql.scalars.AppSyncScalarRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class QueryExecutorTest {
private QueryExecutor executor;
private GraphQLSchema helloSchema;
private GraphQLSchema subscriptionSchema;
private GraphQLSchema multiOpSchema;
@BeforeEach
void setUp() {
AppSyncErrorFormatter formatter = new AppSyncErrorFormatter();
executor = new QueryExecutor(formatter);
AppSyncSchemaParser parser = new AppSyncSchemaParser(new AppSyncScalarRegistry());
helloSchema = parser.parse("type Query { hello: String }");
subscriptionSchema = parser.parse("""
type Query { hello: String }
type Subscription { onHello: String }
""");
multiOpSchema = parser.parse("""
type Query {
hello: String
bye: String
}
""");
}
@Test
void nullableFieldReturnsNullWithoutDataFetcher() {
Map<String, Object> response = executor.execute(helloSchema, "{ hello }", null, null);
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) response.get("data");
assertTrue(data.containsKey("hello"));
assertNull(data.get("hello"));
assertTrue(!response.containsKey("errors") || ((List<?>) response.get("errors")).isEmpty());
}
@Test
void usesAsyncStrategiesAndSupportsSimpleQuery() {
Map<String, Object> response = executor.execute(helloSchema, "query Q { hello }", Map.of(), "Q");
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) response.get("data");
assertNull(data.get("hello"));
}
@Test
void httpSubscriptionReturnsOperationNotSupported() {
Map<String, Object> response = executor.execute(
subscriptionSchema,
"subscription { onHello }",
null,
null);
assertTrue(response.containsKey("errors"));
@SuppressWarnings("unchecked")
List<Map<String, Object>> errors = (List<Map<String, Object>>) response.get("errors");
assertEquals(1, errors.size());
assertEquals("OperationNotSupported", errors.get(0).get("errorType"));
Object data = response.get("data");
if (data != null) {
assertTrue(!(data instanceof org.reactivestreams.Publisher),
"Must not return Publisher JSON for HTTP subscriptions");
}
}
@Test
void missingOperationNameWithMultipleOpsThrowsBadRequest() {
AppSyncTransportException ex = assertThrows(AppSyncTransportException.class, () ->
executor.execute(multiOpSchema, """
query A { hello }
query B { bye }
""", null, null));
assertEquals(400, ex.getHttpStatus());
assertEquals("BadRequestException", ex.getErrorType());
assertEquals("Missing operation name.", ex.getMessage());
}
@Test
void operationNameSelectsAmongMultipleOps() {
Map<String, Object> response = executor.execute(multiOpSchema, """
query A { hello }
query B { bye }
""", null, "B");
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) response.get("data");
assertTrue(data.containsKey("bye"));
assertNull(data.get("bye"));
}
@Test
void syntaxErrorFormattedAsSyntaxError() {
Map<String, Object> response = executor.execute(helloSchema, "{ hello", null, null);
@SuppressWarnings("unchecked")
List<Map<String, Object>> errors = (List<Map<String, Object>>) response.get("errors");
assertEquals("SyntaxError", errors.get(0).get("errorType"));
}
}
@@ -0,0 +1,91 @@
package io.github.hectorvent.floci.services.appsync.graphql;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.services.appsync.graphql.scalars.AppSyncScalarRegistry;
import io.github.hectorvent.floci.services.appsync.model.SchemaCreationStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.LinkedHashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class SchemaCreationWorkerRehydrateTest {
@Mock
AccountAwareStorageBackend<SchemaCreationStatus> schemaStatusStore;
@Mock
AccountAwareStorageBackend<String> schemaStore;
@Mock
EmulatorConfig config;
private SchemaRegistry schemaRegistry;
private SchemaCreationWorker worker;
@BeforeEach
void setUp() {
schemaRegistry = new SchemaRegistry(new AppSyncSchemaParser(new AppSyncScalarRegistry()));
worker = new SchemaCreationWorker(
schemaRegistry, schemaStatusStore, schemaStore, config, new ObjectMapper());
}
@Test
void rehydrateRegistersSdlFromSchemaStore() {
when(schemaStore.scanAllAccountsAsMap())
.thenReturn(Map.of("api-1", "type Query { hello: String }"));
worker.rehydrateSchemas();
assertTrue(schemaRegistry.getSchema("api-1").isPresent());
assertTrue(schemaRegistry.getGraphQL("api-1").isPresent());
}
@Test
void rehydrateLoadsSchemasFromNonDefaultAccounts() {
// Startup has no request context; keys()/get() would only see the default account.
// scanAllAccountsAsMap must surface SDLs stored under other accounts.
Map<String, String> acrossAccounts = new LinkedHashMap<>();
acrossAccounts.put("default-api", "type Query { fromDefault: String }");
acrossAccounts.put("other-acct-api", "type Query { fromOther: String }");
when(schemaStore.scanAllAccountsAsMap()).thenReturn(acrossAccounts);
worker.rehydrateSchemas();
assertTrue(schemaRegistry.getSchema("default-api").isPresent());
assertTrue(schemaRegistry.getSchema("other-acct-api").isPresent());
assertTrue(schemaRegistry.getGraphQL("other-acct-api").isPresent());
verify(schemaStore, never()).keys();
verify(schemaStore, never()).get(anyString());
}
@Test
void rehydrateSkipsUnparseableSdl() {
when(schemaStore.scanAllAccountsAsMap())
.thenReturn(Map.of("bad-api", "not valid sdl {{{"));
worker.rehydrateSchemas();
assertTrue(schemaRegistry.getSchema("bad-api").isEmpty());
}
@Test
void rehydrateSkipsBlankEntries() {
when(schemaStore.scanAllAccountsAsMap()).thenReturn(Map.of("empty", " "));
worker.rehydrateSchemas();
assertTrue(schemaRegistry.getSchema("empty").isEmpty());
verify(schemaStore, never()).put(anyString(), anyString());
}
}
@@ -0,0 +1,55 @@
package io.github.hectorvent.floci.services.appsync.graphql;
import graphql.GraphQL;
import io.github.hectorvent.floci.services.appsync.graphql.scalars.AppSyncScalarRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SchemaRegistryTest {
private static final String SDL = "type Query { hello: String }";
private SchemaRegistry registry;
@BeforeEach
void setUp() {
registry = new SchemaRegistry(new AppSyncSchemaParser(new AppSyncScalarRegistry()));
}
@Test
void getGraphQLReturnsSameInstanceAcrossCalls() {
registry.register("api-1", SDL);
GraphQL first = registry.getGraphQL("api-1").orElseThrow();
GraphQL second = registry.getGraphQL("api-1").orElseThrow();
assertSame(first, second);
}
@Test
void removeClearsCachedGraphQL() {
registry.register("api-1", SDL);
assertTrue(registry.getGraphQL("api-1").isPresent());
registry.remove("api-1");
assertTrue(registry.getGraphQL("api-1").isEmpty());
assertTrue(registry.getSchema("api-1").isEmpty());
}
@Test
void reregisterReplacesCachedGraphQL() {
registry.register("api-1", SDL);
GraphQL original = registry.getGraphQL("api-1").orElseThrow();
registry.register("api-1", "type Query { bye: String }");
GraphQL replaced = registry.getGraphQL("api-1").orElseThrow();
assertNotSame(original, replaced);
assertSame(replaced, registry.getGraphQL("api-1").orElseThrow());
}
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
import io.github.hectorvent.floci.services.cloudformation.model.StackInstance;
@@ -100,10 +101,10 @@ class StackSetServiceDeleteFailureTest {
}
@Override
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
}
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudfront;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.cloudfront.model.Distribution;
import io.github.hectorvent.floci.services.cloudfront.model.StreamingDistribution;
@@ -20,7 +21,7 @@ class CloudFrontServiceTest {
private CloudFrontService serviceWithDomainSuffix(String domainSuffix) {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.codebuild.model.Build;
import io.github.hectorvent.floci.services.codebuild.model.Project;
@@ -149,10 +150,10 @@ class CodeBuildServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.codedeploy.model.DeploymentGroup;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
@@ -112,10 +113,10 @@ class CodeDeployServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -1,6 +1,6 @@
package io.github.hectorvent.floci.services.cognito.verification;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -30,7 +30,7 @@ class VerificationCodeServiceTest {
void setUp() {
clock = new MutableClock(Instant.parse("2026-05-15T12:00:00Z"));
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> new InMemoryStorage<>());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
service = new VerificationCodeService(storageFactory, clock);
}
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.configservice.model.ConfigRule;
import io.github.hectorvent.floci.services.configservice.model.ConfigRuleSource;
@@ -93,10 +94,10 @@ class AwsConfigServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -2,7 +2,7 @@ package io.github.hectorvent.floci.services.docdb;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.docdb.container.DocDbContainerManager;
import io.github.hectorvent.floci.services.docdb.model.DocDbCluster;
@@ -29,7 +29,7 @@ class DocDbServiceTest {
void setUp() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> new InMemoryStorage<>());
.thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager;
import io.github.hectorvent.floci.services.ec2.model.IpPermission;
@@ -259,9 +260,9 @@ class Ec2ServiceConcurrencyTest {
}
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
}
@@ -3,8 +3,7 @@ package io.github.hectorvent.floci.services.ec2;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager;
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
@@ -396,7 +395,7 @@ class Ec2ServiceTest {
@Test
void describeSnapshotsDefaultsToOwnedSnapshots() {
InMemoryStorage<String, Snapshot> snapshotStore = new InMemoryStorage<>();
AccountAwareStorageBackend<Snapshot> snapshotStore = AccountAwareStorageBackend.inMemory("000000000000");
Snapshot foreign = new Snapshot();
foreign.setSnapshotId("snap-foreign");
foreign.setOwnerId("111111111111");
@@ -834,26 +833,26 @@ class Ec2ServiceTest {
}
private static final class InMemoryStorageFactory extends StorageFactory {
private final Map<String, StorageBackend<String, ?>> overrides;
private final Map<String, AccountAwareStorageBackend<?>> overrides;
private InMemoryStorageFactory() {
this(Map.of());
}
private InMemoryStorageFactory(Map<String, StorageBackend<String, ?>> overrides) {
private InMemoryStorageFactory(Map<String, AccountAwareStorageBackend<?>> overrides) {
super(null, null);
this.overrides = overrides;
}
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
StorageBackend<String, ?> override = overrides.get(fileName);
AccountAwareStorageBackend<?> override = overrides.get(fileName);
if (override != null) {
return (StorageBackend<String, V>) override;
return (AccountAwareStorageBackend<V>) override;
}
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
}
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ecs.container.EcsContainerManager;
import io.github.hectorvent.floci.services.ecs.model.Attribute;
@@ -127,10 +128,10 @@ class EcsServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ecs.container.EcsContainerManager;
import io.github.hectorvent.floci.services.ecs.container.EcsTaskHandle;
@@ -127,10 +128,10 @@ class EcsServiceTeardownTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -32,9 +32,9 @@ class EksOidcServiceTest {
void setUp() {
oidcService = new EksOidcService(new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}, new ObjectMapper());
}
@@ -83,9 +83,9 @@ class EksOidcServiceTest {
EksOidcService service = new EksOidcService(new StorageFactory(null, null) {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) accountAware;
return (AccountAwareStorageBackend<V>) accountAware;
}
}, new ObjectMapper());
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ec2.AmiImageResolver;
import io.github.hectorvent.floci.services.ec2.Ec2ContainerManager;
@@ -51,9 +52,9 @@ class EksServiceTest {
void setUp() {
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
@@ -131,9 +132,9 @@ class EksServiceTest {
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
@@ -287,9 +288,13 @@ class EksServiceTest {
private StorageFactory fixedStorageFactory(StorageBackend<String, ?> backend) {
return new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) backend;
if (backend instanceof AccountAwareStorageBackend<?> aware) {
return (AccountAwareStorageBackend<V>) aware;
}
return new AccountAwareStorageBackend<>(
(StorageBackend<String, V>) backend, null, "000000000000");
}
};
}
@@ -309,9 +314,9 @@ class EksServiceTest {
void createClusterWithNonExistentSubnetFails() {
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
@@ -336,9 +341,9 @@ class EksServiceTest {
void createClusterWithExistingSubnetSucceeds() {
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
@@ -369,9 +374,9 @@ class EksServiceTest {
// resolved Subnet, which carries the vpcId; it was simply discarded.
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
@@ -398,9 +403,9 @@ class EksServiceTest {
// the validation half.
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
RegionResolver regionResolver = new RegionResolver("eu-west-2", "000000000000");
@@ -437,9 +442,9 @@ class EksServiceTest {
// behaviour.
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
Ec2Service ec2Service = realEc2Service();
@@ -2,7 +2,7 @@ package io.github.hectorvent.floci.services.elasticache;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerHandle;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheMemcachedContainerManager;
@@ -38,7 +38,7 @@ class ElastiCacheMemcachedServiceTest {
when(ecConfig.defaultMemcachedImage()).thenReturn("memcached:1.6");
when(config.hostname()).thenReturn(Optional.of("localhost"));
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> new InMemoryStorage<>());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(containerManager.start(anyString(), anyString()))
.thenReturn(new ElastiCacheContainerHandle("cid", "cluster", "localhost", 11211));
@@ -110,7 +110,7 @@ class ElastiCacheMemcachedServiceTest {
when(ecConfig.defaultMemcachedImage()).thenReturn("memcached:1.6");
when(config.hostname()).thenReturn(Optional.empty());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> new InMemoryStorage<>());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(containerManager.start(anyString(), anyString()))
.thenReturn(new ElastiCacheContainerHandle("cid", "cluster", "172.20.0.10", 11211));
@@ -2,7 +2,7 @@ package io.github.hectorvent.floci.services.elasticache;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerHandle;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
@@ -53,7 +53,7 @@ class ElastiCacheServiceTest {
when(ecConfig.defaultImage()).thenReturn("valkey/valkey:8");
when(config.hostname()).thenReturn(java.util.Optional.of("localhost"));
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> new InMemoryStorage<>());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(containerManager.start(anyString(), anyString()))
.thenReturn(new ElastiCacheContainerHandle("cid", "grp", "localhost", 6379));
doNothing().when(proxyManager).startProxy(anyString(), any(), anyInt(), anyString(), anyInt(), any());
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.elasticbeanstalk.model.BeanstalkApplication;
import io.github.hectorvent.floci.services.elasticbeanstalk.model.BeanstalkApplicationVersion;
@@ -118,10 +119,10 @@ class ElasticBeanstalkServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.Subnet;
@@ -334,10 +335,10 @@ class ElbV2ServiceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.firehose;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.S3Destination;
@@ -34,7 +35,7 @@ class FirehoseServiceTest {
void setUp() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
s3Service = Mockito.mock(S3Service.class);
firehoseService = new FirehoseService(storageFactory, s3Service,
new RegionResolver("us-east-1", "000000000000"), new MutableClock());
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.glue.schemaregistry.GlueSchemaRegistryService;
import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsTaggingService;
@@ -83,10 +84,10 @@ class GlueJsonHandlerEmptyListTest {
}
@Override
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
}
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.glue.model.Column;
import io.github.hectorvent.floci.services.glue.model.Database;
@@ -1032,10 +1033,10 @@ class GlueServiceTest {
}
@Override
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
}
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager;
import jakarta.ws.rs.core.Response;
@@ -413,7 +414,7 @@ class KinesisAnalyticsV2JsonHandlerTest {
private KinesisAnalyticsV2Service mockModeService() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -3,7 +3,7 @@ package io.github.hectorvent.floci.services.kinesisanalytics;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager;
import io.github.hectorvent.floci.services.kinesisanalytics.model.ApplicationStatus;
@@ -552,9 +552,10 @@ class KinesisAnalyticsV2ServiceTest {
// intermediate state must still be persisted — not just the final RUNNING transition — since
// pendingJars (a separate in-process-only cache) is already cleared by then; an emulator
// restart before the next persist would otherwise leave the application permanently stuck.
InMemoryStorage<String, FlinkApplication> backing = Mockito.spy(new InMemoryStorage<>());
AccountAwareStorageBackend<FlinkApplication> store =
Mockito.spy(AccountAwareStorageBackend.inMemory("000000000000"));
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
Mockito.doReturn(backing).when(storageFactory)
Mockito.doReturn(store).when(storageFactory)
.create(Mockito.anyString(), Mockito.anyString(), Mockito.any());
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
@@ -580,7 +581,7 @@ class KinesisAnalyticsV2ServiceTest {
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
FlinkApplication app = realMode.describeApplication("demo");
app.setApplicationStatus(ApplicationStatus.STARTING);
Mockito.clearInvocations(backing); // ignore createApplication's own put()
Mockito.clearInvocations(store); // ignore createApplication's own put()
try {
// @PostConstruct isn't wired by a plain `new` in this unit test; start the poller manually.
@@ -588,7 +589,8 @@ class KinesisAnalyticsV2ServiceTest {
// The poller's first tick fires ~1s after scheduling; give it margin.
Thread.sleep(1500);
Mockito.verify(backing, Mockito.atLeastOnce()).put(Mockito.eq("demo"), Mockito.any());
Mockito.verify(store, Mockito.atLeastOnce())
.putForAccount(Mockito.eq("000000000000"), Mockito.eq("demo"), Mockito.any());
assertEquals("job-1", realMode.describeApplication("demo").getFlinkJobId());
} finally {
realMode.shutdown();
@@ -609,7 +611,7 @@ class KinesisAnalyticsV2ServiceTest {
private KinesisAnalyticsV2Service buildService(boolean mock, FlinkContainerManager manager) {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -109,13 +109,13 @@ class LambdaServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
// Wrap like the production factory does so the tests exercise the
// account-prefixed key space, not a bare backend.
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName,
ignored -> new AccountAwareStorageBackend<V>(new InMemoryStorage<>(), null, ACCOUNT_ID));
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName,
ignored -> AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
}
}
}
@@ -165,12 +165,12 @@ class LambdaMicrovmsServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
// Wrap like the production factory does so the tests exercise the
// account-prefixed key space, not a bare backend.
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> {
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> {
PersistentStorage<String, V> inner =
new PersistentStorage<>(directory.resolve(fileName), typeReference);
inner.load();
@@ -4,7 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.elasticache.proxy.SigV4Validator;
import io.github.hectorvent.floci.services.memorydb.container.MemoryDbContainerHandle;
@@ -71,7 +71,7 @@ class MemoryDbServiceTest {
AwsArnUtils.Arn.of(inv.getArgument(0), inv.getArgument(1),
"000000000000", inv.getArgument(2)).toString());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> new InMemoryStorage<>());
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(containerManager.start(anyString(), anyString()))
.thenReturn(new MemoryDbContainerHandle("cid", "cluster", "localhost", 6379));
doNothing().when(proxyManager).startProxy(anyString(), anyBoolean(), anyInt(), anyString(), anyInt(), any());
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.msk;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.msk.model.ClusterState;
import io.github.hectorvent.floci.services.msk.model.MskCluster;
@@ -26,7 +27,7 @@ class MskServiceTest {
void setUp() {
storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
config = Mockito.mock(EmulatorConfig.class);
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.docker.PortAllocator;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.mwaa.model.CreateEnvironmentRequest;
import io.github.hectorvent.floci.services.mwaa.model.Environment;
@@ -45,9 +46,9 @@ class MwaaServiceTest {
void setUp() {
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
@@ -329,9 +330,9 @@ class MwaaServiceTest {
void setUpRealMode() {
StorageFactory storageFactory = new StorageFactory(null, null) {
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
};
@@ -3,7 +3,7 @@ package io.github.hectorvent.floci.services.neptune;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.neptune.container.NeptuneContainerHandle;
import io.github.hectorvent.floci.services.neptune.container.NeptuneContainerManager;
@@ -57,7 +57,7 @@ class NeptuneServiceTest {
when(config.hostname()).thenReturn(Optional.of("localhost"));
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(inv -> new InMemoryStorage<>());
.thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(containerManager.start(anyString(), anyString(), any(NeptuneDbType.class)))
.thenReturn(new NeptuneContainerHandle("cid", "c", "localhost", 8182));
doNothing().when(proxyManager).startProxy(anyString(), anyInt(), anyString(), anyInt());
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.pipes;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.pipes.model.DesiredState;
import io.github.hectorvent.floci.services.pipes.model.Pipe;
@@ -26,7 +27,7 @@ class PipesServiceTest {
void setUp() {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
.thenReturn(new InMemoryStorage<>());
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.resourcegroupstagging;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.resourcegroupstagging.model.ResourceTagMapping;
import org.junit.jupiter.api.Test;
@@ -80,10 +81,10 @@ class ResourceGroupsTaggingServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ssm.model.Command;
import io.github.hectorvent.floci.services.ssm.model.CommandInvocation;
@@ -390,9 +391,9 @@ class SsmCommandServiceDirectExecutionTest {
}
@Override
public <V> StorageBackend<String, V> create(String serviceName, String fileName,
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return new InMemoryStorage<>();
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
}
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.transcribe.model.VocabularyInfo;
import org.junit.jupiter.api.Test;
@@ -65,10 +66,10 @@ class TranscribeServicePersistenceTest {
@Override
@SuppressWarnings("unchecked")
public <V> StorageBackend<String, V> create(String serviceName,
public <V> AccountAwareStorageBackend<V> create(String serviceName,
String fileName,
TypeReference<Map<String, V>> typeReference) {
return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}
@@ -39,7 +39,8 @@ public class RestAssuredJsonUtils {
RestAssured.config = RestAssured.config().encoderConfig(
EncoderConfig.encoderConfig()
.encodeContentTypeAs(CONTENT_TYPE_AWS_JSON_1_0, ContentType.JSON)
.encodeContentTypeAs(CONTENT_TYPE_AWS_JSON_1_1, ContentType.JSON));
.encodeContentTypeAs(CONTENT_TYPE_AWS_JSON_1_1, ContentType.JSON)
.encodeContentTypeAs("application/graphql", ContentType.JSON));
if (!RestAssured.filters().contains(AWS_CONTENT_TYPE_FILTER)) {
RestAssured.filters(AWS_CONTENT_TYPE_FILTER);