refactor(dynamodb): isolate backend operation execution (#4379)

* refactor(dynamodb): route wire operations through a backend seam

Rename the native wire handlers to NativeDynamoDbJsonHandler and NativeDynamoDbStreamsJsonHandler.
Add DynamoDbOperations as the raw operation seam, plus typed DynamoDbItemAccess and DynamoDbTableAccess contracts.
Add NativeDynamoDbBackend behind the seam and DynamoDbBackendSelector as the one immutable selection.
Keep DynamoDbJsonHandler and DynamoDbStreamsJsonHandler as thin entry points that resolve account and region.
Add RequestScopes.callAsChecked and let AslExecutor delegate to it.

* refactor(dynamodb): route Java consumers through DynamoDbFacade

DynamoDbFacade hands out the selected item and table capabilities and is
now the one DynamoDB Resource Explorer provider in place of DynamoDbService.
CloudFormation, Step Functions, the IAM condition context and the Redshift
backfill call it with an explicit scope; the IoT dynamoDBv2 action writes as
the rule's owning account.
This commit is contained in:
Mario Toffia authored and GitHub committed 2026-09-25 14:57:13 -04:00
1 parent 0be4d07111
commit 5bad6774f6
59 files changed
+4716 -3488

No files matched your search

@@ -3,7 +3,9 @@ package io.github.hectorvent.floci.core.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.backend.NativeDynamoDbBackend;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
@@ -43,7 +45,7 @@ class IamConditionContextResolverTest {
private final ObjectMapper mapper = new ObjectMapper();
private DynamoDbService dynamoDbService;
private Instance<DynamoDbService> dynamoDbServiceInstance;
private Instance<DynamoDbFacade> dynamoDbFacadeInstance;
private Ec2Service ec2Service;
private S3Service s3Service;
private RequestContext requestContext;
@@ -54,9 +56,11 @@ class IamConditionContextResolverTest {
@BeforeEach
void setUp() {
dynamoDbService = mock(DynamoDbService.class);
dynamoDbServiceInstance = mock(Instance.class);
when(dynamoDbServiceInstance.isResolvable()).thenReturn(true);
when(dynamoDbServiceInstance.get()).thenReturn(dynamoDbService);
NativeDynamoDbBackend dynamoDbBackend = new NativeDynamoDbBackend(null, null, dynamoDbService, mapper);
dynamoDbFacadeInstance = mock(Instance.class);
when(dynamoDbFacadeInstance.isResolvable()).thenReturn(true);
when(dynamoDbFacadeInstance.get()).thenReturn(new DynamoDbFacade(dynamoDbBackend, dynamoDbBackend,
new RegionResolver("us-east-1", "000000000000")));
ec2Service = mock(Ec2Service.class);
Instance<Ec2Service> ec2ServiceInstance = mock(Instance.class);
when(ec2ServiceInstance.isResolvable()).thenReturn(true);
@@ -70,7 +74,7 @@ class IamConditionContextResolverTest {
config = mock(EmulatorConfig.class);
when(config.defaultRegion()).thenReturn("us-east-1");
resolver = new IamConditionContextResolver(
dynamoDbServiceInstance, ec2ServiceInstance, s3ServiceInstance, requestContext, config);
dynamoDbFacadeInstance, ec2ServiceInstance, s3ServiceInstance, requestContext, config);
}
/** A form request whose body can be read again, as a real request's restored stream can. */
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
import io.github.hectorvent.floci.services.acm.AcmService;
import io.github.hectorvent.floci.services.apigateway.ApiGatewayService;
@@ -102,7 +103,9 @@ import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsService
import io.github.hectorvent.floci.services.cloudwatch.metrics.CloudWatchMetricsService;
import io.github.hectorvent.floci.services.cognito.CognitoService;
import io.github.hectorvent.floci.services.docdb.DocDbService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.backend.NativeDynamoDbBackend;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecr.EcrService;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -265,7 +268,9 @@ final class CfnProvisionerFixture {
discovered.add(new SnsCfnProvisioner(snsService));
}
if (dynamoDbService != null) {
discovered.add(new DynamoDbCfnProvisioner(dynamoDbService));
NativeDynamoDbBackend backend = new NativeDynamoDbBackend(null, null, dynamoDbService, objectMapper);
discovered.add(new DynamoDbCfnProvisioner(new DynamoDbFacade(backend, backend,
new RegionResolver("us-east-1", "000000000000"))));
}
if (ssmService != null) {
discovered.add(new SsmCfnProvisioner(ssmService));
@@ -3,9 +3,12 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.backend.NativeDynamoDbBackend;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import org.junit.jupiter.api.Test;
@@ -42,8 +45,10 @@ class DynamoDbCfnProvisionerTest {
private static final String STREAM_ARN = TABLE_ARN + "/stream/2026-01-01T00:00:00.000";
private final DynamoDbService dynamoDb = mock(DynamoDbService.class);
private final DynamoDbCfnProvisioner provisioner = new DynamoDbCfnProvisioner(dynamoDb);
private final ObjectMapper mapper = new ObjectMapper();
private final NativeDynamoDbBackend backend = new NativeDynamoDbBackend(null, null, dynamoDb, mapper);
private final DynamoDbCfnProvisioner provisioner = new DynamoDbCfnProvisioner(
new DynamoDbFacade(backend, backend, new RegionResolver("us-east-1", "000000000000")));
private ProvisionContext ctx() {
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
@@ -42,10 +42,10 @@ class DynamoDbGsiSortKeyRestartTest {
return store;
}
private DynamoDbJsonHandler handlerFor(StorageBackend<String, TableDefinition> store) {
private NativeDynamoDbJsonHandler handlerFor(StorageBackend<String, TableDefinition> store) {
DynamoDbService service = new DynamoDbService(
store, null, new RegionResolver(REGION, "000000000000"), null, null);
return new DynamoDbJsonHandler(service, null, null, mapper);
return new NativeDynamoDbJsonHandler(service, null, null, mapper);
}
private ObjectNode createTableWithGsiSortKeyRequest() {
@@ -82,7 +82,7 @@ class DynamoDbGsiSortKeyRestartTest {
void otherTablesSurviveEvenWhenOneHasAGsiRangeKey(@TempDir Path tmp) throws Exception {
Path file = tmp.resolve("dynamodb-tables.json");
StorageBackend<String, TableDefinition> store = diskStore(file);
DynamoDbJsonHandler handler = handlerFor(store);
NativeDynamoDbJsonHandler handler = handlerFor(store);
handler.handle("CreateTable", createTableWithGsiSortKeyRequest(), REGION);
ObjectNode plainTable = mapper.createObjectNode();
@@ -34,12 +34,12 @@ class DynamoDbItemSizeServiceTest {
private static final int SHORT_KEY_BYTES = 3;
private DynamoDbService service;
private DynamoDbJsonHandler handler;
private NativeDynamoDbJsonHandler handler;
@BeforeEach
void setUp() {
service = new DynamoDbService(new InMemoryStorage<>());
handler = new DynamoDbJsonHandler(service, null, null, new ObjectMapper());
handler = new NativeDynamoDbJsonHandler(service, null, null, new ObjectMapper());
service.createTable(TABLE, List.of(new KeySchemaElement("pk", "HASH")),
List.of(new AttributeDefinition("pk", "S")), 5L, 5L, REGION);
}
@@ -42,11 +42,11 @@ class DynamoDbStreamViewTypeDurabilityTest {
return store;
}
private DynamoDbJsonHandler handlerFor(StorageBackend<String, TableDefinition> store,
private NativeDynamoDbJsonHandler handlerFor(StorageBackend<String, TableDefinition> store,
DynamoDbStreamService streams) {
DynamoDbService service = new DynamoDbService(
store, null, new RegionResolver(REGION, "000000000000"), streams, null);
return new DynamoDbJsonHandler(service, streams, null, mapper);
return new NativeDynamoDbJsonHandler(service, streams, null, mapper);
}
private ObjectNode createTableRequest(String viewType) {
@@ -92,7 +92,7 @@ class DynamoDbStreamViewTypeDurabilityTest {
Path file = tmp.resolve("tables.json");
StorageBackend<String, TableDefinition> store = diskStore(file);
DynamoDbStreamService streams = new DynamoDbStreamService(mapper, store);
DynamoDbJsonHandler handler = handlerFor(store, streams);
NativeDynamoDbJsonHandler handler = handlerFor(store, streams);
handler.handle("CreateTable", createTableRequest("NEW_AND_OLD_IMAGES"), REGION);
handler.handle("UpdateTable", updateViewTypeRequest("KEYS_ONLY"), REGION);
@@ -28,17 +28,17 @@ import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
class DynamoDbJsonHandlerTest {
class NativeDynamoDbJsonHandlerTest {
private DynamoDbService service;
private ObjectMapper mapper;
private DynamoDbJsonHandler handler;
private NativeDynamoDbJsonHandler handler;
@BeforeEach
void setUp() {
service = new DynamoDbService(new InMemoryStorage<>());
mapper = new ObjectMapper();
handler = new DynamoDbJsonHandler(service, null, null, mapper);
handler = new NativeDynamoDbJsonHandler(service, null, null, mapper);
}
private TableDefinition createUsersTable(String region) {
@@ -368,7 +368,7 @@ class DynamoDbJsonHandlerTest {
TypeReference<Map<String, TableDefinition>> typeReference = new TypeReference<>() {};
DynamoDbService persistentService = new DynamoDbService(new PersistentStorage<>(tableFile, typeReference));
DynamoDbJsonHandler persistentHandler = new DynamoDbJsonHandler(persistentService, null, null, mapper);
NativeDynamoDbJsonHandler persistentHandler = new NativeDynamoDbJsonHandler(persistentService, null, null, mapper);
ObjectNode createRequest = mapper.createObjectNode();
createRequest.put("TableName", "PersistedSseTable");
@@ -0,0 +1,90 @@
package io.github.hectorvent.floci.services.dynamodb.backend;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Api;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Call;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Scope;
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** The one DynamoDB backend CDI selects, and the one Resource Explorer provider in front of it. */
@QuarkusTest
class DynamoDbBackendSelectionTest {
private static final String REGION = "us-east-1";
private static final Scope ACCOUNT_A = new Scope("210987654321", REGION);
private static final Scope ACCOUNT_B = new Scope("321098765432", REGION);
@Inject
DynamoDbOperations operations;
@Inject
DynamoDbItemAccess items;
@Inject
DynamoDbTableAccess tables;
// Collected exactly as ResourceExplorer2Service collects its providers.
@Inject
Instance<ResourceProvider> providers;
@Inject
ObjectMapper mapper;
@Test
void everyCapabilityIsTheOneNativeBackend() {
Object backend = ClientProxy.unwrap(operations);
assertInstanceOf(NativeDynamoDbBackend.class, backend);
assertSame(backend, ClientProxy.unwrap(items));
assertSame(backend, ClientProxy.unwrap(tables));
}
@Test
void theFacadeIsTheOnlyDynamoDbTableProvider() {
List<ResourceProvider> dynamoDbProviders = providers.stream()
.filter(provider -> provider.getSupportedResourceTypes().stream()
.anyMatch(type -> "dynamodb:table".equals(type.resourceType())))
.toList();
assertEquals(1, dynamoDbProviders.size());
assertInstanceOf(DynamoDbFacade.class, ClientProxy.unwrap(dynamoDbProviders.get(0)));
}
@Test
void callsRunUnderTheScopeAccount() throws Exception {
String tableName = "backend-scope-" + UUID.randomUUID();
tables.createTable(ACCOUNT_A, tableName, List.of(new KeySchemaElement("id", "HASH")),
List.of(new AttributeDefinition("id", "S")), 5L, 5L, List.of(), List.of());
try {
assertTrue(tables.findTable(ACCOUNT_B, tableName).isEmpty());
assertTrue(tables.findTable(ACCOUNT_A, tableName).isPresent());
ObjectNode body = mapper.createObjectNode().put("TableName", tableName);
AwsException notFound = assertThrows(AwsException.class,
() -> operations.execute(new Call(ACCOUNT_B, Api.DYNAMODB, "DescribeTable", body)));
assertEquals("ResourceNotFoundException", notFound.getErrorCode());
assertEquals(200, operations.execute(new Call(ACCOUNT_A, Api.DYNAMODB, "DescribeTable", body)).status());
} finally {
tables.deleteTable(ACCOUNT_A, tableName);
}
}
}
@@ -0,0 +1,199 @@
package io.github.hectorvent.floci.services.dynamodb.backend;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.config.FlociCertificateAuthority;
import io.github.hectorvent.floci.core.common.IamConditionContextResolver;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.DynamoDbCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.ProvisionContext;
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Scope;
import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend.Invocation;
import io.github.hectorvent.floci.services.firehose.FirehoseService;
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator;
import io.github.hectorvent.floci.services.iot.IotMqttBrokerService;
import io.github.hectorvent.floci.services.iot.IotPublishEventRecorder;
import io.github.hectorvent.floci.services.iot.IotService;
import io.github.hectorvent.floci.services.kinesis.KinesisService;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.sns.SnsService;
import io.github.hectorvent.floci.services.sqs.SqsService;
import jakarta.enterprise.inject.Instance;
import jakarta.ws.rs.container.ContainerRequestContext;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* The facade Java consumers of DynamoDB reach the engine through: it hands out the selected
* capabilities, scopes to the ambient account, and each consumer gives it the account and region
* it means. Every case runs against a recording backend, so nothing here touches native state.
*/
class DynamoDbFacadeTest {
private static final String DEFAULT_ACCOUNT = "000000000000";
private static final String DEFAULT_REGION = "us-east-1";
private static final String OWNER_ACCOUNT = "111122223333";
private static final String OTHER_REGION = "eu-west-1";
private final ObjectMapper mapper = new ObjectMapper();
private final RecordingDynamoDbBackend backend = new RecordingDynamoDbBackend();
private final DynamoDbFacade facade =
new DynamoDbFacade(backend, backend, new RegionResolver(DEFAULT_REGION, DEFAULT_ACCOUNT));
@Test
void scopeIsTheAmbientAccountInTheGivenRegion() {
assertEquals(new Scope(DEFAULT_ACCOUNT, OTHER_REGION), facade.scope(OTHER_REGION));
}
@Test
void resourcesAreListedForTheAmbientAccount() {
assertEquals(List.of(RecordingDynamoDbBackend.RESOURCE), facade.getResources());
assertEquals(List.of(new Invocation("resources", DEFAULT_ACCOUNT, null)), backend.invocations());
}
@Test
void supportedResourceTypeIsTheDynamoDbTable() {
assertEquals(Set.of(new SupportedResourceType("dynamodb:table", "dynamodb", true)),
facade.getSupportedResourceTypes());
}
@Test
void capabilitiesAreTheSelectedOnes() {
RecordingDynamoDbBackend items = new RecordingDynamoDbBackend();
RecordingDynamoDbBackend tables = new RecordingDynamoDbBackend();
DynamoDbFacade split = new DynamoDbFacade(items, tables, new RegionResolver(DEFAULT_REGION, DEFAULT_ACCOUNT));
assertSame(items, split.items());
assertSame(tables, split.tables());
}
@Test
void cloudFormationTableUsesTheStackRegion() throws Exception {
DynamoDbCfnProvisioner provisioner = new DynamoDbCfnProvisioner(facade);
StackResource table = cfnResource("Orders", "AWS::DynamoDB::Table");
provisioner.provision(table, mapper.readTree("{\"TableName\":\"orders\"}"),
cfnContext(DEFAULT_ACCOUNT, OTHER_REGION));
provisioner.delete("AWS::DynamoDB::Table", "orders", OTHER_REGION);
assertEquals(List.of(
new Invocation("createTable", DEFAULT_ACCOUNT, OTHER_REGION),
new Invocation("listTagsOfResource", DEFAULT_ACCOUNT, OTHER_REGION),
new Invocation("deleteTable", DEFAULT_ACCOUNT, OTHER_REGION)), backend.invocations());
}
@Test
void cloudFormationProvisionsUnderTheStackAccountRatherThanTheAmbientOne() throws Exception {
DynamoDbCfnProvisioner provisioner = new DynamoDbCfnProvisioner(facade);
ProvisionContext stack = cfnContext(OWNER_ACCOUNT, OTHER_REGION);
provisioner.provision(cfnResource("Orders", "AWS::DynamoDB::GlobalTable"), mapper.readTree("""
{"TableName": "orders", "Replicas": [{"Region": "us-west-2"}]}
"""), stack);
provisioner.provision(cfnResource("OrdersReplica", "Custom::DynamoDBReplica"), mapper.readTree("""
{"TableName": "orders", "Region": "ap-south-1"}
"""), stack);
assertEquals(List.of(
new Invocation("createTable", OWNER_ACCOUNT, OTHER_REGION),
new Invocation("listTagsOfResource", OWNER_ACCOUNT, OTHER_REGION),
new Invocation("describeTable", OWNER_ACCOUNT, OTHER_REGION),
new Invocation("ensureGlobalTable", OWNER_ACCOUNT, OTHER_REGION),
new Invocation("applyReplicaUpdates", OWNER_ACCOUNT, OTHER_REGION),
new Invocation("applyReplicaUpdates", OWNER_ACCOUNT, OTHER_REGION)), backend.invocations());
}
@Test
void iotDynamoDbRuleActionWritesAsTheRuleOwnerInTheRuleRegion() throws Exception {
// The rule is created by OWNER_ACCOUNT in OTHER_REGION, then fires with no request account,
// as an MQTT publish does: the action must write as the rule's owner, not the ambient default.
IotService iot = iotService(new RegionResolver(OTHER_REGION, OWNER_ACCOUNT));
iot.createTopicRule("toTable", mapper.readTree("""
{"sql": "SELECT * FROM 'devices/+/metrics'",
"actions": [{"dynamoDBv2": {"putItem": {"tableName": "metrics"},
"roleArn": "arn:aws:iam::111122223333:role/rule"}}]}
"""), OTHER_REGION);
iot.publish("devices/d1/metrics", "{\"t\":1}".getBytes(StandardCharsets.UTF_8), false, 0, null, "sensor-1");
assertEquals(List.of(new Invocation("putItem", OWNER_ACCOUNT, OTHER_REGION)), backend.invocations());
}
@Test
@SuppressWarnings("unchecked")
void iamConditionContextFindsTheTableInTheRequestRegion() throws Exception {
Instance<DynamoDbFacade> dynamoDb = mock(Instance.class);
when(dynamoDb.isResolvable()).thenReturn(true);
when(dynamoDb.get()).thenReturn(facade);
RequestContext requestContext = new RequestContext();
requestContext.setRegion(OTHER_REGION);
IamConditionContextResolver resolver = new IamConditionContextResolver(dynamoDb,
mock(Instance.class), mock(Instance.class), requestContext, mock(EmulatorConfig.class));
ContainerRequestContext request = mock(ContainerRequestContext.class);
JsonNode body = mapper.readTree("""
{"TableName": "recorded-table", "Key": {"id": {"S": "USER_alice"}}}
""");
when(request.getProperty("floci.bufferedJsonBody")).thenReturn(body);
Map<String, List<String>> conditions = resolver.resolve("dynamodb", "dynamodb:GetItem", request);
assertEquals(List.of("USER_alice"), conditions.get("dynamodb:LeadingKeys"));
assertEquals(List.of(new Invocation("findTable", DEFAULT_ACCOUNT, OTHER_REGION)), backend.invocations());
}
private StackResource cfnResource(String logicalId, String type) {
StackResource resource = new StackResource();
resource.setLogicalId(logicalId);
resource.setResourceType(type);
resource.setAttributes(new HashMap<>());
return resource;
}
private ProvisionContext cfnContext(String accountId, String region) {
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
when(engine.resolve(any())).thenAnswer(invocation -> {
JsonNode node = invocation.getArgument(0);
return node == null ? null : node.asText();
});
when(engine.resolveNode(any())).thenAnswer(invocation -> invocation.getArgument(0));
return new ProvisionContext(engine, region, accountId, "stack");
}
private IotService iotService(RegionResolver regionResolver) {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory(DEFAULT_ACCOUNT));
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.defaultRegion()).thenReturn(DEFAULT_REGION);
when(config.defaultAccountId()).thenReturn(DEFAULT_ACCOUNT);
when(config.services().iot().ruleSqlStrict()).thenReturn(false);
return new IotService(storageFactory, config, regionResolver, mapper, new IotPublishEventRecorder(),
mock(IotMqttBrokerService.class), mock(SqsService.class), mock(SnsService.class),
mock(S3Service.class), mock(KinesisService.class), facade, mock(LambdaService.class),
mock(FirehoseService.class), mock(CloudWatchLogsService.class),
mock(FlociCertificateAuthority.class), new IamPolicyEvaluator(mapper));
}
}
@@ -0,0 +1,195 @@
package io.github.hectorvent.floci.services.dynamodb.backend;
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.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamsJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.KinesisStreamingForwarder;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbStreamsJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbTableService;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Api;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Call;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Reply;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Scope;
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
import io.github.hectorvent.floci.services.kinesis.KinesisService;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
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.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** The native engine behind the DynamoDB seam, and the thin public handlers in front of it. */
class DynamoDbNativeBackendTest {
private static final String ACCOUNT = "000000000000";
private static final String REGION = "us-east-1";
private static final Scope SCOPE = new Scope(ACCOUNT, REGION);
private static final String TABLE = "orders";
private final ObjectMapper mapper = new ObjectMapper();
private NativeDynamoDbBackend backend;
@BeforeEach
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory(ACCOUNT));
DynamoDbStreamService streams = new DynamoDbStreamService(mapper, storageFactory);
DynamoDbService service = new DynamoDbService(storageFactory, new RegionResolver(REGION, ACCOUNT), streams,
mock(KinesisStreamingForwarder.class), null, mapper, mock(EmulatorConfig.class, RETURNS_DEEP_STUBS));
NativeDynamoDbTableService tables = new NativeDynamoDbTableService(service, streams, mock(KinesisService.class));
backend = new NativeDynamoDbBackend(new NativeDynamoDbJsonHandler(service, tables, mapper),
new NativeDynamoDbStreamsJsonHandler(streams, service, mapper), service, mapper);
}
private Reply call(Api api, String action, JsonNode body) throws Exception {
return backend.execute(new Call(SCOPE, api, action, body));
}
private Reply createTable(String extraFields) throws Exception {
return call(Api.DYNAMODB, "CreateTable", json("""
{"TableName":"%s",
"KeySchema":[{"AttributeName":"id","KeyType":"HASH"}],
"AttributeDefinitions":[{"AttributeName":"id","AttributeType":"S"}],
"BillingMode":"PAY_PER_REQUEST"%s}
""".formatted(TABLE, extraFields)));
}
private JsonNode json(String text) throws Exception {
return mapper.readTree(text);
}
@Test
void rawDeleteTableHonoursDeletionProtectionWhileTypedDeleteDoesNot() throws Exception {
createTable(",\"DeletionProtectionEnabled\":true");
AwsException refused = assertThrows(AwsException.class,
() -> call(Api.DYNAMODB, "DeleteTable", json("{\"TableName\":\"" + TABLE + "\"}")));
assertEquals("ValidationException", refused.getErrorCode());
assertTrue(backend.findTable(SCOPE, TABLE).isPresent());
backend.deleteTable(SCOPE, TABLE);
assertTrue(backend.findTable(SCOPE, TABLE).isEmpty());
}
@Test
void typedUpdateItemReturnsOnlyTheRequestedImage() throws Exception {
backend.createTable(SCOPE, TABLE, List.of(new KeySchemaElement("id", "HASH")),
List.of(new AttributeDefinition("id", "S")), 5L, 5L, List.of(), List.of());
JsonNode key = json("{\"id\":{\"S\":\"k\"}}");
backend.putItem(SCOPE, TABLE, json("{\"id\":{\"S\":\"k\"},\"n\":{\"N\":\"1\"}}"), null, null, null);
JsonNode names = json("{\"#n\":\"n\"}");
JsonNode newImage = backend.updateItem(SCOPE, TABLE, key, null, "SET #n = :v", names,
json("{\":v\":{\"N\":\"2\"}}"), "ALL_NEW", null);
JsonNode oldImage = backend.updateItem(SCOPE, TABLE, key, null, "SET #n = :v", names,
json("{\":v\":{\"N\":\"3\"}}"), "ALL_OLD", null);
JsonNode none = backend.updateItem(SCOPE, TABLE, key, null, "SET #n = :v", names,
json("{\":v\":{\"N\":\"4\"}}"), "NONE", null);
JsonNode updatedNew = backend.updateItem(SCOPE, TABLE, key, null, "SET #n = :v", names,
json("{\":v\":{\"N\":\"5\"}}"), "UPDATED_NEW", null);
assertEquals(json("{\"id\":{\"S\":\"k\"},\"n\":{\"N\":\"2\"}}"), newImage);
assertEquals(json("{\"id\":{\"S\":\"k\"},\"n\":{\"N\":\"2\"}}"), oldImage);
assertNull(none);
assertNull(updatedNew);
assertEquals(json("{\"id\":{\"S\":\"k\"},\"n\":{\"N\":\"5\"}}"), backend.getItem(SCOPE, TABLE, key));
}
@Test
void unknownActionRepliesWithAJsonErrorBody() throws Exception {
Reply reply = call(Api.DYNAMODB, "NoSuchAction", mapper.createObjectNode());
assertEquals(400, reply.status());
assertEquals("UnknownOperationException", reply.body().path("__type").asText());
assertEquals("Operation NoSuchAction is not supported.", reply.body().path("message").asText());
}
@Test
void rawCallsRoundTripAnItem() throws Exception {
JsonNode item = json("{\"id\":{\"S\":\"a\"},\"v\":{\"S\":\"x\"}}");
assertEquals(200, createTable("").status());
ObjectNode put = mapper.createObjectNode().put("TableName", TABLE);
put.set("Item", item);
assertEquals(200, call(Api.DYNAMODB, "PutItem", put).status());
ObjectNode get = mapper.createObjectNode().put("TableName", TABLE);
get.set("Key", json("{\"id\":{\"S\":\"a\"}}"));
Reply reply = call(Api.DYNAMODB, "GetItem", get);
assertEquals(200, reply.status());
assertEquals(item, reply.body().path("Item"));
}
@Test
void streamsCallsReachTheStreamsHandler() throws Exception {
createTable(",\"StreamSpecification\":{\"StreamEnabled\":true,\"StreamViewType\":\"NEW_IMAGE\"}");
Reply reply = call(Api.DYNAMODB_STREAMS, "ListStreams", mapper.createObjectNode());
assertEquals(200, reply.status());
assertTrue(reply.body().path("Streams").isArray());
assertEquals(TABLE, reply.body().path("Streams").path(0).path("TableName").asText());
}
@Test
void scopeRejectsBlankAccountAndRegion() {
IllegalArgumentException account = assertThrows(IllegalArgumentException.class, () -> new Scope(" ", REGION));
IllegalArgumentException region = assertThrows(IllegalArgumentException.class, () -> new Scope(ACCOUNT, ""));
assertTrue(account.getMessage().contains("accountId"));
assertTrue(region.getMessage().contains("region"));
assertThrows(IllegalArgumentException.class, () -> new Scope(null, REGION));
assertThrows(IllegalArgumentException.class, () -> new Scope(ACCOUNT, null));
}
@Test
void thinHandlersPassTheCallersScopeAndRebuildTheReply() throws Exception {
List<Call> calls = new ArrayList<>();
JsonNode replyBody = json("{\"ok\":true}");
DynamoDbOperations recording = call -> {
calls.add(call);
return new Reply(201, replyBody, Map.of("X-Test", List.of("a", "b")));
};
RegionResolver resolver = new RegionResolver("eu-west-1", "111122223333");
JsonNode request = mapper.createObjectNode();
Response response = new DynamoDbJsonHandler(recording, resolver).handle("GetItem", request, "ap-south-1");
new DynamoDbJsonHandler(recording, resolver).handle("GetItem", request, null);
new DynamoDbStreamsJsonHandler(recording, resolver).handle("ListStreams", request, "ap-south-1");
assertEquals(new Call(new Scope("111122223333", "ap-south-1"), Api.DYNAMODB, "GetItem", request),
calls.get(0));
assertSame(request, calls.get(0).body());
assertEquals(new Scope("111122223333", "eu-west-1"), calls.get(1).scope());
assertEquals(Api.DYNAMODB_STREAMS, calls.get(2).api());
assertEquals(201, response.getStatus());
assertSame(replyBody, response.getEntity());
assertEquals(List.of("a", "b"), response.getStringHeaders().get("X-Test"));
}
}
@@ -0,0 +1,151 @@
package io.github.hectorvent.floci.services.dynamodb.backend;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Scope;
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.GlobalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
import io.github.hectorvent.floci.services.dynamodb.model.LocalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* A DynamoDB backend with no state: each typed call is recorded with the account and region it
* was given and answered with a canned value, so a test can see exactly what a consumer asked for.
*/
public final class RecordingDynamoDbBackend implements DynamoDbItemAccess, DynamoDbTableAccess {
/** One typed call. {@code region} is null for {@code resources}, which takes an account only. */
public record Invocation(String method, String accountId, String region) {
public static Invocation of(String method, Scope scope) {
return new Invocation(method, scope.accountId(), scope.region());
}
}
public static final String TABLE_NAME = "recorded-table";
public static final String TABLE_ARN = "arn:aws:dynamodb:us-east-1:000000000000:table/" + TABLE_NAME;
public static final ExplorerResource RESOURCE = new ExplorerResource(TABLE_ARN, "dynamodb:table", "dynamodb",
"us-east-1", "000000000000", Instant.EPOCH, Map.of());
private final List<Invocation> invocations = new CopyOnWriteArrayList<>();
public List<Invocation> invocations() {
return List.copyOf(invocations);
}
private TableDefinition record(String method, Scope scope) {
invocations.add(Invocation.of(method, scope));
TableDefinition table = new TableDefinition();
table.setTableName(TABLE_NAME);
table.setTableArn(TABLE_ARN);
table.setKeySchema(List.of(new KeySchemaElement("id", "HASH")));
return table;
}
@Override
public void putItem(Scope scope, String tableName, JsonNode item, String conditionExpression,
JsonNode expressionAttributeNames, JsonNode expressionAttributeValues) {
record("putItem", scope);
}
@Override
public JsonNode getItem(Scope scope, String tableName, JsonNode key) {
record("getItem", scope);
return null;
}
@Override
public void deleteItem(Scope scope, String tableName, JsonNode key, String conditionExpression,
JsonNode expressionAttributeNames, JsonNode expressionAttributeValues) {
record("deleteItem", scope);
}
@Override
public JsonNode updateItem(Scope scope, String tableName, JsonNode key, JsonNode attributeUpdates,
String updateExpression, JsonNode expressionAttributeNames,
JsonNode expressionAttributeValues, String returnValues, String conditionExpression) {
record("updateItem", scope);
return null;
}
@Override
public ScanPage scan(Scope scope, String tableName, String filterExpression, JsonNode expressionAttributeNames,
JsonNode expressionAttributeValues, JsonNode scanFilter, Integer limit,
JsonNode exclusiveStartKey) {
record("scan", scope);
return new ScanPage(List.of(), 0, null);
}
@Override
public TableDefinition createTable(Scope scope, String tableName, List<KeySchemaElement> keySchema,
List<AttributeDefinition> attributeDefinitions, Long readCapacity,
Long writeCapacity, List<GlobalSecondaryIndex> globalSecondaryIndexes,
List<LocalSecondaryIndex> localSecondaryIndexes) {
return record("createTable", scope);
}
@Override
public TableDefinition describeTable(Scope scope, String tableName) {
return record("describeTable", scope);
}
@Override
public Optional<TableDefinition> findTable(Scope scope, String tableName) {
return Optional.of(record("findTable", scope));
}
@Override
public void deleteTable(Scope scope, String tableName) {
record("deleteTable", scope);
}
@Override
public TableDefinition enableStream(Scope scope, String tableName, String viewType) {
return record("enableStream", scope);
}
@Override
public TableDefinition disableStream(Scope scope, String tableName) {
return record("disableStream", scope);
}
@Override
public Map<String, String> listTagsOfResource(Scope scope, String resourceArn) {
record("listTagsOfResource", scope);
return Map.of();
}
@Override
public void tagResource(Scope scope, String resourceArn, Map<String, String> tags) {
record("tagResource", scope);
}
@Override
public void untagResource(Scope scope, String resourceArn, List<String> tagKeys) {
record("untagResource", scope);
}
@Override
public TableDefinition applyReplicaUpdates(Scope scope, String tableName, List<String> addRegions,
List<String> removeRegions) {
return record("applyReplicaUpdates", scope);
}
@Override
public TableDefinition ensureGlobalTable(Scope scope, String tableName) {
return record("ensureGlobalTable", scope);
}
@Override
public List<ExplorerResource> resources(String accountId) {
invocations.add(new Invocation("resources", accountId, null));
return List.of(RESOURCE);
}
}
@@ -8,7 +8,10 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbItemAccess;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbOperations.Scope;
import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbTableAccess;
import io.github.hectorvent.floci.services.firehose.FirehoseService;
import io.github.hectorvent.floci.services.firehose.model.Record;
import io.github.hectorvent.floci.services.iot.model.IotPolicy;
@@ -42,6 +45,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -68,7 +72,7 @@ class IotServiceTest {
private final ObjectMapper mapper = new ObjectMapper();
private final SqsService sqs = mock(SqsService.class);
private final LambdaService lambda = mock(LambdaService.class);
private final DynamoDbService dynamoDb = mock(DynamoDbService.class);
private final DynamoDbItemAccess dynamoDb = mock(DynamoDbItemAccess.class);
private final FirehoseService firehose = mock(FirehoseService.class);
private final CloudWatchLogsService logs = mock(CloudWatchLogsService.class);
private IotService service;
@@ -101,7 +105,7 @@ class IotServiceTest {
mock(SnsService.class),
mock(S3Service.class),
mock(KinesisService.class),
dynamoDb,
new DynamoDbFacade(dynamoDb, mock(DynamoDbTableAccess.class), new RegionResolver(REGION, ACCOUNT)),
lambda,
firehose,
logs,
@@ -452,7 +456,8 @@ class IotServiceTest {
private JsonNode capturedDynamoDbItem(String tableName) {
ArgumentCaptor<ObjectNode> item = ArgumentCaptor.forClass(ObjectNode.class);
verify(dynamoDb).putItem(eq(tableName), item.capture(), eq(REGION));
verify(dynamoDb).putItem(eq(new Scope(ACCOUNT, REGION)), eq(tableName), item.capture(),
isNull(), isNull(), isNull());
return item.getValue();
}
@@ -7,7 +7,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.services.cloudwatch.logs.CloudWatchLogsService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.firehose.FirehoseService;
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator;
import io.github.hectorvent.floci.services.iot.model.IotCertificate;
@@ -74,7 +74,7 @@ final class IotServiceTestSupport {
mock(SnsService.class),
mock(S3Service.class),
mock(KinesisService.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(LambdaService.class),
mock(FirehoseService.class),
mock(CloudWatchLogsService.class),
@@ -3,9 +3,13 @@ package io.github.hectorvent.floci.services.redshift;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamService;
import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend;
import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend.Invocation;
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.DynamoDbStreamRecord;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
@@ -39,6 +43,9 @@ class RedshiftDynamoDbZeroEtlConsumerTest {
@Inject
DynamoDbService dynamoDbService;
@Inject
DynamoDbFacade dynamoDb;
@Test
void writesRecordsAndAdvancesCheckpointOnlyAfterSuccessfulBatch() {
DynamoDbStreamService streamService = mock(DynamoDbStreamService.class);
@@ -58,7 +65,7 @@ class RedshiftDynamoDbZeroEtlConsumerTest {
.thenReturn(record.getSequenceNumber());
RedshiftDynamoDbZeroEtlConsumer consumer =
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDbService, redshiftService, writer);
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDb, redshiftService, writer);
consumer.pollOnce(integration);
verify(writer).createLandingTable(integration.getAccountId(), "warehouse", "floci_zetl_orders");
@@ -92,7 +99,7 @@ class RedshiftDynamoDbZeroEtlConsumerTest {
assertThrows(AwsException.class, () -> dynamoDbService.describeTable(tableName, "us-east-1"));
RedshiftDynamoDbZeroEtlConsumer consumer =
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDbService, redshiftService, writer);
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDb, redshiftService, writer);
consumer.pollOnce(integration);
assertFalse(integration.isBackfillCompleted());
@@ -129,7 +136,7 @@ class RedshiftDynamoDbZeroEtlConsumerTest {
assertThrows(AwsException.class, () -> dynamoDbService.describeTable(tableName, "us-east-1"));
RedshiftDynamoDbZeroEtlConsumer consumer =
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDbService, redshiftService, writer);
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDb, redshiftService, writer);
consumer.pollOnce(integration);
assertTrue(integration.isBackfillCompleted());
@@ -156,7 +163,7 @@ class RedshiftDynamoDbZeroEtlConsumerTest {
});
RedshiftDynamoDbZeroEtlConsumer consumer =
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDbService, redshiftService, writer);
new RedshiftDynamoDbZeroEtlConsumer(streamService, dynamoDb, redshiftService, writer);
consumer.pollOnce(integration);
integration.setBackfillCompleted(false);
consumer.pollOnce(integration);
@@ -168,6 +175,21 @@ class RedshiftDynamoDbZeroEtlConsumerTest {
captor.getAllValues().get(1).get(0).getEventId());
}
@Test
void backfillReadsTheTableAsTheIntegrationAccountInTheStreamRegion() {
RecordingDynamoDbBackend backend = new RecordingDynamoDbBackend();
DynamoDbFacade recording = new DynamoDbFacade(backend, backend, new RegionResolver("us-east-1", "000000000000"));
Integration integration = integration("orders");
integration.setSourceStreamArn("arn:aws:dynamodb:eu-west-1:111111111111:table/orders/stream/one");
new RedshiftDynamoDbZeroEtlConsumer(mock(DynamoDbStreamService.class), recording,
mock(RedshiftService.class), mock(RedshiftZeroEtlWriter.class)).pollOnce(integration);
assertEquals(List.of(
new Invocation("describeTable", "111111111111", "eu-west-1"),
new Invocation("scan", "111111111111", "eu-west-1")), backend.invocations());
}
private static ObjectNode itemWithId(String id) {
ObjectNode item = MAPPER.createObjectNode();
ObjectNode idAttr = MAPPER.createObjectNode();
@@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -53,7 +53,7 @@ class AslExecutorArrayAndMathIntrinsicsTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class),
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -67,7 +67,7 @@ class AslExecutorBranchHistoryEventsTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
@@ -83,7 +83,7 @@ class AslExecutorCatchTest {
executor = new AslExecutor(
lambdaExecutor,
functionStore,
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -46,7 +46,7 @@ class AslExecutorChoiceRuntimeTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.CustomResourceLiveness;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
@@ -77,7 +77,7 @@ class AslExecutorCustomResourceLivenessTest {
executor = new AslExecutor(
lambdaExecutor,
functionStore,
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
@@ -65,7 +65,7 @@ class AslExecutorEcsRunTaskModeTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -75,7 +75,7 @@ class AslExecutorErrorTerminationTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -53,7 +53,7 @@ class AslExecutorFailStateErrorCauseTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class),
mock(io.github.hectorvent.floci.services.sns.SnsJsonHandler.class),
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -190,7 +190,7 @@ class AslExecutorHistoryEventLimitTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
@@ -162,7 +162,7 @@ class AslExecutorHttpInvokeTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -5,8 +5,8 @@ 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.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -56,7 +56,7 @@ class AslExecutorIntrinsicFunctionsTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.sns.SnsJsonHandler;
@@ -36,7 +36,7 @@ class AslExecutorIntrinsicMissingArgumentTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -41,7 +41,7 @@ class AslExecutorJsonMergeTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaAliasStore;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
@@ -86,7 +86,7 @@ class AslExecutorLambdaInvokeResultTest {
executor = new AslExecutor(
lambdaExecutor,
new LambdaTargetResolver(functionStore, aliasStore),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -56,7 +56,7 @@ class AslExecutorMockedResponsesTest {
executor = new AslExecutor(
lambdaExecutor,
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -60,7 +60,7 @@ class AslExecutorNestedQueryLanguageTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -72,7 +72,7 @@ class AslExecutorNestedStartExecutionTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class),
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.sns.SnsJsonHandler;
@@ -35,7 +35,7 @@ class AslExecutorPathIntrinsicsTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -45,7 +45,7 @@ class AslExecutorResultPathTest {
void setUp() {
executor = new AslExecutor(
mock(LambdaExecutorService.class), mock(LambdaFunctionStore.class),
mock(DynamoDbService.class), mock(DynamoDbJsonHandler.class), mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(DynamoDbFacade.class), mock(DynamoDbJsonHandler.class), mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class), mock(Ec2Service.class), mock(S3Service.class),
mock(EcsService.class), mock(EcsJsonHandler.class),
mock(io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler.class),
@@ -6,8 +6,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -62,7 +62,7 @@ class AslExecutorResultWriterTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
@@ -77,7 +77,7 @@ class AslExecutorRetryTest {
executor = new AslExecutor(
lambdaExecutor,
functionStore,
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -39,7 +39,7 @@ class AslExecutorStatePathTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(CloudFormationQueryHandler.class),
@@ -2,8 +2,11 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend;
import io.github.hectorvent.floci.services.dynamodb.backend.RecordingDynamoDbBackend.Invocation;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
@@ -59,17 +62,24 @@ class AslExecutorTaskHistoryEventsTest {
@Inject
Vertx vertx;
@Inject
RegionResolver regionResolver;
@BeforeEach
void setUp() {
lambdaExecutor = mock(LambdaExecutorService.class);
functionStore = mock(LambdaFunctionStore.class);
executor = newExecutor(mock(DynamoDbFacade.class));
}
private AslExecutor newExecutor(DynamoDbFacade dynamoDb) {
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().stepfunctions().maxWaitSeconds()).thenReturn(30);
executor = new AslExecutor(
return new AslExecutor(
lambdaExecutor,
functionStore,
mock(DynamoDbService.class),
dynamoDb,
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -86,6 +96,36 @@ class AslExecutorTaskHistoryEventsTest {
mock(io.github.hectorvent.floci.core.common.CustomResourceLiveness.class));
}
/**
* The optimized DynamoDB integration scopes to the ambient account, which the executor sets to
* the one in the state machine ARN, and to the state machine's region.
*/
@Test
void optimizedDynamoDbTaskRunsAsTheExecutionAccountInTheStateMachineRegion() {
RecordingDynamoDbBackend backend = new RecordingDynamoDbBackend();
AslExecutor recordingExecutor = newExecutor(new DynamoDbFacade(backend, backend, regionResolver));
StateMachine stateMachine = new StateMachine();
stateMachine.setName("ddb");
stateMachine.setStateMachineArn("arn:aws:states:eu-west-1:111122223333:stateMachine:ddb");
stateMachine.setRoleArn("arn:aws:iam::111122223333:role/test-role");
stateMachine.setDefinition("""
{"StartAt": "Put", "States": {"Put": {"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {"TableName": "orders", "Item": {"id": {"S": "k1"}}}, "End": true}}}
""");
Execution execution = new Execution();
execution.setName("ddb-execution");
execution.setExecutionArn("arn:aws:states:eu-west-1:111122223333:execution:ddb:ddb-execution");
execution.setStateMachineArn(stateMachine.getStateMachineArn());
execution.setInput("{}");
recordingExecutor.executeSync(stateMachine, execution, new ArrayList<>(), (updated, events) -> {
});
assertEquals("SUCCEEDED", execution.getStatus(), execution.getCause());
assertEquals(List.of(new Invocation("putItem", "111122223333", "eu-west-1")), backend.invocations());
}
@Test
void mockedTaskEmitsScheduledStartedSucceededInOrder() throws Exception {
var mocks = testCase(Map.of("Send", List.of(
@@ -2,8 +2,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -53,7 +53,7 @@ class AslExecutorTerminalStateTest {
executor = new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class), mock(SnsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
@@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.CustomResourceLiveness;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbFacade;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
import io.github.hectorvent.floci.services.ecs.EcsService;
@@ -166,7 +166,7 @@ class AslExecutorWaitStateTest {
return new AslExecutor(
mock(LambdaExecutorService.class),
mock(LambdaFunctionStore.class),
mock(DynamoDbService.class),
mock(DynamoDbFacade.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class),
mock(SnsJsonHandler.class),