Light, fluffy, and always free - The AWS Local Emulator alternative
fix(codedeploy): persist applications, deployment groups, configs, on-prem instances and tags (#1579)
Hector Ventura4a53acf0b32f
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex 1e799d4e46..a6b2f0f9e7 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -192,6 +192,7 @@ public interface EmulatorConfig {EcsStorageConfig ecs();CodeBuildStorageConfig codebuild();ConfigStorageConfig config();+ CodeDeployStorageConfig codedeploy();}interface SsmStorageConfig {@@ -365,6 +366,13 @@ public interface EmulatorConfig {long flushIntervalMs();}+ interface CodeDeployStorageConfig {+ Optional<String> mode();++ @WithDefault("5000")+ long flushIntervalMs();+ }+interface WalConfig {@WithDefault("30000")long compactionIntervalMs();diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.javaindex be69aaad77..2b0e271ff1 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java@@ -262,7 +262,8 @@ public class ResolvedServiceCatalog {protocols(ServiceProtocol.REST_JSON),Set.of(), Set.of("batch"), Set.of(), Set.of(BatchController.class)),descriptor("codedeploy", "codedeploy", config.services().codedeploy().enabled(), true,- null, null, 5000L, null, ServiceProtocol.JSON,+ "codedeploy", storageMode(config.storage().services().codedeploy().mode(), config.storage().mode()),+ config.storage().services().codedeploy().flushIntervalMs(), null, ServiceProtocol.JSON,protocols(ServiceProtocol.JSON),Set.of("CodeDeploy_20141006."), Set.of("codedeploy"), Set.of(), Set.of()),descriptor("codepipeline", "codepipeline", config.services().codepipeline().enabled(), true,diff --git a/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java b/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.javaindex 01c484114a..2655d7a696 100644--- a/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java+++ b/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java@@ -1,11 +1,14 @@package io.github.hectorvent.floci.services.codedeploy;+import com.fasterxml.jackson.core.type.TypeReference;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.RegionResolver;+import io.github.hectorvent.floci.core.storage.StorageBackedMap;+import io.github.hectorvent.floci.core.storage.StorageFactory;import io.github.hectorvent.floci.services.codedeploy.model.Application;import io.github.hectorvent.floci.services.codedeploy.model.Deployment;import io.github.hectorvent.floci.services.codedeploy.model.DeploymentConfig;@@ -20,6 +23,7 @@ import io.github.hectorvent.floci.services.lambda.LambdaService;import io.github.hectorvent.floci.services.ssm.SsmCommandService;import io.github.hectorvent.floci.services.lambda.model.InvocationType;import io.github.hectorvent.floci.services.lambda.model.InvokeResult;+import jakarta.annotation.PostConstruct;import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;import org.jboss.logging.Logger;@@ -49,11 +53,13 @@ public class CodeDeployService {private final ObjectMapper mapper;private final ObjectMapper yamlMapper;private final RegionResolver regionResolver;+ private final StorageFactory storageFactory;@Injectpublic CodeDeployService(LambdaService lambdaService, EcsService ecsService,ElbV2Service elbV2Service, SsmCommandService ssmCommandService,- Ec2Service ec2Service, ObjectMapper mapper, RegionResolver regionResolver) {+ Ec2Service ec2Service, ObjectMapper mapper, RegionResolver regionResolver,+ StorageFactory storageFactory) {this.lambdaService = lambdaService;this.ecsService = ecsService;this.elbV2Service = elbV2Service;@@ -62,27 +68,111 @@ public class CodeDeployService {this.mapper = mapper;this.yamlMapper = new ObjectMapper(new YAMLFactory());this.regionResolver = regionResolver;+ this.storageFactory = storageFactory;}+ // ---- Durable (persisted) ----// key: region -> name -> application- private final ConcurrentHashMap<String, ConcurrentHashMap<String, Application>> applications = new ConcurrentHashMap<>();+ private Map<String, Map<String, Application>> applications = new ConcurrentHashMap<>();// key: region -> appName -> groupName -> group- private final ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, DeploymentGroup>>> deploymentGroups = new ConcurrentHashMap<>();+ private Map<String, Map<String, Map<String, DeploymentGroup>>> deploymentGroups = new ConcurrentHashMap<>();// key: region -> configName -> config (pre-seeded with built-ins)- private final ConcurrentHashMap<String, ConcurrentHashMap<String, DeploymentConfig>> deploymentConfigs = new ConcurrentHashMap<>();+ private Map<String, Map<String, DeploymentConfig>> deploymentConfigs = new ConcurrentHashMap<>();// key: resourceArn -> tags- private final ConcurrentHashMap<String, Map<String, String>> tags = new ConcurrentHashMap<>();+ private Map<String, Map<String, String>> tags = new ConcurrentHashMap<>();+ // key: region -> instanceName -> OnPremisesInstance+ private Map<String, Map<String, OnPremisesInstance>> onPremisesInstances = new ConcurrentHashMap<>();++ // ---- Transient runtime state (in memory only) ----// key: region -> deploymentId -> Deploymentprivate final ConcurrentHashMap<String, ConcurrentHashMap<String, Deployment>> deployments = new ConcurrentHashMap<>();// key: region -> deploymentId -> targetId -> DeploymentTarget wrapperprivate final ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, Map<String, Object>>>> deploymentTargets = new ConcurrentHashMap<>();- // key: region -> instanceName -> OnPremisesInstance- private final ConcurrentHashMap<String, ConcurrentHashMap<String, OnPremisesInstance>> onPremisesInstances = new ConcurrentHashMap<>();// key: lifecycleEventHookExecutionId -> CompletableFuture<status>private final ConcurrentHashMap<String, CompletableFuture<String>> hookFutures = new ConcurrentHashMap<>();// key: deploymentId -> stop flagprivate final ConcurrentHashMap<String, AtomicBoolean> stopFlags = new ConcurrentHashMap<>();+ @PostConstruct+ void initializeStorage() {+ if (storageFactory == null) {+ return; // keeps non-CDI unit tests working+ }+ this.applications = storageBacked("codedeploy-applications.json",+ new TypeReference<Map<String, Map<String, Application>>>() {});+ this.deploymentGroups = storageBacked("codedeploy-deployment-groups.json",+ new TypeReference<Map<String, Map<String, Map<String, DeploymentGroup>>>>() {});+ this.deploymentConfigs = storageBacked("codedeploy-deployment-configs.json",+ new TypeReference<Map<String, Map<String, DeploymentConfig>>>() {});+ this.tags = storageBacked("codedeploy-tags.json",+ new TypeReference<Map<String, Map<String, String>>>() {});+ this.onPremisesInstances = storageBacked("codedeploy-on-premises-instances.json",+ new TypeReference<Map<String, Map<String, OnPremisesInstance>>>() {});+ normalizeRegionMaps(applications);+ normalizeDeploymentGroups();+ normalizeRegionMaps(deploymentConfigs);+ normalizeRegionMaps(tags);+ normalizeRegionMaps(onPremisesInstances);+ reconcileBuiltInConfigs();+ }++ private <V> Map<String, V> storageBacked(String fileName, TypeReference<Map<String, V>> typeReference) {+ return new StorageBackedMap<>(storageFactory.create("codedeploy", fileName, typeReference));+ }++ /** After load, re-wrap persisted inner maps as {@link ConcurrentHashMap} (Jackson reads them as+ * plain maps) so per-key mutation stays thread-safe. For two-level region maps. */+ private <V> void normalizeRegionMaps(Map<String, Map<String, V>> resources) {+ for (Map.Entry<String, Map<String, V>> entry : new ArrayList<>(resources.entrySet())) {+ if (!(entry.getValue() instanceof ConcurrentHashMap)) {+ resources.put(entry.getKey(), new ConcurrentHashMap<>(entry.getValue()));+ }+ }+ }++ /** Three-level normalization for deploymentGroups (region -> app -> group). */+ private void normalizeDeploymentGroups() {+ for (Map.Entry<String, Map<String, Map<String, DeploymentGroup>>> regionEntry+ : new ArrayList<>(deploymentGroups.entrySet())) {+ Map<String, Map<String, DeploymentGroup>> appMap = new ConcurrentHashMap<>();+ for (Map.Entry<String, Map<String, DeploymentGroup>> appEntry : regionEntry.getValue().entrySet()) {+ appMap.put(appEntry.getKey(), new ConcurrentHashMap<>(appEntry.getValue()));+ }+ deploymentGroups.put(regionEntry.getKey(), appMap);+ }+ }++ /** Top up any built-in deployment configs missing from already-loaded regions (forward-compat+ * if the built-in list grows between Floci versions). Built-ins themselves are persisted. */+ private void reconcileBuiltInConfigs() {+ for (String region : new ArrayList<>(deploymentConfigs.keySet())) {+ Map<String, DeploymentConfig> store = deploymentConfigs.get(region);+ if (store == null) {+ continue;+ }+ double now = Instant.now().toEpochMilli() / 1000.0;+ boolean changed = false;+ for (String name : BUILT_IN_CONFIG_NAMES) {+ if (!store.containsKey(name)) {+ store.put(name, buildBuiltInConfig(name, now));+ changed = true;+ }+ }+ if (changed) {+ deploymentConfigs.put(region, store);+ }+ }+ }++ /** {@link StorageBackedMap} only flushes on a top-level put, so an in-place mutation of an+ * inner map must be written back by re-putting the region entry. */+ private <V> void persistRegion(Map<String, Map<String, V>> resources, String region) {+ Map<String, V> regionResources = resources.get(region);+ if (regionResources != null) {+ resources.put(region, regionResources);+ }+ }+private static final class AppSpecInfo {String functionName;String aliasName;@@ -143,7 +233,7 @@ public class CodeDeployService {return applications.computeIfAbsent(region, r -> new ConcurrentHashMap<>());}- private Map<String, ConcurrentHashMap<String, DeploymentGroup>> deploymentGroupsFor(String region) {+ private Map<String, Map<String, DeploymentGroup>> deploymentGroupsFor(String region) {return deploymentGroups.computeIfAbsent(region, r -> new ConcurrentHashMap<>());}@@ -229,6 +319,7 @@ public class CodeDeployService {app.setLinkedToGitHub(false);app.setComputePlatform(computePlatform != null ? computePlatform : "Server");store.put(name, app);+ persistRegion(applications, region);if (tags != null && !tags.isEmpty()) {String arn = applicationArn(region, name);@@ -261,6 +352,7 @@ public class CodeDeployService {store.remove(currentName);app.setApplicationName(newName);store.put(newName, app);+ persistRegion(applications, region);}}@@ -269,6 +361,7 @@ public class CodeDeployService {throw new AwsException("ApplicationDoesNotExistException","Application does not exist: " + name, 400);}+ persistRegion(applications, region);}public List<String> listApplications(String region) {@@ -295,8 +388,8 @@ public class CodeDeployService {String deploymentConfigName, String serviceRoleArn,Map<String, Object> fields) {getApplication(region, appName);- Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);- ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.computeIfAbsent(appName, a -> new ConcurrentHashMap<>());+ Map<String, Map<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);+ Map<String, DeploymentGroup> groupStore = appGroups.computeIfAbsent(appName, a -> new ConcurrentHashMap<>());if (groupStore.containsKey(groupName)) {throw new AwsException("DeploymentGroupAlreadyExistsException","Deployment group already exists: " + groupName, 400);@@ -310,13 +403,14 @@ public class CodeDeployService {group.setServiceRoleArn(serviceRoleArn);applyGroupFields(group, fields);groupStore.put(groupName, group);+ persistRegion(deploymentGroups, region);return group;}public DeploymentGroup getDeploymentGroup(String region, String appName, String groupName) {getApplication(region, appName);- Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);- ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);+ Map<String, Map<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);+ Map<String, DeploymentGroup> groupStore = appGroups.get(appName);DeploymentGroup group = groupStore != null ? groupStore.get(groupName) : null;if (group == null) {throw new AwsException("DeploymentGroupDoesNotExistException",@@ -330,7 +424,7 @@ public class CodeDeployService {String deploymentConfigName, String serviceRoleArn,Map<String, Object> fields) {DeploymentGroup group = getDeploymentGroup(region, appName, currentGroupName);- ConcurrentHashMap<String, DeploymentGroup> groupStore = deploymentGroupsFor(region)+ Map<String, DeploymentGroup> groupStore = deploymentGroupsFor(region).computeIfAbsent(appName, a -> new ConcurrentHashMap<>());if (deploymentConfigName != null) { group.setDeploymentConfigName(deploymentConfigName); }@@ -342,30 +436,32 @@ public class CodeDeployService {group.setDeploymentGroupName(newGroupName);groupStore.put(newGroupName, group);}+ persistRegion(deploymentGroups, region);return group;}public void deleteDeploymentGroup(String region, String appName, String groupName) {getApplication(region, appName);- Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);- ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);+ Map<String, Map<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);+ Map<String, DeploymentGroup> groupStore = appGroups.get(appName);if (groupStore == null || groupStore.remove(groupName) == null) {throw new AwsException("DeploymentGroupDoesNotExistException","Deployment group does not exist: " + groupName, 400);}+ persistRegion(deploymentGroups, region);}public List<String> listDeploymentGroups(String region, String appName) {getApplication(region, appName);- Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);- ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);+ Map<String, Map<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);+ Map<String, DeploymentGroup> groupStore = appGroups.get(appName);return groupStore != null ? new ArrayList<>(groupStore.keySet()) : List.of();}public List<DeploymentGroup> batchGetDeploymentGroups(String region, String appName, List<String> names) {getApplication(region, appName);- Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);- ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);+ Map<String, Map<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);+ Map<String, DeploymentGroup> groupStore = appGroups.get(appName);if (groupStore == null) {return List.of();}@@ -400,6 +496,7 @@ public class CodeDeployService {cfg.setTrafficRoutingConfig(trafficRoutingConfig);cfg.setZonalConfig(zonalConfig);store.put(name, cfg);+ persistRegion(deploymentConfigs, region);return cfg;}@@ -421,6 +518,7 @@ public class CodeDeployService {throw new AwsException("DeploymentConfigDoesNotExistException","Deployment configuration does not exist: " + name, 400);}+ persistRegion(deploymentConfigs, region);}public List<String> listDeploymentConfigs(String region) {@@ -599,6 +697,7 @@ public class CodeDeployService {inst.setRegisterTime(Instant.now().toEpochMilli() / 1000.0);inst.setRegistrationStatus("Registered");store.put(instanceName, inst);+ persistRegion(onPremisesInstances, region);return inst;}@@ -606,6 +705,7 @@ public class CodeDeployService {OnPremisesInstance inst = requireOnPremisesInstance(region, instanceName);inst.setDeregisterTime(Instant.now().toEpochMilli() / 1000.0);inst.setRegistrationStatus("Deregistered");+ persistRegion(onPremisesInstances, region);}public OnPremisesInstance getOnPremisesInstance(String region, String instanceName) {@@ -633,6 +733,7 @@ public class CodeDeployService {inst.getTags().add(t);}}+ persistRegion(onPremisesInstances, region);}public void removeTagsFromOnPremisesInstances(String region, List<String> instanceNames, List<Map<String, String>> tagsToRemove) {@@ -642,6 +743,7 @@ public class CodeDeployService {inst.getTags().removeIf(e -> e.get("Key").equals(t.get("Key")));}}+ persistRegion(onPremisesInstances, region);}private OnPremisesInstance requireOnPremisesInstance(String region, String instanceName) {@@ -1624,12 +1726,14 @@ public class CodeDeployService {for (Map<String, String> t : tagList) {tagMap.put(t.get("Key"), t.get("Value"));}+ tags.put(arn, tagMap); // write back the in-place inner-map mutation}public void untagResource(String arn, List<String> tagKeys) {Map<String, String> tagMap = tags.get(arn);if (tagMap != null) {tagKeys.forEach(tagMap::remove);+ tags.put(arn, tagMap); // write back the in-place inner-map mutation}}@@ -1705,5 +1809,6 @@ public class CodeDeployService {String value = t.containsKey("Value") ? t.get("Value") : t.get("value");if (key != null) { tagMap.put(key, value != null ? value : ""); }}+ tags.put(arn, tagMap); // write back the in-place inner-map mutation}}diff --git a/src/main/resources/application.yml b/src/main/resources/application.ymlindex 2ae382712d..54543c012d 100644--- a/src/main/resources/application.yml+++ b/src/main/resources/application.yml@@ -105,6 +105,8 @@ floci:flush-interval-ms: 5000config:flush-interval-ms: 5000+ codedeploy:+ flush-interval-ms: 5000rds:# Override storage mode for RDS (memory = no Docker volumes; hybrid/persistent = named volume per instance)# mode: memorydiff --git a/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServicePersistenceTest.java b/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServicePersistenceTest.javanew file mode 100644index 0000000000..2c3214aebd--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServicePersistenceTest.java@@ -0,0 +1,121 @@+package io.github.hectorvent.floci.services.codedeploy;++import com.fasterxml.jackson.core.type.TypeReference;+import com.fasterxml.jackson.databind.ObjectMapper;+import io.github.hectorvent.floci.core.common.RegionResolver;+import io.github.hectorvent.floci.core.storage.InMemoryStorage;+import io.github.hectorvent.floci.core.storage.StorageBackend;+import io.github.hectorvent.floci.core.storage.StorageFactory;+import io.github.hectorvent.floci.services.codedeploy.model.DeploymentGroup;+import io.github.hectorvent.floci.services.ec2.Ec2Service;+import io.github.hectorvent.floci.services.ecs.EcsService;+import io.github.hectorvent.floci.services.elbv2.ElbV2Service;+import io.github.hectorvent.floci.services.lambda.LambdaService;+import io.github.hectorvent.floci.services.ssm.SsmCommandService;+import org.junit.jupiter.api.Test;++import java.util.HashMap;+import java.util.List;+import java.util.Map;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertNotNull;+import static org.junit.jupiter.api.Assertions.assertThrows;+import static org.junit.jupiter.api.Assertions.assertTrue;+import static org.mockito.Mockito.mock;++/**+ * Verifies CodeDeploy durable resources survive a restart, including the nested deployment groups+ * and the built-in deployment configs. Two service instances share the same {@link StorageFactory}+ * backends; the second simulates a process restart reloading from disk.+ */+class CodeDeployServicePersistenceTest {++ private static final String REGION = "us-east-1";++ @Test+ void durableResourcesAndBuiltInsSurviveRestart() {+ SharedStorageFactory storage = new SharedStorageFactory();++ CodeDeployService first = serviceWithStorage(storage);+ first.createApplication(REGION, "web-app", "Server",+ List.of(Map.of("Key", "team", "Value", "platform")));+ first.createDeploymentGroup(REGION, "web-app", "prod-group",+ "CodeDeployDefault.OneAtATime", "arn:aws:iam::000000000000:role/cd", null);+ first.createDeploymentConfig(REGION, "custom-cfg",+ Map.of("type", "HOST_COUNT", "value", 1), "Server", null, null);+ first.registerOnPremisesInstance(REGION, "onprem-1",+ "arn:aws:sts::000000000000:session/s", "arn:aws:iam::000000000000:user/u");+ first.tagResource(first.applicationArn(REGION, "web-app"),+ List.of(Map.of("Key", "env", "Value", "prod")));++ CodeDeployService reloaded = serviceWithStorage(storage);++ assertEquals(List.of("web-app"), reloaded.listApplications(REGION));+ DeploymentGroup group = reloaded.getDeploymentGroup(REGION, "web-app", "prod-group");+ assertEquals("CodeDeployDefault.OneAtATime", group.getDeploymentConfigName());+ assertNotNull(reloaded.getDeploymentConfig(REGION, "custom-cfg"));+ // built-in configs survive (they are persisted, and topped up on load)+ assertNotNull(reloaded.getDeploymentConfig(REGION, "CodeDeployDefault.OneAtATime"));+ assertTrue(reloaded.listDeploymentConfigs(REGION).size() >= 18,+ "17 built-ins + custom config expected after restart");+ assertEquals("Registered",+ reloaded.getOnPremisesInstance(REGION, "onprem-1").getRegistrationStatus());+ Map<String, String> appTags = reloaded.listTagsForResource(first.applicationArn(REGION, "web-app"))+ .stream().collect(java.util.stream.Collectors.toMap(t -> t.get("Key"), t -> t.get("Value")));+ assertEquals("prod", appTags.get("env")); // tagResource+ assertEquals("platform", appTags.get("team")); // createApplication tags+ }++ @Test+ void deletesAndUntagArePersistedAfterRestart() {+ SharedStorageFactory storage = new SharedStorageFactory();++ CodeDeployService first = serviceWithStorage(storage);+ first.createApplication(REGION, "keep-app", "Server", null);+ first.createApplication(REGION, "drop-app", "Server", null);+ first.createDeploymentGroup(REGION, "keep-app", "g1", null, "arn:r", null);+ first.createDeploymentGroup(REGION, "keep-app", "g2", null, "arn:r", null);+ first.deleteApplication(REGION, "drop-app");+ first.deleteDeploymentGroup(REGION, "keep-app", "g2");+ String arn = first.applicationArn(REGION, "keep-app");+ first.tagResource(arn, List.of(Map.of("Key", "env", "Value", "prod"),+ Map.of("Key", "team", "Value", "sec")));+ first.untagResource(arn, List.of("team"));++ CodeDeployService reloaded = serviceWithStorage(storage);++ assertEquals(List.of("keep-app"), reloaded.listApplications(REGION));+ assertEquals(List.of("g1"), reloaded.listDeploymentGroups(REGION, "keep-app"));+ assertThrows(Exception.class, () -> reloaded.getDeploymentGroup(REGION, "keep-app", "g2"));+ Map<String, String> tags = reloaded.listTagsForResource(arn).stream()+ .collect(java.util.stream.Collectors.toMap(t -> t.get("Key"), t -> t.get("Value")));+ assertEquals("prod", tags.get("env"));+ assertTrue(!tags.containsKey("team"), "untagged key must not reappear after restart");+ }++ private static CodeDeployService serviceWithStorage(StorageFactory storage) {+ CodeDeployService service = new CodeDeployService(+ mock(LambdaService.class), mock(EcsService.class), mock(ElbV2Service.class),+ mock(SsmCommandService.class), mock(Ec2Service.class), new ObjectMapper(),+ new RegionResolver(REGION, "000000000000"), storage);+ service.initializeStorage();+ return service;+ }++ private static final class SharedStorageFactory extends StorageFactory {+ private final Map<String, StorageBackend<String, ?>> stores = new HashMap<>();++ private SharedStorageFactory() {+ super(null, null);+ }++ @Override+ @SuppressWarnings("unchecked")+ public <V> StorageBackend<String, V> create(String serviceName,+ String fileName,+ TypeReference<Map<String, V>> typeReference) {+ return (StorageBackend<String, V>) stores.computeIfAbsent(fileName, ignored -> new InMemoryStorage<>());+ }+ }+}diff --git a/src/test/resources/application.yml b/src/test/resources/application.ymlindex 0e8920e623..51f66676e4 100644--- a/src/test/resources/application.yml+++ b/src/test/resources/application.yml@@ -48,6 +48,8 @@ floci:flush-interval-ms: 60000config:flush-interval-ms: 60000+ codedeploy:+ flush-interval-ms: 60000cloudfront:auth: