mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
* test(dynamodb): failing concurrency tests reproducing #571 Exercises DynamoDbService directly with a starting-gate CountDownLatch and @RepeatedTest(5) to catch read-check-mutate-put races that single-threaded tests cannot see. Scenarios cover: arithmetic if_not_exists counters, ADD updates, conditional PutItem/DeleteItem with attribute_exists/attribute_not_exists, mixed put+update on the same key, transactWriteItems (overlap and disjoint), batchWriteItem, and stream event ordering. Each scenario has a baseline single-threaded sibling. 30 of 51 executions fail on main, matching the races described in the plan. * fix(dynamodb): serialise single-item mutations with per-item locks Adds a per-(storageKey, itemKey) ReentrantLock registry and wraps the full read → check-condition → mutate → put → persist → stream-capture sequence inside putItem, updateItem, and deleteItem. Locks are created lazily on first access and never removed; ReentrantLock is used so the upcoming transaction path can re-enter these methods after acquiring each participant's lock. Unrelated items still run in parallel — only threads contending for the same item serialise, matching real DynamoDB's per-item linearisability. Fixes the updateItem, putItem, deleteItem, and stream-ordering scenarios in DynamoDbConcurrencyIntegrationTest. The transactWriteItems scenario still races and is addressed in the next commit. Refs #571. * fix(dynamodb): serialise transactWriteItems via total-ordered lock acquisition Resolves every participant's (storageKey, itemKey) up front, acquires each ReentrantLock in deterministic ascending order, then evaluates all conditions against a snapshot nobody else can mutate. Writes apply under the same locks; inner putItem/updateItem/deleteItem calls re-enter their lock for free. Fixes the last remaining DynamoDbConcurrencyIntegrationTest scenarios — the all-or-nothing transaction test now observes committed == versionA == versionB across repeated runs, and the disjoint-commute scenario proves the sort order prevents deadlock. Closes #571. * test(compat): end-to-end concurrency scenarios against running Floci Adds the four mandatory compatibility tests that exercise the same locking semantics through the AWS SDK over HTTP: concurrent UpdateItem arithmetic, concurrent PutItem(attribute_not_exists), concurrent overlapping TransactWriteItems, and mixed concurrent UpdateItem + PutItem. N=20 per scenario to keep CI fast; each scenario uses a CountDownLatch starting gate so client threads dispatch simultaneously and the server actually sees overlapping work. * docs(changelog): note the DynamoDB concurrency fix under [Unreleased] Flags the behaviour change for callers whose previously-racing UpdateItem/PutItem/TransactWriteItems calls will now see the ConditionalCheckFailedException or TransactionCanceledException that real DynamoDB would raise. * fix(dynamodb): harden transaction ordering and drop dangling plan references Addresses review feedback on #572: * Replace the delimited-string ordering key for transactWriteItems with a Comparator over TransactParticipant tuples. User-supplied PK/SK bytes can contain any character, so "storageKey + \0 + itemKey" is not an injective ordering — tuple comparison avoids the collision risk entirely. * Release a table's item locks alongside itemsByTable / itemStore in deleteTable so the registry tracks the table's lifetime instead of growing unboundedly across create/drop cycles. * Remove Javadoc and inline comment references to PLAN-dynamodb-concurrency.md, which was a local working doc and was never committed. Issue #571 stays as the public reference.
sdk-test-java
Compatibility tests for Floci using the AWS SDK for Java v2 (2.31.8).
Runs 313 tests across 16 test classes against a live Floci instance — no mocks.
Services Covered
| Test class | Description |
|---|---|
SsmTest |
Parameter Store — put, get, path, tags |
SqsTest |
Queues, send/receive/delete, DLQ, visibility |
SnsTest |
Topics, subscriptions, publish, SQS delivery |
S3Test |
Buckets, objects, tagging, copy, multipart, batch delete |
DynamoDbTest |
Tables, CRUD, batch, TTL, tags, streams |
DynamoDbScanConditionTests |
Scan filter and condition expressions |
LambdaTest |
Create/invoke/update/delete functions |
IamTest |
Users, roles, policies, access keys |
StsTest |
GetCallerIdentity, AssumeRole, GetSessionToken |
SecretsManagerTest |
Create/get/put/list/delete secrets, versioning, tags |
KmsTest |
Keys, aliases, encrypt/decrypt, data keys, sign/verify |
CloudWatchTest |
PutMetricData, ListMetrics, GetMetricStatistics, alarms |
CloudFormationVirtualHostTests |
Virtual host style S3 access via CloudFormation |
ApigwSfnJsonataCrudlTests |
API Gateway + Step Functions JSONata CRUDL integration |
Ec2Tests |
EC2 instances, VPCs, security groups, subnets |
EcsTests |
ECS clusters, task definitions, services |
Adding a New Test
Create a standard JUnit 5 test class in src/test/java/com/floci/test/. Tests run against a live Floci instance using real AWS SDK clients.
Requirements
- Java 17+
- Maven
Running
# All tests
mvn test -q
# Specific test class
mvn test -Dtest=S3Test
# Via just (from compatibility-tests/)
just test-java
Configuration
| Variable | Default | Description |
|---|---|---|
FLOCI_ENDPOINT |
http://localhost:4566 |
Floci emulator endpoint |
AWS credentials are always test / test / us-east-1.
Docker
docker build -t floci-sdk-java .
docker run --rm --network host floci-sdk-java
# Custom endpoint (macOS/Windows)
docker run --rm -e FLOCI_ENDPOINT=http://host.docker.internal:4566 floci-sdk-java