Light, fluffy, and always free - The AWS Local Emulator alternative
chore: import fully qualified types in lambda and s3 (#6737)
Hector Ventura108110563e30
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.javaindex b6186c72de..dd0dd8a5d1 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/DynamoDbStreamsEventSourcePollerTest.java@@ -28,6 +28,8 @@ import io.github.hectorvent.floci.services.s3.model.Bucket;import io.github.hectorvent.floci.services.s3.model.ObjectAnnotation;import io.github.hectorvent.floci.services.s3.model.S3Object;import io.github.hectorvent.floci.services.s3.model.S3ObjectUpdatedEvent;+import io.github.hectorvent.floci.services.sns.SnsService;+import io.github.hectorvent.floci.services.sqs.SqsService;import io.quarkus.test.junit.QuarkusTest;import io.vertx.core.Vertx;import jakarta.enterprise.event.Event;@@ -105,9 +107,9 @@ class DynamoDbStreamsEventSourcePollerTest {private EsmStore esmStore;private EmulatorConfig config;private PipesFilterMatcher filterMatcher;- private io.github.hectorvent.floci.services.sqs.SqsService sqsService;- private io.github.hectorvent.floci.services.sns.SnsService snsService;- private io.github.hectorvent.floci.services.s3.S3Service s3Service;+ private SqsService sqsService;+ private SnsService snsService;+ private S3Service s3Service;private final AtomicLong clock = new AtomicLong();private final AtomicLong sequence = new AtomicLong();@@ -133,9 +135,9 @@ class DynamoDbStreamsEventSourcePollerTest {aliasStore = mock(LambdaAliasStore.class);esmStore = new EsmStore(new AccountAwareStorageBackend<>(new InMemoryStorage<>(), null, ACCOUNT_ID));filterMatcher = new PipesFilterMatcher(OBJECT_MAPPER);- sqsService = mock(io.github.hectorvent.floci.services.sqs.SqsService.class);- snsService = mock(io.github.hectorvent.floci.services.sns.SnsService.class);- s3Service = mock(io.github.hectorvent.floci.services.s3.S3Service.class);+ sqsService = mock(SqsService.class);+ snsService = mock(SnsService.class);+ s3Service = mock(S3Service.class);poller = pollerOver(reader, esmStore);}@@ -946,8 +948,8 @@ class DynamoDbStreamsEventSourcePollerTest {invocation -> requestContextInstance.get().getAccountId());s3Service = new S3Service(storageFactory, config,- mock(io.github.hectorvent.floci.services.sqs.SqsService.class),- mock(io.github.hectorvent.floci.services.sns.SnsService.class),+ mock(SqsService.class),+ mock(SnsService.class),mock(Instance.class), mock(EventBridgeService.class), mock(Event.class),regionResolver, OBJECT_MAPPER, mock(IamService.class));diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaImageConfigTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaImageConfigTest.javaindex b329a2d678..c951c3a00f 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaImageConfigTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaImageConfigTest.java@@ -16,6 +16,7 @@ import io.github.hectorvent.floci.core.storage.InMemoryStorage;import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;import io.github.hectorvent.floci.services.lambda.launcher.ContainerLauncher;import io.github.hectorvent.floci.services.lambda.launcher.ImageResolver;+import io.github.hectorvent.floci.services.lambda.launcher.LambdaExecutionRoleCredentials;import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;import io.github.hectorvent.floci.services.lambda.runtime.RuntimeApiServer;import io.github.hectorvent.floci.services.lambda.runtime.RuntimeApiServerFactory;@@ -30,6 +31,8 @@ import org.mockito.ArgumentCaptor;import org.mockito.Mock;import org.mockito.junit.jupiter.MockitoExtension;+import java.io.InputStream;+import java.io.OutputStream;import java.nio.file.Path;import java.util.HashMap;import java.util.List;@@ -251,8 +254,8 @@ class LambdaImageConfigTest {LaunchedContainerAwsEnv awsEnv = new LaunchedContainerAwsEnv(reachableEndpoint);launcher = new ContainerLauncher(containerBuilder, lifecycleManager, logStreamer, imageResolver,runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager,- mock(io.github.hectorvent.floci.services.lambda.LambdaLayerService.class), awsEnv,- mock(io.github.hectorvent.floci.services.lambda.launcher.LambdaExecutionRoleCredentials.class));+ mock(LambdaLayerService.class), awsEnv,+ mock(LambdaExecutionRoleCredentials.class));when(runtimeApiServerFactory.create()).thenReturn(runtimeApiServer);when(runtimeApiServer.getPort()).thenReturn(9000);@@ -264,7 +267,7 @@ class LambdaImageConfigTest {lenient().when(dockerClient.copyArchiveToContainerCmd(any())).thenAnswer(inv -> {CopyArchiveToContainerCmd cmd = mock(CopyArchiveToContainerCmd.class);- final java.io.InputStream[] captured = {null};+ final InputStream[] captured = {null};when(cmd.withRemotePath(any())).thenReturn(cmd);when(cmd.withTarInputStream(any())).thenAnswer(streamInv -> {captured[0] = streamInv.getArgument(0);@@ -272,7 +275,7 @@ class LambdaImageConfigTest {});doAnswer(execInv -> {if (captured[0] != null) {- try { captured[0].transferTo(java.io.OutputStream.nullOutputStream()); }+ try { captured[0].transferTo(OutputStream.nullOutputStream()); }catch (Exception ignored) {}}return null;diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.javaindex d94fbbd571..0affdd850e 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/SqsEventSourcePollerTest.java@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;import io.github.hectorvent.floci.services.pipes.PipesFilterMatcher;import io.github.hectorvent.floci.services.sqs.SqsService;import io.github.hectorvent.floci.services.sqs.model.Message;+import io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue;import io.vertx.core.Vertx;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;@@ -19,6 +20,8 @@ import org.junit.jupiter.params.provider.ValueSource;import org.mockito.ArgumentCaptor;import java.time.Instant;+import java.util.ArrayList;+import java.util.Base64;import java.util.List;import java.util.Map;import java.util.Optional;@@ -118,8 +121,8 @@ class SqsEventSourcePollerTest {msg.setBody("hello");msg.setSentTimestamp(Instant.now());- io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue attr =- new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("red", "String");+ MessageAttributeValue attr =+ new MessageAttributeValue("red", "String");msg.getMessageAttributes().put("color", attr);msg.updateMd5OfMessageAttributes();@@ -153,8 +156,8 @@ class SqsEventSourcePollerTest {msg.setBody("order");msg.setSentTimestamp(Instant.now());- io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue attr =- new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("42", "Number");+ MessageAttributeValue attr =+ new MessageAttributeValue("42", "Number");msg.getMessageAttributes().put("count", attr);EventSourceMapping esm = new EventSourceMapping();@@ -176,8 +179,8 @@ class SqsEventSourcePollerTest {msg.setSentTimestamp(Instant.now());byte[] raw = {1, 2, 3};- io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue attr =- new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue(raw, "Binary");+ MessageAttributeValue attr =+ new MessageAttributeValue(raw, "Binary");msg.getMessageAttributes().put("data", attr);EventSourceMapping esm = new EventSourceMapping();@@ -191,16 +194,16 @@ class SqsEventSourcePollerTest {assertEquals("Binary", data.get("dataType").asText());assertNull(data.get("stringValue"));assertEquals(- java.util.Base64.getEncoder().encodeToString(raw),+ Base64.getEncoder().encodeToString(raw),data.get("binaryValue").asText());}@Testvoid buildSqsEventHandlesMultipleAttributesAcrossMultipleMessages() throws Exception {- io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue a1 =- new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("v1", "String");- io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue a2 =- new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue("v2", "String");+ MessageAttributeValue a1 =+ new MessageAttributeValue("v1", "String");+ MessageAttributeValue a2 =+ new MessageAttributeValue("v2", "String");Message msg1 = new Message();msg1.setBody("m1");@@ -462,7 +465,7 @@ class SqsEventSourcePollerTest {esm.setBatchSize(batchSize);if (patterns.length > 0) {EventSourceMapping.FilterCriteria fc = new EventSourceMapping.FilterCriteria();- List<EventSourceMapping.Filter> filters = new java.util.ArrayList<>();+ List<EventSourceMapping.Filter> filters = new ArrayList<>();for (String p : patterns) {EventSourceMapping.Filter f = new EventSourceMapping.Filter();f.setPattern(p);diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.javaindex 5ba6a1cf45..70f606bc06 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncherTest.java@@ -47,17 +47,23 @@ import org.mockito.InOrder;import org.mockito.Mock;import org.mockito.junit.jupiter.MockitoExtension;+import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;+import java.io.InputStream;+import java.io.OutputStream;import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Path;+import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import java.util.Optional;import java.util.OptionalInt;+import java.util.UUID;import java.util.concurrent.CompletableFuture;+import java.util.concurrent.CountDownLatch;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicBoolean;import java.util.stream.Stream;@@ -96,7 +102,7 @@ class ContainerLauncherTest {ContainerLauncher launcher;/** Collects remote paths passed to withRemotePath across all copy mocks. */- final java.util.List<String> capturedRemotePaths = new java.util.ArrayList<>();+ final List<String> capturedRemotePaths = new ArrayList<>();String capturedRuntimeBootstrap;final Map<String, String> capturedLayerFiles = new LinkedHashMap<>();@@ -175,7 +181,7 @@ class ContainerLauncherTest {capturedLayerFiles.clear();lenient().when(dockerClient.copyArchiveToContainerCmd(any())).thenAnswer(inv -> {CopyArchiveToContainerCmd cmd = mock(CopyArchiveToContainerCmd.class);- final java.io.InputStream[] captured = {null};+ final InputStream[] captured = {null};String[] remote = {null};when(cmd.withRemotePath(any())).thenAnswer(pathInv -> {capturedRemotePaths.add(pathInv.getArgument(0));@@ -207,7 +213,7 @@ class ContainerLauncherTest {}return null;}- try { captured[0].transferTo(java.io.OutputStream.nullOutputStream()); }+ try { captured[0].transferTo(OutputStream.nullOutputStream()); }catch (Exception ignored) {}}return null;@@ -1109,7 +1115,7 @@ class ContainerLauncherTest {assertTrue(spec.binds().stream().anyMatch(b -> b.getPath().equals("/home/user/.aws")&& b.getVolume().getPath().equals("/opt/aws-config")- && b.getAccessMode() == com.github.dockerjava.api.model.AccessMode.ro),+ && b.getAccessMode() == AccessMode.ro),"awsConfigPath should be bind-mounted read-only to /opt/aws-config");// Should set explicit file paths for SDK discovery@@ -1663,12 +1669,12 @@ class ContainerLauncherTest {when(lifecycleManager.volumeExists(volumeV1)).thenReturn(true);- java.util.concurrent.CountDownLatch cleanupHoldingLock = new java.util.concurrent.CountDownLatch(1);- java.util.concurrent.CountDownLatch releaseCleanup = new java.util.concurrent.CountDownLatch(1);+ CountDownLatch cleanupHoldingLock = new CountDownLatch(1);+ CountDownLatch releaseCleanup = new CountDownLatch(1);doAnswer(inv -> {cleanupHoldingLock.countDown();// Blocks here while still holding volumeV1's per-volume lock, simulating a slow delete.- assertTrue(releaseCleanup.await(5, java.util.concurrent.TimeUnit.SECONDS),+ assertTrue(releaseCleanup.await(5, TimeUnit.SECONDS),"test did not release cleanup in time");return null;}).when(lifecycleManager).removeVolume(volumeV1);@@ -1682,11 +1688,11 @@ class ContainerLauncherTest {Thread cleanupThread = new Thread(launcher::cleanupSupersededVolumes);cleanupThread.start();- assertTrue(cleanupHoldingLock.await(5, java.util.concurrent.TimeUnit.SECONDS),+ assertTrue(cleanupHoldingLock.await(5, TimeUnit.SECONDS),"cleanup never reached removeVolume");- java.util.concurrent.atomic.AtomicBoolean rollbackReturned =- new java.util.concurrent.atomic.AtomicBoolean(false);+ AtomicBoolean rollbackReturned =+ new AtomicBoolean(false);Thread rollbackThread = new Thread(() -> {launcher.launch(v1);rollbackReturned.set(true);@@ -1749,16 +1755,16 @@ class ContainerLauncherTest {// helper-container create() call instead of the real container's.launcher.launch(v1);- java.util.concurrent.CountDownLatch launchReachedCreate = new java.util.concurrent.CountDownLatch(1);- java.util.concurrent.CountDownLatch releaseLaunch = new java.util.concurrent.CountDownLatch(1);- java.util.concurrent.atomic.AtomicBoolean blockedOnce = new java.util.concurrent.atomic.AtomicBoolean(false);+ CountDownLatch launchReachedCreate = new CountDownLatch(1);+ CountDownLatch releaseLaunch = new CountDownLatch(1);+ AtomicBoolean blockedOnce = new AtomicBoolean(false);doAnswer(inv -> {if (blockedOnce.compareAndSet(false, true)) {// Only the delayed re-launch of v1 (the first caller after this stub is// installed) blocks here; v2's later launch below must not, or the test would// deadlock itself waiting on its own main thread to release the latch.launchReachedCreate.countDown();- assertTrue(releaseLaunch.await(5, java.util.concurrent.TimeUnit.SECONDS),+ assertTrue(releaseLaunch.await(5, TimeUnit.SECONDS),"test did not release the delayed launch in time");}return "container-123";@@ -1766,7 +1772,7 @@ class ContainerLauncherTest {Thread launchThread = new Thread(() -> launcher.launch(v1));launchThread.start();- assertTrue(launchReachedCreate.await(5, java.util.concurrent.TimeUnit.SECONDS),+ assertTrue(launchReachedCreate.await(5, TimeUnit.SECONDS),"v1's delayed re-launch never reached create()");assertEquals(1, launcher.inFlightCount(volumeV1),@@ -1821,13 +1827,13 @@ class ContainerLauncherTest {withLoweredCodeVolumeThreshold(() -> {Object functionLock = launcher.functionVolumeTransitionLockFor("xfn");- java.util.concurrent.CountDownLatch testHoldingLock = new java.util.concurrent.CountDownLatch(1);- java.util.concurrent.CountDownLatch releaseLock = new java.util.concurrent.CountDownLatch(1);+ CountDownLatch testHoldingLock = new CountDownLatch(1);+ CountDownLatch releaseLock = new CountDownLatch(1);Thread holderThread = new Thread(() -> {synchronized (functionLock) {testHoldingLock.countDown();try {- assertTrue(releaseLock.await(5, java.util.concurrent.TimeUnit.SECONDS),+ assertTrue(releaseLock.await(5, TimeUnit.SECONDS),"test did not release the function lock in time");} catch (InterruptedException e) {Thread.currentThread().interrupt();@@ -1835,7 +1841,7 @@ class ContainerLauncherTest {}});holderThread.start();- assertTrue(testHoldingLock.await(5, java.util.concurrent.TimeUnit.SECONDS),+ assertTrue(testHoldingLock.await(5, TimeUnit.SECONDS),"test thread never acquired the function lock");AtomicBoolean launchReturned = new AtomicBoolean(false);@@ -1921,7 +1927,7 @@ class ContainerLauncherTest {* (name -> executable), so filtering logic (non-executable files, nested paths) can be* exercised. Names containing "/" are written as-is (not prefixed), to model entries nested* more than one level below the extensions directory. */- private static byte[] tarOfRaw(java.util.Map<String, Boolean> nameToExecutable) throws IOException {+ private static byte[] tarOfRaw(Map<String, Boolean> nameToExecutable) throws IOException {ByteArrayOutputStream bos = new ByteArrayOutputStream();try (TarArchiveOutputStream tar = new TarArchiveOutputStream(bos)) {TarArchiveEntry dir = new TarArchiveEntry("extensions/");@@ -1952,16 +1958,16 @@ class ContainerLauncherTest {* calling {@code launch()} to assert on exactly which discovered names were (and weren't) launched. */private List<ExecCreateCmd> stubExtensionDiscoveryFromTar(byte[] tar) {CopyArchiveFromContainerCmd copyCmd = mock(CopyArchiveFromContainerCmd.class);- when(copyCmd.exec()).thenReturn(new java.io.ByteArrayInputStream(tar));+ when(copyCmd.exec()).thenReturn(new ByteArrayInputStream(tar));when(dockerClient.copyArchiveFromContainerCmd("container-123", "/opt/extensions")).thenReturn(copyCmd);- List<ExecCreateCmd> launchCmds = new java.util.ArrayList<>();+ List<ExecCreateCmd> launchCmds = new ArrayList<>();lenient().when(dockerClient.execCreateCmd("container-123")).thenAnswer(invocation -> {ExecCreateCmd launchCmd = mock(ExecCreateCmd.class, withSettings().defaultAnswer(RETURNS_SELF));ExecCreateCmdResponse launchResponse = mock(ExecCreateCmdResponse.class);- when(launchResponse.getId()).thenReturn("exec-launch-" + java.util.UUID.randomUUID());+ when(launchResponse.getId()).thenReturn("exec-launch-" + UUID.randomUUID());when(launchCmd.exec()).thenReturn(launchResponse);launchCmds.add(launchCmd);return launchCmd;@@ -2003,7 +2009,7 @@ class ContainerLauncherTest {* via {@code withCmd(String...)}, in call order — the {@code /opt/extensions/<name>} path* each discovered extension binary was launched with. */private static List<String> capturedLaunchPaths(List<ExecCreateCmd> launchCmds) {- List<String> paths = new java.util.ArrayList<>();+ List<String> paths = new ArrayList<>();for (ExecCreateCmd cmd : launchCmds) {ArgumentCaptor<String[]> captor = ArgumentCaptor.forClass(String[].class);verify(cmd).withCmd(captor.capture());@@ -2055,7 +2061,7 @@ class ContainerLauncherTest {new ContainerLogStreamer(dockerClient, cloudWatchLogs),imageResolver, runtimeApiServerFactory, dockerHostResolver, config,ecrRegistryManager,- mock(io.github.hectorvent.floci.services.lambda.LambdaLayerService.class),+ mock(LambdaLayerService.class),new LaunchedContainerAwsEnv(reachableEndpoint),executionRoleCredentials);diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3LegacyDiskLayoutIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3LegacyDiskLayoutIntegrationTest.javaindex d18119b8c4..54d5b02de8 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3LegacyDiskLayoutIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3LegacyDiskLayoutIntegrationTest.java@@ -1,5 +1,6 @@package io.github.hectorvent.floci.services.s3;+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.InMemoryStorage;@@ -100,7 +101,7 @@ class S3LegacyDiskLayoutIntegrationTest {Path dataRoot = tempDir.resolve("s3");S3Service s3Service = new S3Service(new InMemoryStorage<>(), new InMemoryStorage<>(), dataRoot, false);- assertThrows(io.github.hectorvent.floci.core.common.AwsException.class,+ assertThrows(AwsException.class,() -> s3Service.createBucket(".accounts", "us-east-1"),"a bucket named exactly like the reserved account-storage root must be rejected, "+ "since Floci doesn't otherwise validate bucket name format at all");diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceAnnotationsTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceAnnotationsTest.javaindex 39731cda2e..aa479900ad 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceAnnotationsTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceAnnotationsTest.java@@ -3,7 +3,9 @@ package io.github.hectorvent.floci.services.s3;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.storage.InMemoryStorage;import io.github.hectorvent.floci.services.s3.model.ChecksumAlgorithm;+import io.github.hectorvent.floci.services.s3.model.CopyObjectOptions;import io.github.hectorvent.floci.services.s3.model.ObjectAnnotation;+import io.github.hectorvent.floci.services.s3.model.PutObjectOptions;import io.github.hectorvent.floci.services.s3.model.S3Object;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;@@ -12,6 +14,7 @@ import org.junit.jupiter.api.io.TempDir;import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Path;+import java.time.Instant;import java.util.List;import java.util.stream.Stream;@@ -349,7 +352,7 @@ class S3ServiceAnnotationsTest {void copyObjectCopiesAnnotationsByDefault() {putAnnotation("copied", "payload");s3Service.copyObject(BUCKET, "docs/readme.txt", BUCKET, "docs/copy.txt",- new io.github.hectorvent.floci.services.s3.model.CopyObjectOptions());+ new CopyObjectOptions());ObjectAnnotation annotation = s3Service.getObjectAnnotation(BUCKET, "docs/copy.txt", "copied", null);assertEquals("payload", new String(s3Service.readObjectAnnotationPayload(annotation), StandardCharsets.UTF_8));@@ -362,7 +365,7 @@ class S3ServiceAnnotationsTest {void copyObjectWithExcludeDirectiveSkipsAnnotations() {putAnnotation("excluded", "payload");s3Service.copyObject(BUCKET, "docs/readme.txt", BUCKET, "docs/copy2.txt",- new io.github.hectorvent.floci.services.s3.model.CopyObjectOptions()+ new CopyObjectOptions().withAnnotationDirective("EXCLUDE"));assertThrowsAws("NoSuchAnnotation", () ->s3Service.getObjectAnnotation(BUCKET, "docs/copy2.txt", "excluded", null));@@ -373,14 +376,14 @@ class S3ServiceAnnotationsTest {putAnnotation("cross-bucket", "payload");s3Service.createBucket("cross-bucket-dest", "us-east-1");s3Service.copyObject(BUCKET, "docs/readme.txt", "cross-bucket-dest", "docs/copy.txt",- new io.github.hectorvent.floci.services.s3.model.CopyObjectOptions());+ new CopyObjectOptions());ObjectAnnotation annotation = s3Service.getObjectAnnotation("cross-bucket-dest","docs/copy.txt", "cross-bucket", null);assertEquals("payload", new String(s3Service.readObjectAnnotationPayload(annotation), StandardCharsets.UTF_8));s3Service.copyObject(BUCKET, "docs/readme.txt", "cross-bucket-dest", "docs/copy-excluded.txt",- new io.github.hectorvent.floci.services.s3.model.CopyObjectOptions()+ new CopyObjectOptions().withAnnotationDirective("EXCLUDE"));assertThrowsAws("NoSuchAnnotation", () ->s3Service.getObjectAnnotation("cross-bucket-dest", "docs/copy-excluded.txt", "cross-bucket", null));@@ -459,7 +462,7 @@ class S3ServiceAnnotationsTest {void selfCopyPreservesAnnotations() {putAnnotation("kept-through-copy", "payload");s3Service.copyObject(BUCKET, "docs/readme.txt", BUCKET, "docs/readme.txt",- new io.github.hectorvent.floci.services.s3.model.CopyObjectOptions());+ new CopyObjectOptions());assertEquals("payload", readPayload("kept-through-copy"));ObjectAnnotation annotation = s3Service.getObjectAnnotation(BUCKET, "docs/readme.txt","kept-through-copy", null);@@ -506,9 +509,9 @@ class S3ServiceAnnotationsTest {void governanceRetentionBlocksAnnotationDeleteWithoutBypass() {s3Service.setBucketObjectLockEnabled(BUCKET);s3Service.putObject(BUCKET, "locked.txt", "body".getBytes(StandardCharsets.UTF_8),- null, null, new io.github.hectorvent.floci.services.s3.model.PutObjectOptions()+ null, null, new PutObjectOptions().withObjectLockMode("GOVERNANCE")- .withRetainUntilDate(java.time.Instant.now().plusSeconds(3600)));+ .withRetainUntilDate(Instant.now().plusSeconds(3600)));// Put is symmetric with delete: a retention-protected version cannot receive annotations.assertThrowsAws("AccessDenied", () ->s3Service.putObjectAnnotation(BUCKET, "locked.txt", "locked-ann", null,@@ -518,9 +521,9 @@ class S3ServiceAnnotationsTest {s3Service.putObjectAnnotation(BUCKET, "governed-plain.txt", "ann", null,"payload".getBytes(StandardCharsets.UTF_8), null, null);s3Service.putObject(BUCKET, "governed-plain.txt", "body v2".getBytes(StandardCharsets.UTF_8),- null, null, new io.github.hectorvent.floci.services.s3.model.PutObjectOptions()+ null, null, new PutObjectOptions().withObjectLockMode("GOVERNANCE")- .withRetainUntilDate(java.time.Instant.now().plusSeconds(3600)));+ .withRetainUntilDate(Instant.now().plusSeconds(3600)));// Replacing the annotation via a re-put is blocked too: the protection cannot be// circumvented by a put.assertThrowsAws("AccessDenied", () ->@@ -537,9 +540,9 @@ class S3ServiceAnnotationsTest {void complianceRetentionBlocksAnnotationPutAndDelete() {s3Service.setBucketObjectLockEnabled(BUCKET);s3Service.putObject(BUCKET, "compliance.txt", "body".getBytes(StandardCharsets.UTF_8),- null, null, new io.github.hectorvent.floci.services.s3.model.PutObjectOptions()+ null, null, new PutObjectOptions().withObjectLockMode("COMPLIANCE")- .withRetainUntilDate(java.time.Instant.now().plusSeconds(3600)));+ .withRetainUntilDate(Instant.now().plusSeconds(3600)));// Put is blocked outright on a COMPLIANCE-protected version (no bypass exists for put).assertThrowsAws("AccessDenied", () ->s3Service.putObjectAnnotation(BUCKET, "compliance.txt", "compliance-ann", null,@@ -574,7 +577,7 @@ class S3ServiceAnnotationsTest {// The .s3ann file exists under the account-scoped .annotations root.try (Stream<Path> stream = Files.walk(tempDir.resolve("s3").resolve(".accounts").resolve("000000000000").resolve(".annotations"))) {- List<java.nio.file.Path> files = stream.filter(Files::isRegularFile).toList();+ List<Path> files = stream.filter(Files::isRegularFile).toList();assertEquals(1, files.size());assertTrue(files.get(0).getFileName().toString().endsWith(".s3ann"));assertEquals("on disk", Files.readString(files.get(0), StandardCharsets.UTF_8));diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.javaindex 129a910a4a..6ff30d9b50 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ServiceTest.java@@ -1,9 +1,11 @@package io.github.hectorvent.floci.services.s3;+import com.fasterxml.jackson.core.type.TypeReference;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.core.storage.HybridStorage;import io.github.hectorvent.floci.core.storage.InMemoryStorage;import io.github.hectorvent.floci.services.lambda.LambdaService;import io.github.hectorvent.floci.services.lambda.model.InvocationType;@@ -18,28 +20,37 @@ import io.github.hectorvent.floci.services.s3.model.ObjectAttributeName;import io.github.hectorvent.floci.services.s3.model.PutObjectOptions;import io.github.hectorvent.floci.services.s3.model.S3Object;import io.github.hectorvent.floci.services.s3.model.WebsiteConfiguration;+import org.junit.jupiter.api.Assumptions;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.condition.DisabledOnOs;+import org.junit.jupiter.api.condition.OS;import org.junit.jupiter.api.io.TempDir;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.ValueSource;import java.io.ByteArrayInputStream;import java.io.IOException;+import java.io.UncheckedIOException;import java.net.URLDecoder;import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Path;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;+import java.util.ArrayList;import java.util.HexFormat;+import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import java.util.Set;import java.util.concurrent.CompletableFuture;import java.util.concurrent.CountDownLatch;+import java.util.concurrent.Executors;+import java.util.concurrent.Future;import java.util.concurrent.FutureTask;import java.util.concurrent.TimeUnit;+import java.util.concurrent.atomic.AtomicReference;import java.util.stream.Stream;import static org.junit.jupiter.api.Assertions.*;@@ -100,16 +111,16 @@ class S3ServiceTest {}@Test- @org.junit.jupiter.api.condition.DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS)+ @DisabledOnOs(OS.WINDOWS)void constructorThrowsWhenDataRootUncreatable() throws Exception {- org.junit.jupiter.api.Assumptions.assumeFalse("root".equals(System.getProperty("user.name")),+ Assumptions.assumeFalse("root".equals(System.getProperty("user.name")),"root ignores directory write permissions");Path readOnlyParent = tempDir.resolve("ro");Files.createDirectories(readOnlyParent);assertTrue(readOnlyParent.toFile().setWritable(false));try {Path dataRoot = readOnlyParent.resolve("s3");- assertThrows(java.io.UncheckedIOException.class,+ assertThrows(UncheckedIOException.class,() -> new S3Service(new InMemoryStorage<>(), new InMemoryStorage<>(), dataRoot, false));} finally {assertTrue(readOnlyParent.toFile().setWritable(true));@@ -1260,16 +1271,16 @@ class S3ServiceTest {// Through the real storage layer rather than Jackson alone: written, flushed to disk, and// read back by a second service over the same file, the way a restart does it.Path bucketsFile = tempDir.resolve("s3-buckets.json");- var beforeRestart = new io.github.hectorvent.floci.core.storage.HybridStorage<String, Bucket>(- bucketsFile, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Bucket>>() {}, 60000);+ var beforeRestart = new HybridStorage<String, Bucket>(+ bucketsFile, new TypeReference<Map<String, Bucket>>() {}, 60000);S3Service before = new S3Service(beforeRestart, new InMemoryStorage<>(), tempDir.resolve("s3a"), false);before.createBucket("persisted-metrics", "us-east-1");before.putBucketMetricsConfiguration("persisted-metrics", "EntireBucket", "<Id>EntireBucket</Id>");beforeRestart.flush();beforeRestart.shutdown();- var afterRestart = new io.github.hectorvent.floci.core.storage.HybridStorage<String, Bucket>(- bucketsFile, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Bucket>>() {}, 60000);+ var afterRestart = new HybridStorage<String, Bucket>(+ bucketsFile, new TypeReference<Map<String, Bucket>>() {}, 60000);afterRestart.load();try {S3Service after = new S3Service(afterRestart, new InMemoryStorage<>(), tempDir.resolve("s3a"), false);@@ -1323,10 +1334,10 @@ class S3ServiceTest {@Testvoid analyticsAndInventoryConfigurationsSurviveAJacksonRoundTrip() throws Exception {- var mapper = new com.fasterxml.jackson.databind.ObjectMapper().findAndRegisterModules();+ var mapper = new ObjectMapper().findAndRegisterModules();Bucket bucket = new Bucket("persisted-configs");- bucket.setAnalyticsConfigurations(new java.util.LinkedHashMap<>(Map.of("a", "<Id>a</Id>")));- bucket.setInventoryConfigurations(new java.util.LinkedHashMap<>(Map.of("i", "<Id>i</Id>")));+ bucket.setAnalyticsConfigurations(new LinkedHashMap<>(Map.of("a", "<Id>a</Id>")));+ bucket.setInventoryConfigurations(new LinkedHashMap<>(Map.of("i", "<Id>i</Id>")));Bucket reloaded = mapper.readValue(mapper.writeValueAsString(bucket), Bucket.class);assertEquals("<Id>a</Id>", reloaded.getAnalyticsConfigurations().get("a"));@@ -1337,9 +1348,9 @@ class S3ServiceTest {void metricsConfigurationsSurviveAJacksonRoundTrip() throws Exception {// Bucket records are persisted as JSON, so the configurations have to come back after a// restart, and a record written before the field existed has to still load.- var mapper = new com.fasterxml.jackson.databind.ObjectMapper().findAndRegisterModules();+ var mapper = new ObjectMapper().findAndRegisterModules();Bucket bucket = new Bucket("persisted");- bucket.setMetricsConfigurations(new java.util.LinkedHashMap<>(+ bucket.setMetricsConfigurations(new LinkedHashMap<>(Map.of("EntireBucket", "<Id>EntireBucket</Id>")));Bucket reloaded = mapper.readValue(mapper.writeValueAsString(bucket), Bucket.class);@@ -1355,7 +1366,7 @@ class S3ServiceTest {* hope for it, which keeps the test both instant and immune to a slow machine.*/private static void awaitBlockedOnMonitor(Thread thread) throws InterruptedException {- long deadline = System.nanoTime() + java.util.concurrent.TimeUnit.SECONDS.toNanos(10);+ long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);while (thread.getState() != Thread.State.BLOCKED) {if (System.nanoTime() > deadline) {fail("thread never reached the bucket monitor");@@ -1378,7 +1389,7 @@ class S3ServiceTest {Thread delete = new Thread(() -> service.deleteBucket("monitor-bucket"));synchronized (record) {delete.start();- long deadline = System.nanoTime() + java.util.concurrent.TimeUnit.SECONDS.toNanos(10);+ long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);while (delete.getState() != Thread.State.BLOCKED) {assertTrue(buckets.get("monitor-bucket").isPresent(),"DeleteBucket removed the record without waiting for the bucket monitor");@@ -1404,8 +1415,8 @@ class S3ServiceTest {service.createBucket("race-bucket", "us-east-1");Bucket record = buckets.get("race-bucket").orElseThrow();- var putStarted = new java.util.concurrent.CountDownLatch(1);- var thrownByPut = new java.util.concurrent.atomic.AtomicReference<Exception>();+ var putStarted = new CountDownLatch(1);+ var thrownByPut = new AtomicReference<Exception>();Thread put = new Thread(() -> {putStarted.countDown();try {@@ -1439,8 +1450,8 @@ class S3ServiceTest {service.createBucket("recreated-bucket", "us-east-1");Bucket original = buckets.get("recreated-bucket").orElseThrow();- var putStarted = new java.util.concurrent.CountDownLatch(1);- var thrownByPut = new java.util.concurrent.atomic.AtomicReference<Exception>();+ var putStarted = new CountDownLatch(1);+ var thrownByPut = new AtomicReference<Exception>();Thread put = new Thread(() -> {putStarted.countDown();try {@@ -1473,10 +1484,10 @@ class S3ServiceTest {// monitor concurrent puts of different ids overwrite each other's work.s3Service.createBucket("metrics-race", "us-east-1");int count = 24;- var pool = java.util.concurrent.Executors.newFixedThreadPool(8);- var start = new java.util.concurrent.CountDownLatch(1);+ var pool = Executors.newFixedThreadPool(8);+ var start = new CountDownLatch(1);try {- var submitted = new java.util.ArrayList<java.util.concurrent.Future<?>>();+ var submitted = new ArrayList<Future<?>>();for (int i = 0; i < count; i++) {String id = "config-" + i;submitted.add(pool.submit(() -> {@@ -1487,7 +1498,7 @@ class S3ServiceTest {}start.countDown();for (var future : submitted) {- future.get(30, java.util.concurrent.TimeUnit.SECONDS);+ future.get(30, TimeUnit.SECONDS);}} finally {pool.shutdownNow();@@ -1574,8 +1585,8 @@ class S3ServiceTest {// Through the real storage layer rather than Jackson alone: written, flushed to disk, and// read back by a second service over the same file, the way a restart does it.Path bucketsFile = tempDir.resolve("s3-buckets-tiering.json");- var beforeRestart = new io.github.hectorvent.floci.core.storage.HybridStorage<String, Bucket>(- bucketsFile, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Bucket>>() {}, 60000);+ var beforeRestart = new HybridStorage<String, Bucket>(+ bucketsFile, new TypeReference<Map<String, Bucket>>() {}, 60000);S3Service before = new S3Service(beforeRestart, new InMemoryStorage<>(), tempDir.resolve("s3b"), false);before.createBucket("persisted-tiering", "us-east-1");before.putBucketIntelligentTieringConfiguration("persisted-tiering", "EntireBucket",@@ -1583,8 +1594,8 @@ class S3ServiceTest {beforeRestart.flush();beforeRestart.shutdown();- var afterRestart = new io.github.hectorvent.floci.core.storage.HybridStorage<String, Bucket>(- bucketsFile, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Bucket>>() {}, 60000);+ var afterRestart = new HybridStorage<String, Bucket>(+ bucketsFile, new TypeReference<Map<String, Bucket>>() {}, 60000);afterRestart.load();try {S3Service after = new S3Service(afterRestart, new InMemoryStorage<>(), tempDir.resolve("s3b"), false);@@ -1599,9 +1610,9 @@ class S3ServiceTest {void intelligentTieringConfigurationsSurviveAJacksonRoundTrip() throws Exception {// Bucket records are persisted as JSON, so the configurations have to come back after a// restart, and a record written before the field existed has to still load.- var mapper = new com.fasterxml.jackson.databind.ObjectMapper().findAndRegisterModules();+ var mapper = new ObjectMapper().findAndRegisterModules();Bucket bucket = new Bucket("persisted");- bucket.setIntelligentTieringConfigurations(new java.util.LinkedHashMap<>(+ bucket.setIntelligentTieringConfigurations(new LinkedHashMap<>(Map.of("EntireBucket", "<Id>EntireBucket</Id>")));Bucket reloaded = mapper.readValue(mapper.writeValueAsString(bucket), Bucket.class);@@ -1618,10 +1629,10 @@ class S3ServiceTest {// monitor concurrent puts of different ids overwrite each other's work.s3Service.createBucket("tiering-race", "us-east-1");int count = 24;- var pool = java.util.concurrent.Executors.newFixedThreadPool(8);- var start = new java.util.concurrent.CountDownLatch(1);+ var pool = Executors.newFixedThreadPool(8);+ var start = new CountDownLatch(1);try {- var submitted = new java.util.ArrayList<java.util.concurrent.Future<?>>();+ var submitted = new ArrayList<Future<?>>();for (int i = 0; i < count; i++) {String id = "config-" + i;submitted.add(pool.submit(() -> {@@ -1633,7 +1644,7 @@ class S3ServiceTest {}start.countDown();for (var future : submitted) {- future.get(30, java.util.concurrent.TimeUnit.SECONDS);+ future.get(30, TimeUnit.SECONDS);}} finally {pool.shutdownNow();diff --git a/tools/checkstyle/suppressions.xml b/tools/checkstyle/suppressions.xmlindex 3c73e85adb..97739950ba 100644--- a/tools/checkstyle/suppressions.xml+++ b/tools/checkstyle/suppressions.xml@@ -267,19 +267,15 @@<suppress id="NoFqcn" files="/services/lakeformation/LakeFormationService\.java$"/><suppress id="NoFqcn" files="/services/lakeformation/MemoryLakeFormationStorage\.java$"/><suppress id="NoFqcn" files="/services/lambda/ApiGatewayController\.java$"/>- <suppress id="NoFqcn" files="/services/lambda/DynamoDbStreamsEventSourcePollerTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaAccountScopedCodeTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaController\.java$"/>- <suppress id="NoFqcn" files="/services/lambda/LambdaImageConfigTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaIntegrationTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaQualifiedReadIntegrationTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaServiceTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaService\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaStructureSerializationIntegrationTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/LambdaTagController\.java$"/>- <suppress id="NoFqcn" files="/services/lambda/SqsEventSourcePollerTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/launcher/ContainerLauncherCodeVolumeReuseTest\.java$"/>- <suppress id="NoFqcn" files="/services/lambda/launcher/ContainerLauncherTest\.java$"/><suppress id="NoFqcn" files="/services/lambda/launcher/ContainerLauncher\.java$"/><suppress id="NoFqcn" files="/services/lambda/launcher/ImageCacheService\.java$"/><suppress id="NoFqcn" files="/services/lambda/launcher/kubernetes/LambdaPodSpecFactory\.java$"/>@@ -323,8 +319,6 @@<suppress id="NoFqcn" files="/services/s3/S3MultipartIntegrationTest\.java$"/><suppress id="NoFqcn" files="/services/s3/S3PresignedPostAuthEnforcementIntegrationTest\.java$"/><suppress id="NoFqcn" files="/services/s3/S3SelectIntegrationTest\.java$"/>- <suppress id="NoFqcn" files="/services/s3/S3ServiceAnnotationsTest\.java$"/>- <suppress id="NoFqcn" files="/services/s3/S3ServiceTest\.java$"/><suppress id="NoFqcn" files="/services/s3/S3Service\.java$"/><suppress id="NoFqcn" files="/services/s3/S3VirtualHostIntegrationTest\.java$"/><suppress id="NoFqcn" files="/services/s3/model/S3Object\.java$"/>