Browse Source

Clean up some older collections idioms in ILM (#118508) (#118582)

Joe Gallo 10 months ago
parent
commit
e04fe26d25
82 changed files with 470 additions and 692 deletions
  1. 4 6
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java
  2. 2 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java
  3. 2 3
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteAction.java
  4. 1 5
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java
  5. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java
  6. 3 4
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java
  7. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java
  8. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java
  9. 1 4
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java
  10. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java
  11. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java
  12. 6 9
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java
  13. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UnfollowAction.java
  14. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStep.java
  15. 1 2
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotAction.java
  16. 10 11
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java
  17. 3 4
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStepTests.java
  18. 6 6
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStepTests.java
  19. 6 5
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseFollowerIndexStepTests.java
  20. 2 4
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseIndexStepTests.java
  21. 4 5
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStepTests.java
  22. 1 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponseTests.java
  23. 1 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeActionTests.java
  24. 3 3
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStepTests.java
  25. 2 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleExplainResponseTests.java
  26. 1 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyClientTests.java
  27. 2 3
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyMetadataTests.java
  28. 18 24
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java
  29. 16 18
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtilsTests.java
  30. 2 4
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockAction.java
  31. 4 5
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/OperationModeUpdateTaskTests.java
  32. 7 7
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PauseFollowerIndexStepTests.java
  33. 12 13
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java
  34. 2 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseExecutionInfoTests.java
  35. 6 7
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseTests.java
  36. 3 7
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverStepTests.java
  37. 5 5
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java
  38. 4 7
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java
  39. 1 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStepTests.java
  40. 2 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkStepTests.java
  41. 1 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStepTests.java
  42. 62 80
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java
  43. 5 5
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowFollowerIndexStepTests.java
  44. 2 3
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStepTests.java
  45. 1 3
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForDataTierStepTests.java
  46. 6 6
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java
  47. 3 3
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStepTests.java
  48. 2 7
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java
  49. 1 2
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/GetLifecycleResponseTests.java
  50. 2 3
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/PutLifecycleRequestTests.java
  51. 3 5
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/RemoveIndexLifecyclePolicyResponseTests.java
  52. 2 3
      x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ilm/CCRIndexLifecycleIT.java
  53. 6 7
      x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java
  54. 6 8
      x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java
  55. 5 12
      x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyForIndexIT.java
  56. 3 4
      x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java
  57. 19 20
      x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java
  58. 1 2
      x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ShrinkActionIT.java
  59. 2 3
      x-pack/plugin/ilm/qa/with-security/src/javaRestTest/java/org/elasticsearch/xpack/security/PermissionsIT.java
  60. 1 2
      x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java
  61. 8 9
      x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java
  62. 7 8
      x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java
  63. 6 7
      x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeWithCCRDisabledIT.java
  64. 7 9
      x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java
  65. 1 2
      x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java
  66. 4 5
      x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java
  67. 1 2
      x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java
  68. 1 2
      x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportGetLifecycleAction.java
  69. 2 2
      x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItem.java
  70. 12 34
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java
  71. 10 20
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java
  72. 2 3
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorServiceTests.java
  73. 6 7
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java
  74. 7 12
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleMetadataTests.java
  75. 17 20
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java
  76. 36 72
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java
  77. 38 64
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java
  78. 2 5
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTaskTests.java
  79. 3 7
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTaskTests.java
  80. 13 17
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java
  81. 1 2
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/StagnatingIndicesFinderTests.java
  82. 3 2
      x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportStopILMActionTests.java

+ 4 - 6
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java

@@ -20,8 +20,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -73,17 +71,17 @@ public class AllocateAction implements LifecycleAction {
         Map<String, String> require
     ) {
         if (include == null) {
-            this.include = Collections.emptyMap();
+            this.include = Map.of();
         } else {
             this.include = include;
         }
         if (exclude == null) {
-            this.exclude = Collections.emptyMap();
+            this.exclude = Map.of();
         } else {
             this.exclude = exclude;
         }
         if (require == null) {
-            this.require = Collections.emptyMap();
+            this.require = Map.of();
         } else {
             this.require = require;
         }
@@ -201,7 +199,7 @@ public class AllocateAction implements LifecycleAction {
         }
         UpdateSettingsStep allocateStep = new UpdateSettingsStep(allocateKey, allocationRoutedKey, client, newSettings.build());
         AllocationRoutedStep routedCheckStep = new AllocationRoutedStep(allocationRoutedKey, nextStepKey);
-        return Arrays.asList(allocateStep, routedCheckStep);
+        return List.of(allocateStep, routedCheckStep);
     }
 
     @Override

+ 2 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java

@@ -22,7 +22,7 @@ import org.elasticsearch.common.settings.ClusterSettings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.index.Index;
 
-import java.util.Collections;
+import java.util.List;
 
 import static org.elasticsearch.xpack.core.ilm.step.info.AllocationInfo.allShardsActiveAllocationInfo;
 import static org.elasticsearch.xpack.core.ilm.step.info.AllocationInfo.waitingForActiveShardsAllocationInfo;
@@ -62,7 +62,7 @@ public class AllocationRoutedStep extends ClusterStateWaitStep {
         }
 
         AllocationDeciders allocationDeciders = new AllocationDeciders(
-            Collections.singletonList(
+            List.of(
                 new FilterAllocationDecider(
                     clusterState.getMetadata().settings(),
                     new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)

+ 2 - 3
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteAction.java

@@ -17,7 +17,6 @@ import org.elasticsearch.xcontent.XContentParser;
 
 import java.io.IOException;
 import java.time.Instant;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
 
@@ -99,7 +98,7 @@ public class DeleteAction implements LifecycleAction {
             );
             CleanupSnapshotStep cleanupSnapshotStep = new CleanupSnapshotStep(cleanSnapshotKey, deleteStepKey, client);
             DeleteStep deleteStep = new DeleteStep(deleteStepKey, nextStepKey, client);
-            return Arrays.asList(waitForNoFollowersStep, waitUntilTimeSeriesEndTimeStep, cleanupSnapshotStep, deleteStep);
+            return List.of(waitForNoFollowersStep, waitUntilTimeSeriesEndTimeStep, cleanupSnapshotStep, deleteStep);
         } else {
             WaitForNoFollowersStep waitForNoFollowersStep = new WaitForNoFollowersStep(
                 waitForNoFollowerStepKey,
@@ -113,7 +112,7 @@ public class DeleteAction implements LifecycleAction {
                 client
             );
             DeleteStep deleteStep = new DeleteStep(deleteStepKey, nextStepKey, client);
-            return Arrays.asList(waitForNoFollowersStep, waitUntilTimeSeriesEndTimeStep, deleteStep);
+            return List.of(waitForNoFollowersStep, waitUntilTimeSeriesEndTimeStep, deleteStep);
         }
     }
 

+ 1 - 5
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java

@@ -20,7 +20,6 @@ import org.elasticsearch.common.Strings;
 
 import java.util.Arrays;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 /**
  * Invokes a force merge on a single index.
@@ -67,10 +66,7 @@ public class ForceMergeStep extends AsyncActionStep {
                     policyName,
                     failures == null
                         ? "n/a"
-                        : Strings.collectionToDelimitedString(
-                            Arrays.stream(failures).map(Strings::toString).collect(Collectors.toList()),
-                            ","
-                        ),
+                        : Strings.collectionToDelimitedString(Arrays.stream(failures).map(Strings::toString).toList(), ","),
                     NAME
                 );
                 logger.warn(errorMessage);

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java

@@ -18,7 +18,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -98,7 +97,7 @@ public class FreezeAction implements LifecycleAction {
         );
         CheckNotDataStreamWriteIndexStep checkNoWriteIndexStep = new CheckNotDataStreamWriteIndexStep(checkNotWriteIndex, freezeStepKey);
         FreezeStep freezeStep = new FreezeStep(freezeStepKey, nextStepKey, client);
-        return Arrays.asList(conditionalSkipFreezeStep, checkNoWriteIndexStep, freezeStep);
+        return List.of(conditionalSkipFreezeStep, checkNoWriteIndexStep, freezeStep);
     }
 
     @Override

+ 3 - 4
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java

@@ -26,7 +26,6 @@ import org.elasticsearch.xpack.core.template.resources.TemplateResources;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * A utility class used for index lifecycle policies
@@ -121,7 +120,7 @@ public class LifecyclePolicyUtils {
             .stream()
             .filter(indexMetadata -> policyName.equals(indexMetadata.getLifecyclePolicyName()))
             .map(indexMetadata -> indexMetadata.getIndex().getName())
-            .collect(Collectors.toList());
+            .toList();
 
         final List<String> allDataStreams = indexNameExpressionResolver.dataStreamNames(
             state,
@@ -136,12 +135,12 @@ public class LifecyclePolicyUtils {
             } else {
                 return false;
             }
-        }).collect(Collectors.toList());
+        }).toList();
 
         final List<String> composableTemplates = state.metadata().templatesV2().keySet().stream().filter(templateName -> {
             Settings settings = MetadataIndexTemplateService.resolveSettings(state.metadata(), templateName);
             return policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(settings));
-        }).collect(Collectors.toList());
+        }).toList();
 
         return new ItemUsage(indices, dataStreams, composableTemplates);
     }

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java

@@ -17,7 +17,6 @@ import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
 import java.time.Instant;
-import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -72,7 +71,7 @@ public class ReadOnlyAction implements LifecycleAction {
             client
         );
         ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, nextStepKey, client);
-        return Arrays.asList(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep);
+        return List.of(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep);
     }
 
     @Override

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java

@@ -22,7 +22,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
 
@@ -172,7 +171,7 @@ public class RolloverAction implements LifecycleAction {
             client,
             INDEXING_COMPLETE
         );
-        return Arrays.asList(waitForRolloverReadyStep, rolloverStep, waitForActiveShardsStep, updateDateStep, setIndexingCompleteStep);
+        return List.of(waitForRolloverReadyStep, rolloverStep, waitForActiveShardsStep, updateDateStep, setIndexingCompleteStep);
     }
 
     @Override

+ 1 - 4
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java

@@ -67,10 +67,7 @@ public class SegmentCountStep extends AsyncWaitStep {
                     response.getFailedShards(),
                     failures == null
                         ? "n/a"
-                        : Strings.collectionToDelimitedString(
-                            Arrays.stream(failures).map(Strings::toString).collect(Collectors.toList()),
-                            ","
-                        )
+                        : Strings.collectionToDelimitedString(Arrays.stream(failures).map(Strings::toString).toList(), ",")
                 );
                 listener.onResponse(true, new Info(-1));
             } else {

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java

@@ -21,7 +21,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
@@ -101,7 +100,7 @@ public class SetPriorityAction implements LifecycleAction {
         Settings indexPriority = recoveryPriority == null
             ? NULL_PRIORITY_SETTINGS
             : Settings.builder().put(IndexMetadata.INDEX_PRIORITY_SETTING.getKey(), recoveryPriority).build();
-        return Collections.singletonList(new UpdateSettingsStep(key, nextStepKey, client, indexPriority));
+        return List.of(new UpdateSettingsStep(key, nextStepKey, client, indexPriority));
     }
 
     @Override

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java

@@ -31,7 +31,6 @@ import java.io.IOException;
 import java.time.Instant;
 import java.util.List;
 import java.util.Objects;
-import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
@@ -329,7 +328,7 @@ public class ShrinkAction implements LifecycleAction {
             allowWriteAfterShrinkStep
         );
 
-        return steps.filter(Objects::nonNull).collect(Collectors.toList());
+        return steps.filter(Objects::nonNull).toList();
     }
 
     @Override

+ 6 - 9
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java

@@ -14,7 +14,6 @@ import org.elasticsearch.core.Tuple;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -30,8 +29,6 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-import static java.util.stream.Collectors.toList;
-
 /**
  * Represents the lifecycle of an index from creation to deletion. A
  * {@link TimeseriesLifecycleType} is made up of a set of {@link Phase}s which it will
@@ -114,7 +111,7 @@ public class TimeseriesLifecycleType implements LifecycleType {
     // Set of actions that cannot be defined (executed) after the managed index has been mounted as searchable snapshot.
     // It's ordered to produce consistent error messages which can be unit tested.
     public static final Set<String> ACTIONS_CANNOT_FOLLOW_SEARCHABLE_SNAPSHOT = Collections.unmodifiableSet(
-        new LinkedHashSet<>(Arrays.asList(ForceMergeAction.NAME, FreezeAction.NAME, ShrinkAction.NAME, DownsampleAction.NAME))
+        new LinkedHashSet<>(List.of(ForceMergeAction.NAME, FreezeAction.NAME, ShrinkAction.NAME, DownsampleAction.NAME))
     );
 
     private TimeseriesLifecycleType() {}
@@ -180,11 +177,11 @@ public class TimeseriesLifecycleType implements LifecycleType {
     public List<LifecycleAction> getOrderedActions(Phase phase) {
         Map<String, LifecycleAction> actions = phase.getActions();
         return switch (phase.getName()) {
-            case HOT_PHASE -> ORDERED_VALID_HOT_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).collect(toList());
-            case WARM_PHASE -> ORDERED_VALID_WARM_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).collect(toList());
-            case COLD_PHASE -> ORDERED_VALID_COLD_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).collect(toList());
-            case FROZEN_PHASE -> ORDERED_VALID_FROZEN_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).collect(toList());
-            case DELETE_PHASE -> ORDERED_VALID_DELETE_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).collect(toList());
+            case HOT_PHASE -> ORDERED_VALID_HOT_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).toList();
+            case WARM_PHASE -> ORDERED_VALID_WARM_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).toList();
+            case COLD_PHASE -> ORDERED_VALID_COLD_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).toList();
+            case FROZEN_PHASE -> ORDERED_VALID_FROZEN_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).toList();
+            case DELETE_PHASE -> ORDERED_VALID_DELETE_ACTIONS.stream().map(actions::get).filter(Objects::nonNull).toList();
             default -> throw new IllegalArgumentException("lifecycle type [" + TYPE + "] does not support phase [" + phase.getName() + "]");
         };
     }

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UnfollowAction.java

@@ -17,7 +17,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -72,7 +71,7 @@ public final class UnfollowAction implements LifecycleAction {
         UnfollowFollowerIndexStep step5 = new UnfollowFollowerIndexStep(unfollowFollowerIndex, openFollowerIndex, client);
         OpenIndexStep step6 = new OpenIndexStep(openFollowerIndex, waitForYellowStep, client);
         WaitForIndexColorStep step7 = new WaitForIndexColorStep(waitForYellowStep, nextStepKey, ClusterHealthStatus.YELLOW);
-        return Arrays.asList(conditionalSkipUnfollowStep, step1, step2, step3, step4, step5, step6, step7);
+        return List.of(conditionalSkipUnfollowStep, step1, step2, step3, step4, step5, step6, step7);
     }
 
     @Override

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStep.java

@@ -22,7 +22,6 @@ import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY;
 
@@ -78,7 +77,7 @@ final class WaitForFollowShardTasksStep extends AsyncWaitStep {
                         status.followerGlobalCheckpoint()
                     )
                 )
-                .collect(Collectors.toList());
+                .toList();
             listener.onResponse(false, new Info(shardFollowTaskInfos));
         }
     }

+ 1 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotAction.java

@@ -17,7 +17,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
@@ -62,7 +61,7 @@ public class WaitForSnapshotAction implements LifecycleAction {
     @Override
     public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) {
         StepKey waitForSnapshotKey = new StepKey(phase, NAME, WaitForSnapshotStep.NAME);
-        return Collections.singletonList(new WaitForSnapshotStep(waitForSnapshotKey, nextStepKey, client, policy));
+        return List.of(new WaitForSnapshotStep(waitForSnapshotKey, nextStepKey, client, policy));
     }
 
     @Override

+ 10 - 11
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java

@@ -14,7 +14,6 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -44,20 +43,20 @@ public class AllocateActionTests extends AbstractActionTestCase<AllocateAction>
             includes = randomAllocationRoutingMap(1, 100);
             hasAtLeastOneMap = true;
         } else {
-            includes = randomBoolean() ? null : Collections.emptyMap();
+            includes = randomBoolean() ? null : Map.of();
         }
         Map<String, String> excludes;
         if (randomBoolean()) {
             hasAtLeastOneMap = true;
             excludes = randomAllocationRoutingMap(1, 100);
         } else {
-            excludes = randomBoolean() ? null : Collections.emptyMap();
+            excludes = randomBoolean() ? null : Map.of();
         }
         Map<String, String> requires;
         if (hasAtLeastOneMap == false || randomBoolean()) {
             requires = randomAllocationRoutingMap(1, 100);
         } else {
-            requires = randomBoolean() ? null : Collections.emptyMap();
+            requires = randomBoolean() ? null : Map.of();
         }
         Integer numberOfReplicas = randomBoolean() ? null : randomIntBetween(0, 10);
         Integer totalShardsPerNode = randomBoolean() ? null : randomIntBetween(-1, 10);
@@ -97,9 +96,9 @@ public class AllocateActionTests extends AbstractActionTestCase<AllocateAction>
     }
 
     public void testAllMapsNullOrEmpty() {
-        Map<String, String> include = randomBoolean() ? null : Collections.emptyMap();
-        Map<String, String> exclude = randomBoolean() ? null : Collections.emptyMap();
-        Map<String, String> require = randomBoolean() ? null : Collections.emptyMap();
+        Map<String, String> include = randomBoolean() ? null : Map.of();
+        Map<String, String> exclude = randomBoolean() ? null : Map.of();
+        Map<String, String> require = randomBoolean() ? null : Map.of();
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
             () -> new AllocateAction(null, null, include, exclude, require)
@@ -124,8 +123,8 @@ public class AllocateActionTests extends AbstractActionTestCase<AllocateAction>
 
     public void testInvalidNumberOfReplicas() {
         Map<String, String> include = randomAllocationRoutingMap(1, 5);
-        Map<String, String> exclude = randomBoolean() ? null : Collections.emptyMap();
-        Map<String, String> require = randomBoolean() ? null : Collections.emptyMap();
+        Map<String, String> exclude = randomBoolean() ? null : Map.of();
+        Map<String, String> require = randomBoolean() ? null : Map.of();
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
             () -> new AllocateAction(randomIntBetween(-1000, -1), randomIntBetween(0, 300), include, exclude, require)
@@ -135,8 +134,8 @@ public class AllocateActionTests extends AbstractActionTestCase<AllocateAction>
 
     public void testInvalidTotalShardsPerNode() {
         Map<String, String> include = randomAllocationRoutingMap(1, 5);
-        Map<String, String> exclude = randomBoolean() ? null : Collections.emptyMap();
-        Map<String, String> require = randomBoolean() ? null : Collections.emptyMap();
+        Map<String, String> exclude = randomBoolean() ? null : Map.of();
+        Map<String, String> require = randomBoolean() ? null : Map.of();
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
             () -> new AllocateAction(randomIntBetween(0, 300), randomIntBetween(-1000, -2), include, exclude, require)

+ 3 - 4
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStepTests.java

@@ -27,7 +27,6 @@ import org.elasticsearch.node.Node;
 import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep.Result;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
-import java.util.Collections;
 import java.util.Map;
 
 import static org.elasticsearch.cluster.routing.TestShardRouting.buildUnassignedInfo;
@@ -109,7 +108,7 @@ public class AllocationRoutedStepTests extends AbstractStepTestCase<AllocationRo
 
     public void testRequireConditionMetOnlyOneCopyAllocated() {
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
-        Map<String, String> requires = Collections.singletonMap(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "foo", "bar");
+        Map<String, String> requires = Map.of(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "foo", "bar");
         Settings.Builder existingSettings = Settings.builder()
             .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
             .put(IndexMetadata.SETTING_INDEX_UUID, index.getUUID());
@@ -187,7 +186,7 @@ public class AllocationRoutedStepTests extends AbstractStepTestCase<AllocationRo
 
     public void testExcludeConditionMetOnlyOneCopyAllocated() {
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
-        Map<String, String> excludes = Collections.singletonMap(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "foo", "bar");
+        Map<String, String> excludes = Map.of(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "foo", "bar");
         Settings.Builder existingSettings = Settings.builder()
             .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
             .put(IndexMetadata.SETTING_INDEX_UUID, index.getUUID());
@@ -218,7 +217,7 @@ public class AllocationRoutedStepTests extends AbstractStepTestCase<AllocationRo
 
     public void testIncludeConditionMetOnlyOneCopyAllocated() {
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
-        Map<String, String> includes = Collections.singletonMap(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "foo", "bar");
+        Map<String, String> includes = Map.of(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "foo", "bar");
         Settings.Builder existingSettings = Settings.builder()
             .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
             .put(IndexMetadata.SETTING_INDEX_UUID, index.getUUID());

+ 6 - 6
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStepTests.java

@@ -29,9 +29,9 @@ import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.node.Node;
 
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import static org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata.Type.SIGTERM;
 import static org.elasticsearch.cluster.routing.TestShardRouting.shardRoutingBuilder;
@@ -340,7 +340,7 @@ public class CheckShrinkReadyStepTests extends AbstractStepTestCase<CheckShrinkR
      */
     public void testExecuteReplicasNotAllocatedOnSingleNode() {
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
-        Map<String, String> requires = Collections.singletonMap("_id", "node1");
+        Map<String, String> requires = Map.of("_id", "node1");
         Settings.Builder existingSettings = Settings.builder()
             .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
             .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id", "node1")
@@ -376,7 +376,7 @@ public class CheckShrinkReadyStepTests extends AbstractStepTestCase<CheckShrinkR
 
     public void testExecuteReplicasButCopiesNotPresent() {
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
-        Map<String, String> requires = Collections.singletonMap("_id", "node1");
+        Map<String, String> requires = Map.of("_id", "node1");
         Settings.Builder existingSettings = Settings.builder()
             .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
             .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id", "node1")
@@ -458,7 +458,7 @@ public class CheckShrinkReadyStepTests extends AbstractStepTestCase<CheckShrinkR
                         .putCustom(
                             NodesShutdownMetadata.TYPE,
                             new NodesShutdownMetadata(
-                                Collections.singletonMap(
+                                Map.of(
                                     "node1",
                                     SingleNodeShutdownMetadata.builder()
                                         .setType(type)
@@ -537,7 +537,7 @@ public class CheckShrinkReadyStepTests extends AbstractStepTestCase<CheckShrinkR
                         .putCustom(
                             NodesShutdownMetadata.TYPE,
                             new NodesShutdownMetadata(
-                                Collections.singletonMap(
+                                Map.of(
                                     "node1",
                                     SingleNodeShutdownMetadata.builder()
                                         .setType(type)
@@ -649,7 +649,7 @@ public class CheckShrinkReadyStepTests extends AbstractStepTestCase<CheckShrinkR
             System.currentTimeMillis(),
             delayed,
             UnassignedInfo.AllocationStatus.NO_ATTEMPT,
-            Collections.emptySet(),
+            Set.of(),
             lastAllocatedNodeId
         );
     }

+ 6 - 5
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseFollowerIndexStepTests.java

@@ -13,7 +13,8 @@ import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.index.IndexVersion;
 import org.mockito.Mockito;
 
-import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY;
 import static org.hamcrest.Matchers.equalTo;
@@ -24,7 +25,7 @@ public class CloseFollowerIndexStepTests extends AbstractStepTestCase<CloseFollo
     private static IndexMetadata getIndexMetadata() {
         return IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -38,7 +39,7 @@ public class CloseFollowerIndexStepTests extends AbstractStepTestCase<CloseFollo
             assertThat(closeIndexRequest.indices()[0], equalTo("follower-index"));
             @SuppressWarnings("unchecked")
             ActionListener<CloseIndexResponse> listener = (ActionListener<CloseIndexResponse>) invocation.getArguments()[1];
-            listener.onResponse(new CloseIndexResponse(true, true, Collections.emptyList()));
+            listener.onResponse(new CloseIndexResponse(true, true, List.of()));
             return null;
         }).when(indicesClient).close(Mockito.any(), Mockito.any());
 
@@ -54,7 +55,7 @@ public class CloseFollowerIndexStepTests extends AbstractStepTestCase<CloseFollo
             assertThat(closeIndexRequest.indices()[0], equalTo("follower-index"));
             @SuppressWarnings("unchecked")
             ActionListener<CloseIndexResponse> listener = (ActionListener<CloseIndexResponse>) invocation.getArguments()[1];
-            listener.onResponse(new CloseIndexResponse(false, false, Collections.emptyList()));
+            listener.onResponse(new CloseIndexResponse(false, false, List.of()));
             return null;
         }).when(indicesClient).close(Mockito.any(), Mockito.any());
 
@@ -85,7 +86,7 @@ public class CloseFollowerIndexStepTests extends AbstractStepTestCase<CloseFollo
     public void testCloseFollowerIndexIsNoopForAlreadyClosedIndex() throws Exception {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .state(IndexMetadata.State.CLOSE)
             .numberOfShards(1)
             .numberOfReplicas(0)

+ 2 - 4
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseIndexStepTests.java

@@ -20,7 +20,7 @@ import org.junit.Before;
 import org.mockito.Mockito;
 import org.mockito.stubbing.Answer;
 
-import java.util.Collections;
+import java.util.List;
 
 import static org.hamcrest.Matchers.equalTo;
 
@@ -77,9 +77,7 @@ public class CloseIndexStepTests extends AbstractStepTestCase<CloseIndexStep> {
             @SuppressWarnings("unchecked")
             ActionListener<CloseIndexResponse> listener = (ActionListener<CloseIndexResponse>) invocation.getArguments()[1];
             assertThat(request.indices(), equalTo(new String[] { indexMetadata.getIndex().getName() }));
-            listener.onResponse(
-                new CloseIndexResponse(true, true, Collections.singletonList(new CloseIndexResponse.IndexResult(indexMetadata.getIndex())))
-            );
+            listener.onResponse(new CloseIndexResponse(true, true, List.of(new CloseIndexResponse.IndexResult(indexMetadata.getIndex()))));
             return null;
         }).when(indicesClient).close(Mockito.any(), Mockito.any());
 

+ 4 - 5
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStepTests.java

@@ -20,7 +20,6 @@ import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;
 import java.time.Clock;
 import java.time.Instant;
 import java.time.ZoneId;
-import java.util.Collections;
 import java.util.Map;
 import java.util.UUID;
 
@@ -83,7 +82,7 @@ public class ClusterStateWaitUntilThresholdStepTests extends AbstractStepTestCas
                         .put(LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD, "480h")
                 )
                 .putCustom(ILM_CUSTOM_METADATA_KEY, Map.of("step_time", String.valueOf(System.currentTimeMillis())))
-                .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+                .putCustom(CCR_METADATA_KEY, Map.of())
                 .numberOfShards(1)
                 .numberOfReplicas(0)
                 .build();
@@ -107,7 +106,7 @@ public class ClusterStateWaitUntilThresholdStepTests extends AbstractStepTestCas
                         .put(LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD, "48h")
                 )
                 .putCustom(ILM_CUSTOM_METADATA_KEY, Map.of("step_time", String.valueOf(System.currentTimeMillis())))
-                .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+                .putCustom(CCR_METADATA_KEY, Map.of())
                 .numberOfShards(1)
                 .numberOfReplicas(0)
                 .build();
@@ -140,7 +139,7 @@ public class ClusterStateWaitUntilThresholdStepTests extends AbstractStepTestCas
                     settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true")
                         .put(LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD, "1s")
                 )
-                .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+                .putCustom(CCR_METADATA_KEY, Map.of())
                 .putCustom(ILM_CUSTOM_METADATA_KEY, Map.of("step_time", String.valueOf(1234L)))
                 .numberOfShards(1)
                 .numberOfReplicas(0)
@@ -168,7 +167,7 @@ public class ClusterStateWaitUntilThresholdStepTests extends AbstractStepTestCas
                     settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "false")
                         .put(LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD, "1h")
                 )
-                .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+                .putCustom(CCR_METADATA_KEY, Map.of())
                 .putCustom(ILM_CUSTOM_METADATA_KEY, Map.of("step_time", String.valueOf(1234L)))
                 .numberOfShards(1)
                 .numberOfReplicas(0)

+ 1 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponseTests.java

@@ -18,7 +18,6 @@ import org.elasticsearch.xcontent.ParseField;
 import org.elasticsearch.xcontent.XContentParser;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -81,7 +80,7 @@ public class ExplainLifecycleResponseTests extends AbstractXContentSerializingTe
 
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
+            List.of(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
         );
     }
 

+ 1 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeActionTests.java

@@ -20,7 +20,6 @@ import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.stream.Collectors;
 
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.equalTo;
@@ -109,7 +108,7 @@ public class ForceMergeActionTests extends AbstractActionTestCase<ForceMergeActi
             // available
             .skip(1)
             .map(s -> new Tuple<>(s.getKey(), s.getNextStepKey()))
-            .collect(Collectors.toList());
+            .toList();
 
         StepKey checkNotWriteIndex = new StepKey(phase, ForceMergeAction.NAME, CheckNotDataStreamWriteIndexStep.NAME);
         StepKey waitTimeSeriesEndTimePassesKey = new StepKey(phase, ForceMergeAction.NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME);

+ 3 - 3
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStepTests.java

@@ -17,7 +17,7 @@ import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.index.IndexVersion;
 
-import java.util.Collections;
+import java.util.List;
 import java.util.Locale;
 
 import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
@@ -82,7 +82,7 @@ public class GenerateSnapshotNameStepTests extends AbstractStepTestCase<Generate
             .metadata(
                 Metadata.builder()
                     .put(indexMetadata, false)
-                    .putCustom(RepositoriesMetadata.TYPE, new RepositoriesMetadata(Collections.singletonList(repo)))
+                    .putCustom(RepositoriesMetadata.TYPE, new RepositoriesMetadata(List.of(repo)))
                     .build()
             )
             .build();
@@ -167,7 +167,7 @@ public class GenerateSnapshotNameStepTests extends AbstractStepTestCase<Generate
             .metadata(
                 Metadata.builder()
                     .put(indexMetadata, false)
-                    .putCustom(RepositoriesMetadata.TYPE, new RepositoriesMetadata(Collections.singletonList(repo)))
+                    .putCustom(RepositoriesMetadata.TYPE, new RepositoriesMetadata(List.of(repo)))
                     .build()
             )
             .build();

+ 2 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleExplainResponseTests.java

@@ -23,7 +23,7 @@ import org.elasticsearch.xcontent.XContentBuilder;
 import org.elasticsearch.xcontent.XContentParser;
 
 import java.io.IOException;
-import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
 import java.util.function.Supplier;
 
@@ -292,7 +292,7 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
 
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
+            List.of(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
         );
     }
 

+ 1 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyClientTests.java

@@ -21,7 +21,6 @@ import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.xpack.core.ClientHelper;
 import org.mockito.Mockito;
 
-import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 
@@ -56,7 +55,7 @@ public class LifecyclePolicyClientTests extends ESTestCase {
 
         SearchRequest request = new SearchRequest("foo");
 
-        final var policyClient = new LifecyclePolicySecurityClient(client, ClientHelper.INDEX_LIFECYCLE_ORIGIN, Collections.emptyMap());
+        final var policyClient = new LifecyclePolicySecurityClient(client, ClientHelper.INDEX_LIFECYCLE_ORIGIN, Map.of());
         policyClient.execute(TransportSearchAction.TYPE, request, listener);
 
         latch.await();

+ 2 - 3
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyMetadataTests.java

@@ -18,7 +18,6 @@ import org.junit.Before;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,7 +36,7 @@ public class LifecyclePolicyMetadataTests extends AbstractXContentSerializingTes
     @Override
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(
+            List.of(
                 new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new),
                 new NamedWriteableRegistry.Entry(
                     LifecycleType.class,
@@ -65,7 +64,7 @@ public class LifecyclePolicyMetadataTests extends AbstractXContentSerializingTes
     protected NamedXContentRegistry xContentRegistry() {
         List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
         entries.addAll(
-            Arrays.asList(
+            List.of(
                 new NamedXContentRegistry.Entry(
                     LifecycleType.class,
                     new ParseField(TimeseriesLifecycleType.TYPE),

+ 18 - 24
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java

@@ -20,8 +20,6 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -30,7 +28,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
-import java.util.stream.Collectors;
 
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.instanceOf;
@@ -48,7 +45,7 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
     @Override
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(
+            List.of(
                 new NamedWriteableRegistry.Entry(
                     LifecycleType.class,
                     TimeseriesLifecycleType.TYPE,
@@ -75,7 +72,7 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
     protected NamedXContentRegistry xContentRegistry() {
         List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
         entries.addAll(
-            Arrays.asList(
+            List.of(
                 new NamedXContentRegistry.Entry(
                     LifecycleType.class,
                     new ParseField(TimeseriesLifecycleType.TYPE),
@@ -150,7 +147,7 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
         ).stream()
             // Remove the frozen phase, we'll randomly re-add it later
             .filter(pn -> TimeseriesLifecycleType.FROZEN_PHASE.equals(pn) == false)
-            .collect(Collectors.toList());
+            .toList();
 
         // let's order the phases so we can reason about actions in a previous phase in order to generate a random *valid* policy
         List<String> orderedPhases = new ArrayList<>(phaseNames.size());
@@ -218,7 +215,7 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
                 new Phase(
                     TimeseriesLifecycleType.FROZEN_PHASE,
                     frozenTime,
-                    Collections.singletonMap(
+                    Map.of(
                         SearchableSnapshotAction.NAME,
                         new SearchableSnapshotAction(
                             randomAlphaOfLength(10),
@@ -300,11 +297,11 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
                     () -> randomFrom(
                         TimeseriesLifecycleType.ORDERED_VALID_PHASES.stream()
                             .filter(pn -> TimeseriesLifecycleType.FROZEN_PHASE.equals(pn) == false)
-                            .collect(Collectors.toList())
+                            .toList()
                     )
                 );
                 phases = new LinkedHashMap<>(phases);
-                phases.put(phaseName, new Phase(phaseName, null, Collections.emptyMap()));
+                phases.put(phaseName, new Phase(phaseName, null, Map.of()));
             }
             case 2 -> metadata = randomValueOtherThan(metadata, LifecyclePolicyTests::randomMeta);
             case 3 -> deprecated = instance.isDeprecated() ? randomFrom(false, null) : true;
@@ -337,8 +334,8 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
 
         lifecycleName = randomAlphaOfLengthBetween(1, 20);
         Map<String, Phase> phases = new LinkedHashMap<>();
-        LifecycleAction firstAction = new MockAction(Arrays.asList(mockStep));
-        Map<String, LifecycleAction> actions = Collections.singletonMap(MockAction.NAME, firstAction);
+        LifecycleAction firstAction = new MockAction(List.of(mockStep));
+        Map<String, LifecycleAction> actions = Map.of(MockAction.NAME, firstAction);
         Phase firstPhase = new Phase("test", TimeValue.ZERO, actions);
         phases.put(firstPhase.getName(), firstPhase);
         LifecyclePolicy policy = new LifecyclePolicy(TestLifecycleType.INSTANCE, lifecycleName, phases, randomMeta());
@@ -372,10 +369,10 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
 
         lifecycleName = randomAlphaOfLengthBetween(1, 20);
         Map<String, Phase> phases = new LinkedHashMap<>();
-        LifecycleAction firstAction = new MockAction(Arrays.asList(firstActionStep, firstActionAnotherStep));
-        LifecycleAction secondAction = new MockAction(Arrays.asList(secondActionStep));
-        Map<String, LifecycleAction> firstActions = Collections.singletonMap(MockAction.NAME, firstAction);
-        Map<String, LifecycleAction> secondActions = Collections.singletonMap(MockAction.NAME, secondAction);
+        LifecycleAction firstAction = new MockAction(List.of(firstActionStep, firstActionAnotherStep));
+        LifecycleAction secondAction = new MockAction(List.of(secondActionStep));
+        Map<String, LifecycleAction> firstActions = Map.of(MockAction.NAME, firstAction);
+        Map<String, LifecycleAction> secondActions = Map.of(MockAction.NAME, secondAction);
         Phase firstPhase = new Phase("first_phase", TimeValue.ZERO, firstActions);
         Phase secondPhase = new Phase("second_phase", TimeValue.ZERO, secondActions);
         phases.put(firstPhase.getName(), firstPhase);
@@ -401,10 +398,10 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
 
     public void testIsActionSafe() {
         Map<String, Phase> phases = new LinkedHashMap<>();
-        LifecycleAction firstAction = new MockAction(Collections.emptyList(), true);
-        LifecycleAction secondAction = new MockAction(Collections.emptyList(), false);
-        Map<String, LifecycleAction> firstActions = Collections.singletonMap(MockAction.NAME, firstAction);
-        Map<String, LifecycleAction> secondActions = Collections.singletonMap(MockAction.NAME, secondAction);
+        LifecycleAction firstAction = new MockAction(List.of(), true);
+        LifecycleAction secondAction = new MockAction(List.of(), false);
+        Map<String, LifecycleAction> firstActions = Map.of(MockAction.NAME, firstAction);
+        Map<String, LifecycleAction> secondActions = Map.of(MockAction.NAME, secondAction);
         Phase firstPhase = new Phase("first_phase", TimeValue.ZERO, firstActions);
         Phase secondPhase = new Phase("second_phase", TimeValue.ZERO, secondActions);
         phases.put(firstPhase.getName(), firstPhase);
@@ -458,12 +455,9 @@ public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<Li
     public static Map<String, Object> randomMeta() {
         if (randomBoolean()) {
             if (randomBoolean()) {
-                return Collections.singletonMap(randomAlphaOfLength(4), randomAlphaOfLength(4));
+                return Map.of(randomAlphaOfLength(4), randomAlphaOfLength(4));
             } else {
-                return Collections.singletonMap(
-                    randomAlphaOfLength(5),
-                    Collections.singletonMap(randomAlphaOfLength(4), randomAlphaOfLength(4))
-                );
+                return Map.of(randomAlphaOfLength(5), Map.of(randomAlphaOfLength(4), randomAlphaOfLength(4)));
             }
         } else {
             return null;

+ 16 - 18
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtilsTests.java

@@ -23,8 +23,8 @@ import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.indices.EmptySystemIndices;
 import org.elasticsearch.test.ESTestCase;
 
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 import static org.hamcrest.Matchers.equalTo;
 
@@ -40,7 +40,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
             ClusterState state = ClusterState.builder(new ClusterName("mycluster")).build();
             assertThat(
                 LifecyclePolicyUtils.calculateUsage(iner, state, "mypolicy"),
-                equalTo(new ItemUsage(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))
+                equalTo(new ItemUsage(List.of(), List.of(), List.of()))
             );
         }
 
@@ -52,7 +52,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
                             new IndexLifecycleMetadata(
-                                Collections.singletonMap("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
+                                Map.of("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
                                 OperationMode.RUNNING
                             )
                         )
@@ -61,7 +61,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                 .build();
             assertThat(
                 LifecyclePolicyUtils.calculateUsage(iner, state, "mypolicy"),
-                equalTo(new ItemUsage(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))
+                equalTo(new ItemUsage(List.of(), List.of(), List.of()))
             );
         }
 
@@ -73,7 +73,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
                             new IndexLifecycleMetadata(
-                                Collections.singletonMap("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
+                                Map.of("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
                                 OperationMode.RUNNING
                             )
                         )
@@ -86,7 +86,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                 .build();
             assertThat(
                 LifecyclePolicyUtils.calculateUsage(iner, state, "mypolicy"),
-                equalTo(new ItemUsage(Collections.singleton("myindex"), Collections.emptyList(), Collections.emptyList()))
+                equalTo(new ItemUsage(List.of("myindex"), List.of(), List.of()))
             );
         }
 
@@ -98,7 +98,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
                             new IndexLifecycleMetadata(
-                                Collections.singletonMap("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
+                                Map.of("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
                                 OperationMode.RUNNING
                             )
                         )
@@ -109,10 +109,10 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                         .putCustom(
                             ComposableIndexTemplateMetadata.TYPE,
                             new ComposableIndexTemplateMetadata(
-                                Collections.singletonMap(
+                                Map.of(
                                     "mytemplate",
                                     ComposableIndexTemplate.builder()
-                                        .indexPatterns(Collections.singletonList("myds"))
+                                        .indexPatterns(List.of("myds"))
                                         .template(
                                             new Template(
                                                 Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy").build(),
@@ -130,7 +130,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                 .build();
             assertThat(
                 LifecyclePolicyUtils.calculateUsage(iner, state, "mypolicy"),
-                equalTo(new ItemUsage(Collections.singleton("myindex"), Collections.emptyList(), Collections.singleton("mytemplate")))
+                equalTo(new ItemUsage(List.of("myindex"), List.of(), List.of("mytemplate")))
             );
         }
 
@@ -139,7 +139,7 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                 .putCustom(
                     IndexLifecycleMetadata.TYPE,
                     new IndexLifecycleMetadata(
-                        Collections.singletonMap("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
+                        Map.of("mypolicy", LifecyclePolicyMetadataTests.createRandomPolicyMetadata("mypolicy")),
                         OperationMode.RUNNING
                     )
                 )
@@ -159,10 +159,10 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                 .putCustom(
                     ComposableIndexTemplateMetadata.TYPE,
                     new ComposableIndexTemplateMetadata(
-                        Collections.singletonMap(
+                        Map.of(
                             "mytemplate",
                             ComposableIndexTemplate.builder()
-                                .indexPatterns(Collections.singletonList("myds"))
+                                .indexPatterns(List.of("myds"))
                                 .template(
                                     new Template(Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy").build(), null, null)
                                 )
@@ -172,15 +172,13 @@ public class LifecyclePolicyUtilsTests extends ESTestCase {
                     )
                 );
             // Need to get the real Index instance of myindex:
-            mBuilder.put(DataStreamTestHelper.newInstance("myds", Collections.singletonList(mBuilder.get("myindex").getIndex())));
+            mBuilder.put(DataStreamTestHelper.newInstance("myds", List.of(mBuilder.get("myindex").getIndex())));
 
             // Test where policy exists and is used by an index, datastream, and template
             ClusterState state = ClusterState.builder(new ClusterName("mycluster")).metadata(mBuilder.build()).build();
             assertThat(
                 LifecyclePolicyUtils.calculateUsage(iner, state, "mypolicy"),
-                equalTo(
-                    new ItemUsage(Arrays.asList("myindex", "another"), Collections.singleton("myds"), Collections.singleton("mytemplate"))
-                )
+                equalTo(new ItemUsage(List.of("myindex", "another"), List.of("myds"), List.of("mytemplate")))
             );
         }
     }

+ 2 - 4
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockAction.java

@@ -15,10 +15,8 @@ import org.elasticsearch.xcontent.XContentParser;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 public class MockAction implements LifecycleAction {
     public static final String NAME = "TEST_ACTION";
@@ -32,7 +30,7 @@ public class MockAction implements LifecycleAction {
     }
 
     public MockAction() {
-        this(Collections.emptyList());
+        this(List.of());
     }
 
     public MockAction(List<Step> steps) {
@@ -77,7 +75,7 @@ public class MockAction implements LifecycleAction {
 
     @Override
     public void writeTo(StreamOutput out) throws IOException {
-        out.writeCollection(steps.stream().map(MockStep::new).collect(Collectors.toList()));
+        out.writeCollection(steps.stream().map(MockStep::new).toList());
         out.writeBoolean(safe);
     }
 

+ 4 - 5
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/OperationModeUpdateTaskTests.java

@@ -14,7 +14,6 @@ import org.elasticsearch.test.ESTestCase;
 import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata;
 import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats;
 
-import java.util.Collections;
 import java.util.Map;
 import java.util.Optional;
 
@@ -97,9 +96,9 @@ public class OperationModeUpdateTaskTests extends ESTestCase {
         OperationMode requestMode,
         boolean assertSameClusterState
     ) {
-        IndexLifecycleMetadata indexLifecycleMetadata = new IndexLifecycleMetadata(Collections.emptyMap(), currentMode);
+        IndexLifecycleMetadata indexLifecycleMetadata = new IndexLifecycleMetadata(Map.of(), currentMode);
         SnapshotLifecycleMetadata snapshotLifecycleMetadata = new SnapshotLifecycleMetadata(
-            Collections.emptyMap(),
+            Map.of(),
             currentMode,
             new SnapshotLifecycleStats()
         );
@@ -131,9 +130,9 @@ public class OperationModeUpdateTaskTests extends ESTestCase {
         OperationMode requestMode,
         boolean assertSameClusterState
     ) {
-        IndexLifecycleMetadata indexLifecycleMetadata = new IndexLifecycleMetadata(Collections.emptyMap(), currentMode);
+        IndexLifecycleMetadata indexLifecycleMetadata = new IndexLifecycleMetadata(Map.of(), currentMode);
         SnapshotLifecycleMetadata snapshotLifecycleMetadata = new SnapshotLifecycleMetadata(
-            Collections.emptyMap(),
+            Map.of(),
             currentMode,
             new SnapshotLifecycleStats()
         );

+ 7 - 7
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PauseFollowerIndexStepTests.java

@@ -22,7 +22,7 @@ import org.elasticsearch.xpack.core.ccr.action.PauseFollowAction;
 import org.elasticsearch.xpack.core.ccr.action.ShardFollowTask;
 import org.mockito.Mockito;
 
-import java.util.Collections;
+import java.util.Map;
 
 import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY;
 import static org.hamcrest.Matchers.equalTo;
@@ -38,7 +38,7 @@ public class PauseFollowerIndexStepTests extends AbstractUnfollowIndexStepTestCa
     public void testPauseFollowingIndex() throws Exception {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -60,7 +60,7 @@ public class PauseFollowerIndexStepTests extends AbstractUnfollowIndexStepTestCa
     public void testRequestNotAcknowledged() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -81,7 +81,7 @@ public class PauseFollowerIndexStepTests extends AbstractUnfollowIndexStepTestCa
     public void testPauseFollowingIndexFailed() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -107,7 +107,7 @@ public class PauseFollowerIndexStepTests extends AbstractUnfollowIndexStepTestCa
     public final void testNoShardFollowPersistentTasks() throws Exception {
         IndexMetadata indexMetadata = IndexMetadata.builder("managed-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -138,7 +138,7 @@ public class PauseFollowerIndexStepTests extends AbstractUnfollowIndexStepTestCa
 
         IndexMetadata followerIndex = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -171,7 +171,7 @@ public class PauseFollowerIndexStepTests extends AbstractUnfollowIndexStepTestCa
                     new ByteSizeValue(512, ByteSizeUnit.MB),
                     TimeValue.timeValueMillis(10),
                     TimeValue.timeValueMillis(10),
-                    Collections.emptyMap()
+                    Map.of()
                 ),
                 null
             );

+ 12 - 13
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java

@@ -21,7 +21,6 @@ import org.elasticsearch.xcontent.NamedXContentRegistry;
 import org.elasticsearch.xcontent.ParseField;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -84,9 +83,9 @@ public class PhaseCacheManagementTests extends ESTestCase {
         actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
         actions.put("set_priority", new SetPriorityAction(100));
         Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-        Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+        Map<String, Phase> phases = Map.of("hot", hotPhase);
         LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(newPolicy, Collections.emptyMap(), 2L, 2L);
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(newPolicy, Map.of(), 2L, 2L);
 
         ClusterState existingState = ClusterState.builder(ClusterState.EMPTY_STATE)
             .metadata(Metadata.builder(Metadata.EMPTY_METADATA).put(meta, false).build())
@@ -315,7 +314,7 @@ public class PhaseCacheManagementTests extends ESTestCase {
             actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
             actions.put("set_priority", new SetPriorityAction(100));
             Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-            Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+            Map<String, Phase> phases = Map.of("hot", hotPhase);
             LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
 
             assertTrue(isIndexPhaseDefinitionUpdatable(REGISTRY, client, meta, newPolicy, null));
@@ -351,7 +350,7 @@ public class PhaseCacheManagementTests extends ESTestCase {
             Map<String, LifecycleAction> actions = new HashMap<>();
             actions.put("set_priority", new SetPriorityAction(150));
             Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-            Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+            Map<String, Phase> phases = Map.of("hot", hotPhase);
             LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
 
             assertFalse(isIndexPhaseDefinitionUpdatable(REGISTRY, client, meta, newPolicy, null));
@@ -390,7 +389,7 @@ public class PhaseCacheManagementTests extends ESTestCase {
                 new RolloverAction(null, null, TimeValue.timeValueSeconds(5), null, null, null, null, null, null, null)
             );
             Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-            Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+            Map<String, Phase> phases = Map.of("hot", hotPhase);
             LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
 
             assertFalse(isIndexPhaseDefinitionUpdatable(REGISTRY, client, meta, newPolicy, null));
@@ -422,7 +421,7 @@ public class PhaseCacheManagementTests extends ESTestCase {
             actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
             actions.put("set_priority", new SetPriorityAction(100));
             Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-            Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+            Map<String, Phase> phases = Map.of("hot", hotPhase);
             LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
 
             assertFalse(isIndexPhaseDefinitionUpdatable(REGISTRY, client, meta, newPolicy, null));
@@ -443,7 +442,7 @@ public class PhaseCacheManagementTests extends ESTestCase {
             actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
             actions.put("set_priority", new SetPriorityAction(100));
             Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-            Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+            Map<String, Phase> phases = Map.of("hot", hotPhase);
             LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
 
             assertFalse(isIndexPhaseDefinitionUpdatable(REGISTRY, client, meta, newPolicy, null));
@@ -482,16 +481,16 @@ public class PhaseCacheManagementTests extends ESTestCase {
         oldActions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
         oldActions.put("set_priority", new SetPriorityAction(100));
         Phase oldHotPhase = new Phase("hot", TimeValue.ZERO, oldActions);
-        Map<String, Phase> oldPhases = Collections.singletonMap("hot", oldHotPhase);
+        Map<String, Phase> oldPhases = Map.of("hot", oldHotPhase);
         LifecyclePolicy oldPolicy = new LifecyclePolicy("my-policy", oldPhases);
 
         Map<String, LifecycleAction> actions = new HashMap<>();
         actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
         actions.put("set_priority", new SetPriorityAction(100));
         Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-        Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+        Map<String, Phase> phases = Map.of("hot", hotPhase);
         LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(newPolicy, Collections.emptyMap(), 2L, 2L);
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(newPolicy, Map.of(), 2L, 2L);
 
         assertTrue(isIndexPhaseDefinitionUpdatable(REGISTRY, client, meta, newPolicy, null));
 
@@ -509,9 +508,9 @@ public class PhaseCacheManagementTests extends ESTestCase {
         actions.put("rollover", new RolloverAction(null, null, null, 2L, null, null, null, null, null, null));
         actions.put("set_priority", new SetPriorityAction(150));
         hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-        phases = Collections.singletonMap("hot", hotPhase);
+        phases = Map.of("hot", hotPhase);
         newPolicy = new LifecyclePolicy("my-policy", phases);
-        policyMetadata = new LifecyclePolicyMetadata(newPolicy, Collections.emptyMap(), 2L, 2L);
+        policyMetadata = new LifecyclePolicyMetadata(newPolicy, Map.of(), 2L, 2L);
 
         logger.info("--> update with changed policy, but not configured in settings");
         updatedState = updateIndicesForPolicy(existingState, REGISTRY, client, oldPolicy, policyMetadata, null);

+ 2 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseExecutionInfoTests.java

@@ -18,7 +18,7 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.junit.Before;
 
 import java.io.IOException;
-import java.util.Arrays;
+import java.util.List;
 
 public class PhaseExecutionInfoTests extends AbstractXContentSerializingTestCase<PhaseExecutionInfo> {
 
@@ -71,7 +71,7 @@ public class PhaseExecutionInfoTests extends AbstractXContentSerializingTestCase
 
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
+            List.of(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
         );
     }
 

+ 6 - 7
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseTests.java

@@ -18,9 +18,8 @@ import org.elasticsearch.xcontent.XContentParser;
 import org.junit.Before;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -42,9 +41,9 @@ public class PhaseTests extends AbstractXContentSerializingTestCase<Phase> {
         if (randomBoolean()) {
             after = randomTimeValue(0, 1_000_000_000, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS);
         }
-        Map<String, LifecycleAction> actions = Collections.emptyMap();
+        Map<String, LifecycleAction> actions = Map.of();
         if (randomBoolean()) {
-            actions = Collections.singletonMap(MockAction.NAME, new MockAction());
+            actions = Map.of(MockAction.NAME, new MockAction());
         }
         return new Phase(phaseName, after, actions);
     }
@@ -61,7 +60,7 @@ public class PhaseTests extends AbstractXContentSerializingTestCase<Phase> {
 
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
+            List.of(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))
         );
     }
 
@@ -85,7 +84,7 @@ public class PhaseTests extends AbstractXContentSerializingTestCase<Phase> {
             case 1 -> after = TimeValue.timeValueSeconds(after.getSeconds() + randomIntBetween(1, 1000));
             case 2 -> {
                 actions = new HashMap<>(actions);
-                actions.put(MockAction.NAME + "another", new MockAction(Collections.emptyList()));
+                actions.put(MockAction.NAME + "another", new MockAction(List.of()));
             }
             default -> throw new AssertionError("Illegal randomisation branch");
         }
@@ -93,7 +92,7 @@ public class PhaseTests extends AbstractXContentSerializingTestCase<Phase> {
     }
 
     public void testDefaultAfter() {
-        Phase phase = new Phase(randomAlphaOfLength(20), null, Collections.emptyMap());
+        Phase phase = new Phase(randomAlphaOfLength(20), null, Map.of());
         assertEquals(TimeValue.ZERO, phase.getMinimumAge());
     }
 }

+ 3 - 7
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverStepTests.java

@@ -23,9 +23,9 @@ import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 import org.hamcrest.Matchers;
 import org.mockito.Mockito;
 
-import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.newInstance;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -185,7 +185,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
             @SuppressWarnings("unchecked")
             ActionListener<RolloverResponse> listener = (ActionListener<RolloverResponse>) invocation.getArguments()[1];
             assertRolloverIndexRequest(request, rolloverTarget);
-            listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), true, true, true, false));
+            listener.onResponse(new RolloverResponse(null, null, Map.of(), request.isDryRun(), true, true, true, false));
             return null;
         }).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
     }
@@ -214,11 +214,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
             .putAlias(AliasMetadata.builder(rolloverAlias))
             .settings(settings(IndexVersion.current()).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, rolloverAlias))
             .putRolloverInfo(
-                new RolloverInfo(
-                    rolloverAlias,
-                    Collections.singletonList(new MaxSizeCondition(ByteSizeValue.ofBytes(2L))),
-                    System.currentTimeMillis()
-                )
+                new RolloverInfo(rolloverAlias, List.of(new MaxSizeCondition(ByteSizeValue.ofBytes(2L))), System.currentTimeMillis())
             )
             .numberOfShards(randomIntBetween(1, 5))
             .numberOfReplicas(randomIntBetween(0, 5))

+ 5 - 5
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java

@@ -77,14 +77,14 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
         ShardSegments shardSegmentsOne = Mockito.mock(ShardSegments.class);
         ShardSegments[] shardSegmentsArray = new ShardSegments[] { shardSegmentsOne };
         IndexShardSegments indexShardSegments = new IndexShardSegments(ShardId.fromString("[idx][123]"), shardSegmentsArray);
-        Map<Integer, IndexShardSegments> indexShards = Collections.singletonMap(0, indexShardSegments);
+        Map<Integer, IndexShardSegments> indexShards = Map.of(0, indexShardSegments);
         Spliterator<IndexShardSegments> iss = indexShards.values().spliterator();
         List<Segment> segments = new ArrayList<>();
         for (int i = 0; i < maxNumSegments - randomIntBetween(0, 3); i++) {
             segments.add(null);
         }
         Mockito.when(indicesSegmentResponse.getStatus()).thenReturn(RestStatus.OK);
-        Mockito.when(indicesSegmentResponse.getIndices()).thenReturn(Collections.singletonMap(index.getName(), indexSegments));
+        Mockito.when(indicesSegmentResponse.getIndices()).thenReturn(Map.of(index.getName(), indexSegments));
         Mockito.when(indexSegments.spliterator()).thenReturn(iss);
         Mockito.when(shardSegmentsOne.getSegments()).thenReturn(segments);
 
@@ -129,14 +129,14 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
         ShardSegments shardSegmentsOne = Mockito.mock(ShardSegments.class);
         ShardSegments[] shardSegmentsArray = new ShardSegments[] { shardSegmentsOne };
         IndexShardSegments indexShardSegments = new IndexShardSegments(ShardId.fromString("[idx][123]"), shardSegmentsArray);
-        Map<Integer, IndexShardSegments> indexShards = Collections.singletonMap(0, indexShardSegments);
+        Map<Integer, IndexShardSegments> indexShards = Map.of(0, indexShardSegments);
         Spliterator<IndexShardSegments> iss = indexShards.values().spliterator();
         List<Segment> segments = new ArrayList<>();
         for (int i = 0; i < maxNumSegments + randomIntBetween(1, 3); i++) {
             segments.add(null);
         }
         Mockito.when(indicesSegmentResponse.getStatus()).thenReturn(RestStatus.OK);
-        Mockito.when(indicesSegmentResponse.getIndices()).thenReturn(Collections.singletonMap(index.getName(), indexSegments));
+        Mockito.when(indicesSegmentResponse.getIndices()).thenReturn(Map.of(index.getName(), indexSegments));
         Mockito.when(indexSegments.spliterator()).thenReturn(iss);
         Mockito.when(shardSegmentsOne.getSegments()).thenReturn(segments);
 
@@ -181,7 +181,7 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
         ShardSegments shardSegmentsOne = Mockito.mock(ShardSegments.class);
         ShardSegments[] shardSegmentsArray = new ShardSegments[] { shardSegmentsOne };
         IndexShardSegments indexShardSegments = new IndexShardSegments(ShardId.fromString("[idx][123]"), shardSegmentsArray);
-        Map<Integer, IndexShardSegments> indexShards = Collections.singletonMap(0, indexShardSegments);
+        Map<Integer, IndexShardSegments> indexShards = Map.of(0, indexShardSegments);
         Spliterator<IndexShardSegments> iss = indexShards.values().spliterator();
         List<Segment> segments = new ArrayList<>();
         for (int i = 0; i < maxNumSegments + randomIntBetween(1, 3); i++) {

+ 4 - 7
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java

@@ -28,8 +28,8 @@ import org.junit.Before;
 import org.mockito.Mockito;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -203,11 +203,11 @@ public class ShrinkActionTests extends AbstractActionTestCase<ShrinkAction> {
 
         LifecyclePolicy policy = new LifecyclePolicy(
             lifecycleName,
-            Collections.singletonMap("warm", new Phase("warm", TimeValue.ZERO, Collections.singletonMap(action.getWriteableName(), action)))
+            Map.of("warm", new Phase("warm", TimeValue.ZERO, Map.of(action.getWriteableName(), action)))
         );
         LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(
             policy,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -216,10 +216,7 @@ public class ShrinkActionTests extends AbstractActionTestCase<ShrinkAction> {
                 Metadata.builder()
                     .putCustom(
                         IndexLifecycleMetadata.TYPE,
-                        new IndexLifecycleMetadata(
-                            Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                            OperationMode.RUNNING
-                        )
+                        new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.RUNNING)
                     )
                     .put(
                         indexMetadataBuilder.putCustom(

+ 1 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStepTests.java

@@ -17,7 +17,6 @@ import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 import org.mockito.Mockito;
 import org.mockito.stubbing.Answer;
 
-import java.util.Arrays;
 import java.util.List;
 
 import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
@@ -73,7 +72,7 @@ public class ShrinkSetAliasStepTests extends AbstractStepTestCase<ShrinkSetAlias
 
         String sourceIndex = indexMetadata.getIndex().getName();
         String shrunkenIndex = SHRUNKEN_INDEX_PREFIX + sourceIndex;
-        List<AliasActions> expectedAliasActions = Arrays.asList(
+        List<AliasActions> expectedAliasActions = List.of(
             IndicesAliasesRequest.AliasActions.removeIndex().index(sourceIndex),
             IndicesAliasesRequest.AliasActions.add().index(shrunkenIndex).alias(sourceIndex),
             IndicesAliasesRequest.AliasActions.add()

+ 2 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkStepTests.java

@@ -21,8 +21,8 @@ import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 import org.mockito.Mockito;
 
-import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 
 import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
 import static org.elasticsearch.common.IndexNameGenerator.generateValidIndexName;
@@ -101,7 +101,7 @@ public class ShrinkStepTests extends AbstractStepTestCase<ShrinkStep> {
             @SuppressWarnings("unchecked")
             ActionListener<CreateIndexResponse> listener = (ActionListener<CreateIndexResponse>) invocation.getArguments()[1];
             assertThat(request.getSourceIndex(), equalTo(sourceIndexMetadata.getIndex().getName()));
-            assertThat(request.getTargetIndexRequest().aliases(), equalTo(Collections.emptySet()));
+            assertThat(request.getTargetIndexRequest().aliases(), equalTo(Set.of()));
 
             Settings.Builder builder = Settings.builder();
             builder.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, sourceIndexMetadata.getNumberOfReplicas())

+ 1 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStepTests.java

@@ -23,7 +23,6 @@ import org.elasticsearch.test.client.NoOpClient;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
-import java.util.Arrays;
 import java.util.List;
 import java.util.function.BiFunction;
 
@@ -92,7 +91,7 @@ public class SwapAliasesAndDeleteSourceIndexStepTests extends AbstractStepTestCa
         String targetIndexPrefix = "index_prefix";
         String targetIndexName = targetIndexPrefix + sourceIndexName;
 
-        List<AliasActions> expectedAliasActions = Arrays.asList(
+        List<AliasActions> expectedAliasActions = List.of(
             AliasActions.removeIndex().index(sourceIndexName),
             AliasActions.add().index(targetIndexName).alias(sourceIndexName),
             AliasActions.add()

+ 62 - 80
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java

@@ -13,9 +13,7 @@ import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInter
 import org.elasticsearch.test.ESTestCase;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -51,13 +49,7 @@ import static org.hamcrest.Matchers.notNullValue;
 
 public class TimeseriesLifecycleTypeTests extends ESTestCase {
 
-    private static final AllocateAction TEST_ALLOCATE_ACTION = new AllocateAction(
-        2,
-        20,
-        Collections.singletonMap("node", "node1"),
-        null,
-        null
-    );
+    private static final AllocateAction TEST_ALLOCATE_ACTION = new AllocateAction(2, 20, Map.of("node", "node1"), null, null);
     private static final DeleteAction TEST_DELETE_ACTION = DeleteAction.WITH_SNAPSHOT_DELETE;
 
     private static final WaitForSnapshotAction TEST_WAIT_FOR_SNAPSHOT_ACTION = new WaitForSnapshotAction("policy");
@@ -91,7 +83,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
         if (invalid) {
             phaseName += randomAlphaOfLength(5);
         }
-        Map<String, Phase> phases = Collections.singletonMap(phaseName, new Phase(phaseName, TimeValue.ZERO, Collections.emptyMap()));
+        Map<String, Phase> phases = Map.of(phaseName, new Phase(phaseName, TimeValue.ZERO, Map.of()));
         if (invalid) {
             Exception e = expectThrows(IllegalArgumentException.class, () -> TimeseriesLifecycleType.INSTANCE.validate(phases.values()));
             assertThat(e.getMessage(), equalTo("Timeseries lifecycle does not support phase [" + phaseName + "]"));
@@ -109,7 +101,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             invalidAction = getTestAction(randomFrom("allocate", "delete", "freeze"));
             actions.put(invalidAction.getWriteableName(), invalidAction);
         }
-        Map<String, Phase> hotPhase = Collections.singletonMap("hot", new Phase("hot", TimeValue.ZERO, actions));
+        Map<String, Phase> hotPhase = Map.of("hot", new Phase("hot", TimeValue.ZERO, actions));
 
         if (invalidAction != null) {
             Exception e = expectThrows(IllegalArgumentException.class, () -> TimeseriesLifecycleType.INSTANCE.validate(hotPhase.values()));
@@ -123,14 +115,14 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
                 final Map<String, LifecycleAction> hotActionMap = hotActions.stream()
                     .map(this::getTestAction)
                     .collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity()));
-                TimeseriesLifecycleType.INSTANCE.validate(Collections.singleton(new Phase("hot", TimeValue.ZERO, hotActionMap)));
+                TimeseriesLifecycleType.INSTANCE.validate(List.of(new Phase("hot", TimeValue.ZERO, hotActionMap)));
             };
 
-            validateHotActions.accept(Arrays.asList(RolloverAction.NAME));
-            validateHotActions.accept(Arrays.asList(RolloverAction.NAME, ForceMergeAction.NAME));
+            validateHotActions.accept(List.of(RolloverAction.NAME));
+            validateHotActions.accept(List.of(RolloverAction.NAME, ForceMergeAction.NAME));
             IllegalArgumentException e = expectThrows(
                 IllegalArgumentException.class,
-                () -> validateHotActions.accept(Arrays.asList(ForceMergeAction.NAME))
+                () -> validateHotActions.accept(List.of(ForceMergeAction.NAME))
             );
             assertThat(
                 e.getMessage(),
@@ -148,7 +140,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             invalidAction = getTestAction(randomFrom("rollover", "delete", "freeze"));
             actions.put(invalidAction.getWriteableName(), invalidAction);
         }
-        Map<String, Phase> warmPhase = Collections.singletonMap("warm", new Phase("warm", TimeValue.ZERO, actions));
+        Map<String, Phase> warmPhase = Map.of("warm", new Phase("warm", TimeValue.ZERO, actions));
 
         if (invalidAction != null) {
             Exception e = expectThrows(IllegalArgumentException.class, () -> TimeseriesLifecycleType.INSTANCE.validate(warmPhase.values()));
@@ -167,7 +159,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             invalidAction = getTestAction(randomFrom("rollover", "delete", "forcemerge", "shrink"));
             actions.put(invalidAction.getWriteableName(), invalidAction);
         }
-        Map<String, Phase> coldPhase = Collections.singletonMap("cold", new Phase("cold", TimeValue.ZERO, actions));
+        Map<String, Phase> coldPhase = Map.of("cold", new Phase("cold", TimeValue.ZERO, actions));
 
         if (invalidAction != null) {
             Exception e = expectThrows(IllegalArgumentException.class, () -> TimeseriesLifecycleType.INSTANCE.validate(coldPhase.values()));
@@ -188,7 +180,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             invalidAction = getTestAction(randomFrom("rollover", "delete", "forcemerge", "shrink"));
             actions.put(invalidAction.getWriteableName(), invalidAction);
         }
-        Map<String, Phase> frozenPhase = Collections.singletonMap("frozen", new Phase("frozen", TimeValue.ZERO, actions));
+        Map<String, Phase> frozenPhase = Map.of("frozen", new Phase("frozen", TimeValue.ZERO, actions));
 
         if (invalidAction != null) {
             Exception e = expectThrows(
@@ -210,7 +202,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             invalidAction = getTestAction(randomFrom("allocate", "rollover", "forcemerge", "shrink", "freeze", "set_priority"));
             actions.put(invalidAction.getWriteableName(), invalidAction);
         }
-        Map<String, Phase> deletePhase = Collections.singletonMap("delete", new Phase("delete", TimeValue.ZERO, actions));
+        Map<String, Phase> deletePhase = Map.of("delete", new Phase("delete", TimeValue.ZERO, actions));
 
         if (invalidAction != null) {
             Exception e = expectThrows(
@@ -459,7 +451,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
     public void testGetOrderedPhases() {
         Map<String, Phase> phaseMap = new HashMap<>();
         for (String phaseName : randomSubsetOf(randomIntBetween(0, ORDERED_VALID_PHASES.size()), ORDERED_VALID_PHASES)) {
-            phaseMap.put(phaseName, new Phase(phaseName, TimeValue.ZERO, Collections.emptyMap()));
+            phaseMap.put(phaseName, new Phase(phaseName, TimeValue.ZERO, Map.of()));
         }
 
         assertTrue(isSorted(TimeseriesLifecycleType.INSTANCE.getOrderedPhases(phaseMap), Phase::getName, ORDERED_VALID_PHASES));
@@ -509,7 +501,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
     public void testGetOrderedActionsInvalidPhase() {
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
-            () -> TimeseriesLifecycleType.INSTANCE.getOrderedActions(new Phase("invalid", TimeValue.ZERO, Collections.emptyMap()))
+            () -> TimeseriesLifecycleType.INSTANCE.getOrderedActions(new Phase("invalid", TimeValue.ZERO, Map.of()))
         );
         assertThat(exception.getMessage(), equalTo("lifecycle type [timeseries] does not support phase [invalid]"));
     }
@@ -583,25 +575,25 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
 
         {
             // not inject in hot phase
-            Phase phase = new Phase(HOT_PHASE, TimeValue.ZERO, Collections.emptyMap());
+            Phase phase = new Phase(HOT_PHASE, TimeValue.ZERO, Map.of());
             assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false));
         }
 
         {
             // not inject in frozen phase
-            Phase phase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Collections.emptyMap());
+            Phase phase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Map.of());
             assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false));
         }
 
         {
             // not inject in delete phase
-            Phase phase = new Phase(DELETE_PHASE, TimeValue.ZERO, Collections.emptyMap());
+            Phase phase = new Phase(DELETE_PHASE, TimeValue.ZERO, Map.of());
             assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false));
         }
 
         {
             // return false for invalid phase
-            Phase phase = new Phase(HOT_PHASE + randomAlphaOfLength(5), TimeValue.ZERO, Collections.emptyMap());
+            Phase phase = new Phase(HOT_PHASE + randomAlphaOfLength(5), TimeValue.ZERO, Map.of());
             assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false));
         }
     }
@@ -620,7 +612,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             Phase coldPhase = new Phase(HOT_PHASE, TimeValue.ZERO, coldActions);
             Phase frozenPhase = new Phase(HOT_PHASE, TimeValue.ZERO, frozenActions);
 
-            validateAllSearchableSnapshotActionsUseSameRepository(Arrays.asList(hotPhase, coldPhase, frozenPhase));
+            validateAllSearchableSnapshotActionsUseSameRepository(List.of(hotPhase, coldPhase, frozenPhase));
         }
 
         {
@@ -634,7 +626,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
 
             IllegalArgumentException e = expectThrows(
                 IllegalArgumentException.class,
-                () -> validateAllSearchableSnapshotActionsUseSameRepository(Arrays.asList(hotPhase, coldPhase, frozenPhase))
+                () -> validateAllSearchableSnapshotActionsUseSameRepository(List.of(hotPhase, coldPhase, frozenPhase))
             );
             assertThat(
                 e.getMessage(),
@@ -649,25 +641,25 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
 
     public void testValidatingIncreasingAges() {
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.ZERO, Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.ZERO, Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.ZERO, Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.ZERO, Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.ZERO, Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.ZERO, Map.of());
 
             assertFalse(
                 Strings.hasText(
-                    validateMonotonicallyIncreasingPhaseTimings(Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase))
+                    validateMonotonicallyIncreasingPhaseTimings(List.of(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase))
                 )
             );
         }
 
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Map.of());
 
             List<Phase> phases = new ArrayList<>();
             phases.add(hotPhase);
@@ -687,15 +679,13 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
         }
 
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.ZERO, Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.timeValueHours(12), Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.ZERO, Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.ZERO, Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.timeValueHours(12), Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.ZERO, Map.of());
 
-            String err = validateMonotonicallyIncreasingPhaseTimings(
-                Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase)
-            );
+            String err = validateMonotonicallyIncreasingPhaseTimings(List.of(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase));
 
             assertThat(
                 err,
@@ -708,15 +698,13 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
         }
 
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(3), Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, null, Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(3), Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, null, Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(2), Map.of());
 
-            String err = validateMonotonicallyIncreasingPhaseTimings(
-                Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase)
-            );
+            String err = validateMonotonicallyIncreasingPhaseTimings(List.of(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase));
 
             assertThat(
                 err,
@@ -729,15 +717,13 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
         }
 
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(3), Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, null, Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(3), Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, null, Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Map.of());
 
-            String err = validateMonotonicallyIncreasingPhaseTimings(
-                Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase)
-            );
+            String err = validateMonotonicallyIncreasingPhaseTimings(List.of(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase));
 
             assertThat(
                 err,
@@ -750,15 +736,13 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
         }
 
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(3), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, null, Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(3), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(2), Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, null, Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Map.of());
 
-            String err = validateMonotonicallyIncreasingPhaseTimings(
-                Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase)
-            );
+            String err = validateMonotonicallyIncreasingPhaseTimings(List.of(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase));
 
             assertThat(
                 err,
@@ -772,15 +756,13 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
         }
 
         {
-            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(3), Collections.emptyMap());
-            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
-            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
-            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
-            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
+            Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(3), Map.of());
+            Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(2), Map.of());
+            Phase coldPhase = new Phase(COLD_PHASE, TimeValue.timeValueDays(2), Map.of());
+            Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Map.of());
+            Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Map.of());
 
-            String err = validateMonotonicallyIncreasingPhaseTimings(
-                Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase)
-            );
+            String err = validateMonotonicallyIncreasingPhaseTimings(List.of(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase));
 
             assertThat(
                 err,
@@ -799,7 +781,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             Map<String, LifecycleAction> frozenActions = new HashMap<>();
             frozenActions.put(SearchableSnapshotAction.NAME, new SearchableSnapshotAction("repo1", randomBoolean()));
             Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.ZERO, frozenActions);
-            validateFrozenPhaseHasSearchableSnapshotAction(Collections.singleton(frozenPhase));
+            validateFrozenPhaseHasSearchableSnapshotAction(List.of(frozenPhase));
         }
 
         {
@@ -807,7 +789,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
             Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.ZERO, frozenActions);
             IllegalArgumentException e = expectThrows(
                 IllegalArgumentException.class,
-                () -> validateFrozenPhaseHasSearchableSnapshotAction(Collections.singleton(frozenPhase))
+                () -> validateFrozenPhaseHasSearchableSnapshotAction(List.of(frozenPhase))
             );
             assertThat(
                 e.getMessage(),

+ 5 - 5
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowFollowerIndexStepTests.java

@@ -14,7 +14,7 @@ import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.xpack.core.ccr.action.UnfollowAction;
 import org.mockito.Mockito;
 
-import java.util.Collections;
+import java.util.Map;
 
 import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY;
 import static org.hamcrest.Matchers.equalTo;
@@ -30,7 +30,7 @@ public class UnfollowFollowerIndexStepTests extends AbstractUnfollowIndexStepTes
     public void testUnFollow() throws Exception {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -51,7 +51,7 @@ public class UnfollowFollowerIndexStepTests extends AbstractUnfollowIndexStepTes
     public void testRequestNotAcknowledged() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -71,7 +71,7 @@ public class UnfollowFollowerIndexStepTests extends AbstractUnfollowIndexStepTes
     public void testUnFollowUnfollowFailed() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -93,7 +93,7 @@ public class UnfollowFollowerIndexStepTests extends AbstractUnfollowIndexStepTes
     public void testFailureToReleaseRetentionLeases() throws Exception {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();

+ 2 - 3
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStepTests.java

@@ -17,7 +17,6 @@ import org.elasticsearch.cluster.metadata.Metadata;
 import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
-import java.util.Collections;
 import java.util.List;
 import java.util.function.LongSupplier;
 
@@ -68,7 +67,7 @@ public class UpdateRolloverLifecycleDateStepTests extends AbstractStepTestCase<U
             .numberOfReplicas(randomIntBetween(0, 5))
             .build();
         IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10))
-            .putRolloverInfo(new RolloverInfo(alias, Collections.emptyList(), rolloverTime))
+            .putRolloverInfo(new RolloverInfo(alias, List.of(), rolloverTime))
             .settings(settings(IndexVersion.current()).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
             .numberOfShards(randomIntBetween(1, 5))
             .numberOfReplicas(randomIntBetween(0, 5))
@@ -88,7 +87,7 @@ public class UpdateRolloverLifecycleDateStepTests extends AbstractStepTestCase<U
         long rolloverTime = randomValueOtherThan(creationDate, () -> randomNonNegativeLong());
         String dataStreamName = "test-datastream";
         IndexMetadata originalIndexMeta = IndexMetadata.builder(DataStream.getDefaultBackingIndexName(dataStreamName, 1))
-            .putRolloverInfo(new RolloverInfo(dataStreamName, Collections.emptyList(), rolloverTime))
+            .putRolloverInfo(new RolloverInfo(dataStreamName, List.of(), rolloverTime))
             .settings(settings(IndexVersion.current()))
             .numberOfShards(randomIntBetween(1, 5))
             .numberOfReplicas(randomIntBetween(0, 5))

+ 1 - 3
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForDataTierStepTests.java

@@ -64,9 +64,7 @@ public class WaitForDataTierStepTests extends AbstractStepTestCase<WaitForDataTi
 
     public void testConditionMet() {
         String notIncludedTier = randomFrom(DataTier.ALL_DATA_TIERS);
-        List<String> otherTiers = DataTier.ALL_DATA_TIERS.stream()
-            .filter(tier -> notIncludedTier.equals(tier) == false)
-            .collect(Collectors.toList());
+        List<String> otherTiers = DataTier.ALL_DATA_TIERS.stream().filter(tier -> notIncludedTier.equals(tier) == false).toList();
         List<String> includedTiers = randomSubsetOf(between(1, otherTiers.size()), otherTiers);
         String tierPreference = String.join(",", includedTiers);
         WaitForDataTierStep step = new WaitForDataTierStep(randomStepKey(), randomStepKey(), tierPreference);

+ 6 - 6
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java

@@ -16,9 +16,9 @@ import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 import org.mockito.Mockito;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY;
 import static org.hamcrest.Matchers.equalTo;
@@ -57,11 +57,11 @@ public class WaitForFollowShardTasksStepTests extends AbstractStepTestCase<WaitF
     public void testConditionMet() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(2)
             .numberOfReplicas(0)
             .build();
-        List<FollowStatsAction.StatsResponse> statsResponses = Arrays.asList(
+        List<FollowStatsAction.StatsResponse> statsResponses = List.of(
             new FollowStatsAction.StatsResponse(createShardFollowTaskStatus(0, 9, 9)),
             new FollowStatsAction.StatsResponse(createShardFollowTaskStatus(1, 3, 3))
         );
@@ -96,11 +96,11 @@ public class WaitForFollowShardTasksStepTests extends AbstractStepTestCase<WaitF
     public void testConditionNotMetShardsNotInSync() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(2)
             .numberOfReplicas(0)
             .build();
-        List<FollowStatsAction.StatsResponse> statsResponses = Arrays.asList(
+        List<FollowStatsAction.StatsResponse> statsResponses = List.of(
             new FollowStatsAction.StatsResponse(createShardFollowTaskStatus(0, 9, 9)),
             new FollowStatsAction.StatsResponse(createShardFollowTaskStatus(1, 8, 3))
         );
@@ -214,7 +214,7 @@ public class WaitForFollowShardTasksStepTests extends AbstractStepTestCase<WaitF
             @SuppressWarnings("unchecked")
             ActionListener<FollowStatsAction.StatsResponses> listener = (ActionListener<FollowStatsAction.StatsResponses>) invocationOnMock
                 .getArguments()[2];
-            listener.onResponse(new FollowStatsAction.StatsResponses(Collections.emptyList(), Collections.emptyList(), statsResponses));
+            listener.onResponse(new FollowStatsAction.StatsResponses(List.of(), List.of(), statsResponses));
             return null;
         }).when(client).execute(Mockito.eq(FollowStatsAction.INSTANCE), Mockito.any(), Mockito.any());
     }

+ 3 - 3
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStepTests.java

@@ -15,7 +15,7 @@ import org.elasticsearch.index.Index;
 import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
-import java.util.Collections;
+import java.util.Map;
 
 import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY;
 import static org.hamcrest.Matchers.equalTo;
@@ -54,7 +54,7 @@ public class WaitForIndexingCompleteStepTests extends AbstractStepTestCase<WaitF
     public void testConditionMet() {
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();
@@ -93,7 +93,7 @@ public class WaitForIndexingCompleteStepTests extends AbstractStepTestCase<WaitF
         }
         IndexMetadata indexMetadata = IndexMetadata.builder("follower-index")
             .settings(indexSettings)
-            .putCustom(CCR_METADATA_KEY, Collections.emptyMap())
+            .putCustom(CCR_METADATA_KEY, Map.of())
             .numberOfShards(1)
             .numberOfReplicas(0)
             .build();

+ 2 - 7
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java

@@ -38,7 +38,6 @@ import org.elasticsearch.xcontent.ToXContentObject;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
@@ -396,11 +395,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
             .putAlias(AliasMetadata.builder(rolloverAlias))
             .settings(settings(IndexVersion.current()).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, rolloverAlias))
             .putRolloverInfo(
-                new RolloverInfo(
-                    rolloverAlias,
-                    Collections.singletonList(new MaxSizeCondition(ByteSizeValue.ofBytes(2L))),
-                    System.currentTimeMillis()
-                )
+                new RolloverInfo(rolloverAlias, List.of(new MaxSizeCondition(ByteSizeValue.ofBytes(2L))), System.currentTimeMillis())
             )
             .numberOfShards(randomIntBetween(1, 5))
             .numberOfReplicas(randomIntBetween(0, 5))
@@ -432,7 +427,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
             .putRolloverInfo(
                 new RolloverInfo(
                     randomAlphaOfLength(5),
-                    Collections.singletonList(new MaxSizeCondition(ByteSizeValue.ofBytes(2L))),
+                    List.of(new MaxSizeCondition(ByteSizeValue.ofBytes(2L))),
                     System.currentTimeMillis()
                 )
             )

+ 1 - 2
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/GetLifecycleResponseTests.java

@@ -24,7 +24,6 @@ import org.elasticsearch.xpack.core.ilm.action.GetLifecycleAction.Response;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -90,7 +89,7 @@ public class GetLifecycleResponseTests extends AbstractWireSerializingTestCase<R
 
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(
+            List.of(
                 new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new),
                 new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, in -> TestLifecycleType.INSTANCE)
             )

+ 2 - 3
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/PutLifecycleRequestTests.java

@@ -34,7 +34,6 @@ import org.elasticsearch.xpack.core.ilm.WaitForSnapshotAction;
 import org.junit.Before;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 public class PutLifecycleRequestTests extends AbstractXContentSerializingTestCase<PutLifecycleRequest> {
@@ -78,7 +77,7 @@ public class PutLifecycleRequestTests extends AbstractXContentSerializingTestCas
     @Override
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(
+            List.of(
                 new NamedWriteableRegistry.Entry(
                     LifecycleType.class,
                     TimeseriesLifecycleType.TYPE,
@@ -105,7 +104,7 @@ public class PutLifecycleRequestTests extends AbstractXContentSerializingTestCas
     protected NamedXContentRegistry xContentRegistry() {
         List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
         entries.addAll(
-            Arrays.asList(
+            List.of(
                 new NamedXContentRegistry.Entry(
                     LifecycleType.class,
                     new ParseField(TimeseriesLifecycleType.TYPE),

+ 3 - 5
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/RemoveIndexLifecyclePolicyResponseTests.java

@@ -14,15 +14,13 @@ import org.elasticsearch.xpack.core.ilm.action.RemoveIndexLifecyclePolicyAction.
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 public class RemoveIndexLifecyclePolicyResponseTests extends AbstractXContentSerializingTestCase<Response> {
 
     @Override
     protected Response createTestInstance() {
-        List<String> failedIndexes = Arrays.asList(generateRandomStringArray(20, 20, false));
+        List<String> failedIndexes = List.of(generateRandomStringArray(20, 20, false));
         return new Response(failedIndexes);
     }
 
@@ -35,7 +33,7 @@ public class RemoveIndexLifecyclePolicyResponseTests extends AbstractXContentSer
     protected Response mutateInstance(Response instance) {
         List<String> failedIndices = randomValueOtherThan(
             instance.getFailedIndexes(),
-            () -> Arrays.asList(generateRandomStringArray(20, 20, false))
+            () -> List.of(generateRandomStringArray(20, 20, false))
         );
         return new Response(failedIndices);
     }
@@ -53,7 +51,7 @@ public class RemoveIndexLifecyclePolicyResponseTests extends AbstractXContentSer
     public void testHasFailures() {
         Response response = new Response(new ArrayList<>());
         assertFalse(response.hasFailures());
-        assertEquals(Collections.emptyList(), response.getFailedIndexes());
+        assertEquals(List.of(), response.getFailedIndexes());
 
         int size = randomIntBetween(1, 10);
         List<String> failedIndexes = new ArrayList<>(size);

+ 2 - 3
x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ilm/CCRIndexLifecycleIT.java

@@ -38,7 +38,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
 import static org.hamcrest.Matchers.equalTo;
@@ -762,8 +761,8 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
     }
 
     private void createNewSingletonPolicy(String policyName, String phaseName, LifecycleAction action, TimeValue after) throws IOException {
-        Phase phase = new Phase(phaseName, after, singletonMap(action.getWriteableName(), action));
-        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policyName, singletonMap(phase.getName(), phase));
+        Phase phase = new Phase(phaseName, after, Map.of(action.getWriteableName(), action));
+        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policyName, Map.of(phase.getName(), phase));
         XContentBuilder builder = jsonBuilder();
         lifecyclePolicy.toXContent(builder, null);
         final StringEntity entity = new StringEntity("{ \"policy\":" + Strings.toString(builder) + "}", ContentType.APPLICATION_JSON);

+ 6 - 7
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java

@@ -46,7 +46,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createPolicy;
@@ -101,11 +100,11 @@ public class MigrateToDataTiersIT extends ESRestTestCase {
         Map<String, LifecycleAction> warmActions = new HashMap<>();
         warmActions.put(SetPriorityAction.NAME, new SetPriorityAction(50));
         warmActions.put(ForceMergeAction.NAME, new ForceMergeAction(1, null));
-        warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, singletonMap("data", "warm"), null, null));
+        warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, Map.of("data", "warm"), null, null));
         warmActions.put(ShrinkAction.NAME, new ShrinkAction(1, null, false));
         Map<String, LifecycleAction> coldActions = new HashMap<>();
         coldActions.put(SetPriorityAction.NAME, new SetPriorityAction(0));
-        coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null, singletonMap("data", "cold")));
+        coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null, Map.of("data", "cold")));
 
         createPolicy(
             client(),
@@ -114,7 +113,7 @@ public class MigrateToDataTiersIT extends ESRestTestCase {
             new Phase("warm", TimeValue.ZERO, warmActions),
             new Phase("cold", TimeValue.timeValueDays(100), coldActions),
             null,
-            new Phase("delete", TimeValue.ZERO, singletonMap(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE))
+            new Phase("delete", TimeValue.ZERO, Map.of(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE))
         );
 
         createIndexWithSettings(
@@ -377,11 +376,11 @@ public class MigrateToDataTiersIT extends ESRestTestCase {
         Map<String, LifecycleAction> warmActions = new HashMap<>();
         warmActions.put(SetPriorityAction.NAME, new SetPriorityAction(50));
         warmActions.put(ForceMergeAction.NAME, new ForceMergeAction(1, null));
-        warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, singletonMap("data", "warm"), null, null));
+        warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, Map.of("data", "warm"), null, null));
         warmActions.put(ShrinkAction.NAME, new ShrinkAction(1, null, false));
         Map<String, LifecycleAction> coldActions = new HashMap<>();
         coldActions.put(SetPriorityAction.NAME, new SetPriorityAction(0));
-        coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null, singletonMap("data", "cold")));
+        coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null, Map.of("data", "cold")));
 
         createPolicy(
             client(),
@@ -390,7 +389,7 @@ public class MigrateToDataTiersIT extends ESRestTestCase {
             new Phase("warm", TimeValue.ZERO, warmActions),
             new Phase("cold", TimeValue.timeValueDays(100), coldActions),
             null,
-            new Phase("delete", TimeValue.ZERO, singletonMap(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE))
+            new Phase("delete", TimeValue.ZERO, Map.of(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE))
         );
 
         createIndexWithSettings(

+ 6 - 8
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java

@@ -41,7 +41,6 @@ import org.elasticsearch.xpack.core.ilm.Step;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -50,7 +49,6 @@ import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
 import static org.elasticsearch.test.ESTestCase.randomAlphaOfLengthBetween;
 import static org.elasticsearch.test.ESTestCase.randomBoolean;
@@ -154,8 +152,8 @@ public final class TimeSeriesRestDriver {
         LifecycleAction action,
         TimeValue after
     ) throws IOException {
-        Phase phase = new Phase(phaseName, after, singletonMap(action.getWriteableName(), action));
-        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policyName, singletonMap(phase.getName(), phase));
+        Phase phase = new Phase(phaseName, after, Map.of(action.getWriteableName(), action));
+        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policyName, Map.of(phase.getName(), phase));
         XContentBuilder builder = jsonBuilder();
         lifecyclePolicy.toXContent(builder, null);
         final StringEntity entity = new StringEntity("{ \"policy\":" + Strings.toString(builder) + "}", ContentType.APPLICATION_JSON);
@@ -202,7 +200,7 @@ public final class TimeSeriesRestDriver {
             new AllocateAction(
                 1,
                 null,
-                singletonMap("_name", "javaRestTest-0,javaRestTest-1," + "javaRestTest-2," + "javaRestTest-3"),
+                Map.of("_name", "javaRestTest-0,javaRestTest-1," + "javaRestTest-2," + "javaRestTest-3"),
                 null,
                 null
             )
@@ -215,7 +213,7 @@ public final class TimeSeriesRestDriver {
             new AllocateAction(
                 0,
                 null,
-                singletonMap("_name", "javaRestTest-0,javaRestTest-1," + "javaRestTest-2," + "javaRestTest-3"),
+                Map.of("_name", "javaRestTest-0,javaRestTest-1," + "javaRestTest-2," + "javaRestTest-3"),
                 null,
                 null
             )
@@ -224,7 +222,7 @@ public final class TimeSeriesRestDriver {
         phases.put("hot", new Phase("hot", hotTime, hotActions));
         phases.put("warm", new Phase("warm", TimeValue.ZERO, warmActions));
         phases.put("cold", new Phase("cold", TimeValue.ZERO, coldActions));
-        phases.put("delete", new Phase("delete", TimeValue.ZERO, singletonMap(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE)));
+        phases.put("delete", new Phase("delete", TimeValue.ZERO, Map.of(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE)));
         LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policyName, phases);
         // PUT policy
         XContentBuilder builder = jsonBuilder();
@@ -300,7 +298,7 @@ public final class TimeSeriesRestDriver {
             Map<String, Object> responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
             Map<String, Object> indexSettings = (Map<String, Object>) responseMap.get(index);
             if (indexSettings == null) {
-                return Collections.emptyMap();
+                return Map.of();
             }
             return (Map<String, Object>) indexSettings.get("settings");
         }

+ 5 - 12
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyForIndexIT.java

@@ -32,7 +32,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
@@ -67,7 +66,7 @@ public class ChangePolicyForIndexIT extends ESRestTestCase {
             new Phase(
                 "hot",
                 TimeValue.ZERO,
-                singletonMap(RolloverAction.NAME, new RolloverAction(null, null, null, 1L, null, null, null, null, null, null))
+                Map.of(RolloverAction.NAME, new RolloverAction(null, null, null, 1L, null, null, null, null, null, null))
             )
         );
         phases1.put(
@@ -75,7 +74,7 @@ public class ChangePolicyForIndexIT extends ESRestTestCase {
             new Phase(
                 "warm",
                 TimeValue.ZERO,
-                singletonMap(AllocateAction.NAME, new AllocateAction(1, null, singletonMap("_name", "foobarbaz"), null, null))
+                Map.of(AllocateAction.NAME, new AllocateAction(1, null, Map.of("_name", "foobarbaz"), null, null))
             )
         );
         LifecyclePolicy lifecyclePolicy1 = new LifecyclePolicy("policy_1", phases1);
@@ -85,7 +84,7 @@ public class ChangePolicyForIndexIT extends ESRestTestCase {
             new Phase(
                 "hot",
                 TimeValue.ZERO,
-                singletonMap(RolloverAction.NAME, new RolloverAction(null, null, null, 1000L, null, null, null, null, null, null))
+                Map.of(RolloverAction.NAME, new RolloverAction(null, null, null, 1000L, null, null, null, null, null, null))
             )
         );
         phases2.put(
@@ -93,15 +92,9 @@ public class ChangePolicyForIndexIT extends ESRestTestCase {
             new Phase(
                 "warm",
                 TimeValue.ZERO,
-                singletonMap(
+                Map.of(
                     AllocateAction.NAME,
-                    new AllocateAction(
-                        1,
-                        null,
-                        singletonMap("_name", "javaRestTest-0,javaRestTest-1,javaRestTest-2,javaRestTest-3"),
-                        null,
-                        null
-                    )
+                    new AllocateAction(1, null, Map.of("_name", "javaRestTest-0,javaRestTest-1,javaRestTest-2,javaRestTest-3"), null, null)
                 )
             )
         );

+ 3 - 4
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

@@ -58,7 +58,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createFullPolicy;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
@@ -219,7 +218,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
             Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
         );
         String allocateNodeName = "javaRestTest-0,javaRestTest-1,javaRestTest-2,javaRestTest-3";
-        AllocateAction allocateAction = new AllocateAction(null, null, singletonMap("_name", allocateNodeName), null, null);
+        AllocateAction allocateAction = new AllocateAction(null, null, Map.of("_name", allocateNodeName), null, null);
         String endPhase = randomFrom("warm", "cold");
         createNewSingletonPolicy(client(), policy, endPhase, allocateAction);
         updatePolicy(client(), index, policy);
@@ -978,7 +977,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
             hotActions.put(SetPriorityAction.NAME, new SetPriorityAction(100));
             Map<String, Phase> phases = new HashMap<>();
             phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions));
-            phases.put("delete", new Phase("delete", TimeValue.ZERO, singletonMap(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE)));
+            phases.put("delete", new Phase("delete", TimeValue.ZERO, Map.of(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE)));
             LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
             // PUT policy
             XContentBuilder builder = jsonBuilder();
@@ -1004,7 +1003,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
         phases.put("cold", new Phase("cold", TimeValue.ZERO, coldActions));
         phases.put(
             "delete",
-            new Phase("delete", TimeValue.timeValueMillis(10000), singletonMap(DeleteAction.NAME, DeleteAction.NO_SNAPSHOT_DELETE))
+            new Phase("delete", TimeValue.timeValueMillis(10000), Map.of(DeleteAction.NAME, DeleteAction.NO_SNAPSHOT_DELETE))
         );
         LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
         // PUT policy

+ 19 - 20
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java

@@ -47,7 +47,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING;
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createComposableTemplate;
@@ -185,7 +184,7 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
         Map<String, LifecycleAction> coldActions = Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo));
         Map<String, Phase> phases = new HashMap<>();
         phases.put("cold", new Phase("cold", TimeValue.ZERO, coldActions));
-        phases.put("delete", new Phase("delete", TimeValue.timeValueMillis(10000), singletonMap(DeleteAction.NAME, WITH_SNAPSHOT_DELETE)));
+        phases.put("delete", new Phase("delete", TimeValue.timeValueMillis(10000), Map.of(DeleteAction.NAME, WITH_SNAPSHOT_DELETE)));
         LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
         // PUT policy
         XContentBuilder builder = jsonBuilder();
@@ -455,7 +454,7 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null
         );
@@ -516,12 +515,12 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             new Phase(
                 "frozen",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null
         );
@@ -586,7 +585,7 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null,
             null
@@ -600,12 +599,12 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             new Phase(
                 "frozen",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null
         );
@@ -664,14 +663,14 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             new Phase(
                 "frozen",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
-            new Phase("delete", TimeValue.ZERO, singletonMap(DeleteAction.NAME, WITH_SNAPSHOT_DELETE))
+            new Phase("delete", TimeValue.ZERO, Map.of(DeleteAction.NAME, WITH_SNAPSHOT_DELETE))
         );
         assertBusy(() -> {
             logger.info("--> waiting for [{}] to be deleted...", partiallyMountedIndexName);
@@ -695,7 +694,7 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null,
             null
@@ -710,12 +709,12 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             new Phase(
                 "frozen",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null
         );
@@ -775,10 +774,10 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             null,
-            new Phase("delete", TimeValue.ZERO, singletonMap(DeleteAction.NAME, WITH_SNAPSHOT_DELETE))
+            new Phase("delete", TimeValue.ZERO, Map.of(DeleteAction.NAME, WITH_SNAPSHOT_DELETE))
         );
         assertBusy(() -> {
             logger.info("--> waiting for [{}] to be deleted...", restoredPartiallyMountedIndexName);
@@ -803,12 +802,12 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
                 new Phase(
                     "cold",
                     TimeValue.ZERO,
-                    singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                    Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
                 ),
                 new Phase(
                     "frozen",
                     TimeValue.ZERO,
-                    singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(secondRepo, randomBoolean()))
+                    Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(secondRepo, randomBoolean()))
                 ),
                 null
             )
@@ -934,12 +933,12 @@ public class SearchableSnapshotActionIT extends ESRestTestCase {
             new Phase(
                 "cold",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()))
             ),
             new Phase(
                 "frozen",
                 TimeValue.ZERO,
-                singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean(), totalShardsPerNode))
+                Map.of(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean(), totalShardsPerNode))
             ),
             null
         );

+ 1 - 2
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ShrinkActionIT.java

@@ -39,7 +39,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
@@ -286,7 +285,7 @@ public class ShrinkActionIT extends ESRestTestCase {
             TimeValue.ZERO,
             Map.of(migrateAction.getWriteableName(), migrateAction, shrinkAction.getWriteableName(), shrinkAction)
         );
-        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, singletonMap(phase.getName(), phase));
+        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, Map.of(phase.getName(), phase));
         XContentBuilder builder = jsonBuilder();
         lifecyclePolicy.toXContent(builder, null);
         final StringEntity entity = new StringEntity("{ \"policy\":" + Strings.toString(builder) + "}", ContentType.APPLICATION_JSON);

+ 2 - 3
x-pack/plugin/ilm/qa/with-security/src/javaRestTest/java/org/elasticsearch/xpack/security/PermissionsIT.java

@@ -45,7 +45,6 @@ import java.io.InputStream;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static java.util.Collections.singletonMap;
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -225,8 +224,8 @@ public class PermissionsIT extends ESRestTestCase {
     }
 
     private void createNewSingletonPolicy(RestClient client, String policy, String phaseName, LifecycleAction action) throws IOException {
-        Phase phase = new Phase(phaseName, TimeValue.ZERO, singletonMap(action.getWriteableName(), action));
-        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, singletonMap(phase.getName(), phase));
+        Phase phase = new Phase(phaseName, TimeValue.ZERO, Map.of(action.getWriteableName(), action));
+        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, Map.of(phase.getName(), phase));
         XContentBuilder builder = jsonBuilder();
         lifecyclePolicy.toXContent(builder, null);
         final StringEntity entity = new StringEntity("{ \"policy\":" + Strings.toString(builder) + "}", ContentType.APPLICATION_JSON);

+ 1 - 2
x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java

@@ -35,7 +35,6 @@ import org.elasticsearch.xpack.core.ilm.action.ILMActions;
 import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest;
 import org.junit.Before;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
@@ -65,7 +64,7 @@ public class ClusterStateWaitThresholdBreachTests extends ESIntegTestCase {
 
     @Override
     protected Collection<Class<? extends Plugin>> nodePlugins() {
-        return Arrays.asList(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class, Ccr.class);
+        return List.of(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class, Ccr.class);
     }
 
     @Override

+ 8 - 9
x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java

@@ -30,9 +30,8 @@ import org.elasticsearch.xpack.core.ilm.action.ILMActions;
 import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest;
 import org.junit.Before;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -57,7 +56,7 @@ public class DataTiersMigrationsTests extends ESIntegTestCase {
 
     @Override
     protected Collection<Class<? extends Plugin>> nodePlugins() {
-        return Arrays.asList(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class);
+        return List.of(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class);
     }
 
     @Override
@@ -100,9 +99,9 @@ public class DataTiersMigrationsTests extends ESIntegTestCase {
         logger.info("starting a cold data node");
         internalCluster().startNode(coldNode(Settings.EMPTY));
 
-        Phase hotPhase = new Phase("hot", TimeValue.ZERO, Collections.emptyMap());
-        Phase warmPhase = new Phase("warm", TimeValue.ZERO, Collections.emptyMap());
-        Phase coldPhase = new Phase("cold", TimeValue.ZERO, Collections.emptyMap());
+        Phase hotPhase = new Phase("hot", TimeValue.ZERO, Map.of());
+        Phase warmPhase = new Phase("warm", TimeValue.ZERO, Map.of());
+        Phase coldPhase = new Phase("cold", TimeValue.ZERO, Map.of());
         LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, Map.of("hot", hotPhase, "warm", warmPhase, "cold", coldPhase));
         PutLifecycleRequest putLifecycleRequest = new PutLifecycleRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, lifecyclePolicy);
         assertAcked(client().execute(ILMActions.PUT, putLifecycleRequest).get());
@@ -161,9 +160,9 @@ public class DataTiersMigrationsTests extends ESIntegTestCase {
         logger.info("starting a cold data node");
         internalCluster().startNode(coldNode(Settings.EMPTY));
 
-        Phase hotPhase = new Phase("hot", TimeValue.ZERO, Collections.emptyMap());
-        Phase warmPhase = new Phase("warm", TimeValue.ZERO, Collections.emptyMap());
-        Phase coldPhase = new Phase("cold", TimeValue.ZERO, Collections.emptyMap());
+        Phase hotPhase = new Phase("hot", TimeValue.ZERO, Map.of());
+        Phase warmPhase = new Phase("warm", TimeValue.ZERO, Map.of());
+        Phase coldPhase = new Phase("cold", TimeValue.ZERO, Map.of());
         LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, Map.of("hot", hotPhase, "warm", warmPhase, "cold", coldPhase));
         PutLifecycleRequest putLifecycleRequest = new PutLifecycleRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, lifecyclePolicy);
         assertAcked(client().execute(ILMActions.PUT, putLifecycleRequest).get());

+ 7 - 8
x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java

@@ -33,10 +33,9 @@ import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction;
 import org.elasticsearch.xpack.core.ilm.action.ILMActions;
 import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -49,7 +48,7 @@ public class ILMMultiNodeIT extends ESIntegTestCase {
 
     @Override
     protected Collection<Class<? extends Plugin>> nodePlugins() {
-        return Arrays.asList(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class);
+        return List.of(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class);
     }
 
     @Override
@@ -69,9 +68,9 @@ public class ILMMultiNodeIT extends ESIntegTestCase {
         ensureGreen();
 
         RolloverAction rolloverAction = new RolloverAction(null, null, null, 1L, null, null, null, null, null, null);
-        Phase hotPhase = new Phase("hot", TimeValue.ZERO, Collections.singletonMap(rolloverAction.getWriteableName(), rolloverAction));
+        Phase hotPhase = new Phase("hot", TimeValue.ZERO, Map.of(rolloverAction.getWriteableName(), rolloverAction));
         ShrinkAction shrinkAction = new ShrinkAction(1, null, false);
-        Phase warmPhase = new Phase("warm", TimeValue.ZERO, Collections.singletonMap(shrinkAction.getWriteableName(), shrinkAction));
+        Phase warmPhase = new Phase("warm", TimeValue.ZERO, Map.of(shrinkAction.getWriteableName(), shrinkAction));
         Map<String, Phase> phases = new HashMap<>();
         phases.put(hotPhase.getName(), hotPhase);
         phases.put(warmPhase.getName(), warmPhase);
@@ -89,7 +88,7 @@ public class ILMMultiNodeIT extends ESIntegTestCase {
         );
 
         ComposableIndexTemplate template = ComposableIndexTemplate.builder()
-            .indexPatterns(Collections.singletonList(index))
+            .indexPatterns(List.of(index))
             .template(t)
             .dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate())
             .build();
@@ -121,12 +120,12 @@ public class ILMMultiNodeIT extends ESIntegTestCase {
     }
 
     public void startHotOnlyNode() {
-        Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_hot", "ingest")).build();
+        Settings nodeSettings = Settings.builder().putList("node.roles", List.of("master", "data_hot", "ingest")).build();
         internalCluster().startNode(nodeSettings);
     }
 
     public void startWarmOnlyNode() {
-        Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_warm", "ingest")).build();
+        Settings nodeSettings = Settings.builder().putList("node.roles", List.of("master", "data_warm", "ingest")).build();
         internalCluster().startNode(nodeSettings);
     }
 }

+ 6 - 7
x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeWithCCRDisabledIT.java

@@ -34,10 +34,9 @@ import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction;
 import org.elasticsearch.xpack.core.ilm.action.ILMActions;
 import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -50,7 +49,7 @@ public class ILMMultiNodeWithCCRDisabledIT extends ESIntegTestCase {
 
     @Override
     protected Collection<Class<? extends Plugin>> nodePlugins() {
-        return Arrays.asList(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class);
+        return List.of(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class);
     }
 
     @Override
@@ -75,7 +74,7 @@ public class ILMMultiNodeWithCCRDisabledIT extends ESIntegTestCase {
         actions.put(shrinkAction.getWriteableName(), shrinkAction);
         Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
 
-        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy("shrink-policy", Collections.singletonMap(hotPhase.getName(), hotPhase));
+        LifecyclePolicy lifecyclePolicy = new LifecyclePolicy("shrink-policy", Map.of(hotPhase.getName(), hotPhase));
         client().execute(ILMActions.PUT, new PutLifecycleRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, lifecyclePolicy)).get();
 
         Template t = new Template(
@@ -89,7 +88,7 @@ public class ILMMultiNodeWithCCRDisabledIT extends ESIntegTestCase {
         );
 
         ComposableIndexTemplate template = ComposableIndexTemplate.builder()
-            .indexPatterns(Collections.singletonList(index))
+            .indexPatterns(List.of(index))
             .template(t)
             .dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate())
             .build();
@@ -121,12 +120,12 @@ public class ILMMultiNodeWithCCRDisabledIT extends ESIntegTestCase {
     }
 
     public void startHotOnlyNode() {
-        Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_hot", "ingest")).build();
+        Settings nodeSettings = Settings.builder().putList("node.roles", List.of("master", "data_hot", "ingest")).build();
         internalCluster().startNode(nodeSettings);
     }
 
     public void startWarmOnlyNode() {
-        Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_warm", "ingest")).build();
+        Settings nodeSettings = Settings.builder().putList("node.roles", List.of("master", "data_warm", "ingest")).build();
         internalCluster().startNode(nodeSettings);
     }
 }

+ 7 - 9
x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java

@@ -56,9 +56,7 @@ import org.junit.Before;
 import java.io.IOException;
 import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -112,7 +110,7 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
 
     @Override
     protected Collection<Class<? extends Plugin>> nodePlugins() {
-        return Arrays.asList(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class, TestILMPlugin.class);
+        return List.of(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class, TestILMPlugin.class);
     }
 
     @Before
@@ -128,9 +126,9 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
         Step.StepKey compKey = new Step.StepKey("mock", "complete", "complete");
         steps.add(new ObservableClusterStateWaitStep(key, compKey));
         steps.add(new PhaseCompleteStep(compKey, null));
-        Map<String, LifecycleAction> actions = Collections.singletonMap(ObservableAction.NAME, OBSERVABLE_ACTION);
+        Map<String, LifecycleAction> actions = Map.of(ObservableAction.NAME, OBSERVABLE_ACTION);
         mockPhase = new Phase("mock", TimeValue.timeValueSeconds(0), actions);
-        Map<String, Phase> phases = Collections.singletonMap("mock", mockPhase);
+        Map<String, Phase> phases = Map.of("mock", mockPhase);
         lifecyclePolicy = newLockableLifecyclePolicy("test", phases);
     }
 
@@ -311,7 +309,7 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
         updateIndexSettings(Settings.builder().put("index.lifecycle.test.complete", true), "test");
 
         {
-            Phase phase = new Phase("mock", TimeValue.ZERO, Collections.singletonMap("TEST_ACTION", OBSERVABLE_ACTION));
+            Phase phase = new Phase("mock", TimeValue.ZERO, Map.of("TEST_ACTION", OBSERVABLE_ACTION));
             PhaseExecutionInfo expectedExecutionInfo = new PhaseExecutionInfo(lifecyclePolicy.getName(), phase, 1L, actualModifiedDate);
             assertBusy(() -> {
                 IndexLifecycleExplainResponse indexResponse = executeExplainRequestAndGetTestIndexResponse("test");
@@ -526,12 +524,12 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
                 Setting.Property.Dynamic,
                 Setting.Property.IndexScope
             );
-            return Collections.singletonList(COMPLETE_SETTING);
+            return List.of(COMPLETE_SETTING);
         }
 
         @Override
         public List<NamedXContentRegistry.Entry> getNamedXContent() {
-            return Arrays.asList(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ObservableAction.NAME), (p) -> {
+            return List.of(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ObservableAction.NAME), (p) -> {
                 MockAction.parse(p);
                 return OBSERVABLE_ACTION;
             }));
@@ -539,7 +537,7 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
 
         @Override
         public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
-            return Arrays.asList(
+            return List.of(
                 new NamedWriteableRegistry.Entry(LifecycleType.class, LockableLifecycleType.TYPE, (in) -> LockableLifecycleType.INSTANCE),
                 new NamedWriteableRegistry.Entry(LifecycleAction.class, ObservableAction.NAME, ObservableAction::readObservableAction),
                 new NamedWriteableRegistry.Entry(

+ 1 - 2
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java

@@ -251,7 +251,7 @@ public final class MetadataMigrateToDataTiersRoutingService {
     ) {
         IndexLifecycleMetadata currentLifecycleMetadata = currentState.metadata().custom(IndexLifecycleMetadata.TYPE);
         if (currentLifecycleMetadata == null) {
-            return Collections.emptyList();
+            return List.of();
         }
 
         List<String> migratedPolicies = new ArrayList<>();
@@ -827,7 +827,6 @@ public final class MetadataMigrateToDataTiersRoutingService {
             this.migratedPolicies = Collections.unmodifiableList(migratedPolicies);
             this.migratedTemplates = migratedTemplates;
         }
-
     }
 
     /**

+ 4 - 5
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java

@@ -41,7 +41,6 @@ import org.elasticsearch.xpack.core.ilm.WaitForNoFollowersStep;
 import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -219,8 +218,8 @@ public class IlmHealthIndicatorService implements HealthIndicatorService {
                 GREEN,
                 "No Index Lifecycle Management policies configured",
                 createDetails(verbose, ilmMetadata, currentMode),
-                Collections.emptyList(),
-                Collections.emptyList()
+                List.of(),
+                List.of()
             );
         } else if (currentMode != OperationMode.RUNNING) {
             return createIndicator(
@@ -238,8 +237,8 @@ public class IlmHealthIndicatorService implements HealthIndicatorService {
                     GREEN,
                     "Index Lifecycle Management is running",
                     createDetails(verbose, ilmMetadata, currentMode),
-                    Collections.emptyList(),
-                    Collections.emptyList()
+                    List.of(),
+                    List.of()
                 );
             } else {
                 return createIndicator(

+ 1 - 2
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java

@@ -54,7 +54,6 @@ import org.elasticsearch.xpack.ilm.history.ILMHistoryStore;
 import java.io.Closeable;
 import java.time.Clock;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.LongSupplier;
@@ -500,7 +499,7 @@ public class IndexLifecycleService
             SingleNodeShutdownMetadata.Type.REPLACE
         );
         if (shutdownNodes.isEmpty()) {
-            return Collections.emptySet();
+            return Set.of();
         }
 
         Set<String> indicesPreventingShutdown = state.metadata()

+ 1 - 2
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportGetLifecycleAction.java

@@ -32,7 +32,6 @@ import org.elasticsearch.xpack.core.ilm.action.GetLifecycleAction.Response;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -71,7 +70,7 @@ public class TransportGetLifecycleAction extends TransportMasterNodeAction<Reque
         IndexLifecycleMetadata metadata = clusterService.state().metadata().custom(IndexLifecycleMetadata.TYPE);
         if (metadata == null) {
             if (request.getPolicyNames().length == 0) {
-                listener.onResponse(new Response(Collections.emptyList()));
+                listener.onResponse(new Response(List.of()));
             } else {
                 listener.onFailure(
                     new ResourceNotFoundException("Lifecycle policy not found: {}", Arrays.toString(request.getPolicyNames()))

+ 2 - 2
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItem.java

@@ -18,7 +18,7 @@ import org.elasticsearch.xcontent.XContentBuilder;
 import org.elasticsearch.xcontent.json.JsonXContent;
 
 import java.io.IOException;
-import java.util.Collections;
+import java.util.Map;
 import java.util.Objects;
 
 import static org.elasticsearch.ElasticsearchException.REST_EXCEPTION_SKIP_STACK_TRACE;
@@ -110,7 +110,7 @@ public class ILMHistoryItem implements ToXContentObject {
     }
 
     private static String exceptionToString(Exception exception) {
-        Params stacktraceParams = new MapParams(Collections.singletonMap(REST_EXCEPTION_SKIP_STACK_TRACE, "false"));
+        Params stacktraceParams = new MapParams(Map.of(REST_EXCEPTION_SKIP_STACK_TRACE, "false"));
         String exceptionString;
         try (XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder()) {
             causeXContentBuilder.startObject();

+ 12 - 34
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java

@@ -48,7 +48,6 @@ import org.junit.Before;
 
 import java.io.ByteArrayInputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -118,10 +117,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                 Metadata.builder()
                     .putCustom(
                         IndexLifecycleMetadata.TYPE,
-                        new IndexLifecycleMetadata(
-                            Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                            OperationMode.STOPPED
-                        )
+                        new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED)
                     )
                     .put(IndexMetadata.builder(indexName).settings(getBaseIndexSettings()))
                     .build()
@@ -176,7 +172,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
         );
         LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(
             policy,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -186,10 +182,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                 Metadata.builder()
                     .putCustom(
                         IndexLifecycleMetadata.TYPE,
-                        new IndexLifecycleMetadata(
-                            Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                            OperationMode.STOPPED
-                        )
+                        new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED)
                     )
                     .put(IndexMetadata.builder(indexName).settings(getBaseIndexSettings()))
                     .build()
@@ -245,10 +238,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                     Metadata.builder()
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
-                            new IndexLifecycleMetadata(
-                                Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                                OperationMode.STOPPED
-                            )
+                            new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED)
                         )
                         .put(indexMetadata)
                         .build()
@@ -302,10 +292,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
                             new IndexLifecycleMetadata(
-                                Collections.singletonMap(
-                                    policyMetadataWithTotalShardsPerNode.getName(),
-                                    policyMetadataWithTotalShardsPerNode
-                                ),
+                                Map.of(policyMetadataWithTotalShardsPerNode.getName(), policyMetadataWithTotalShardsPerNode),
                                 OperationMode.STOPPED
                             )
                         )
@@ -352,10 +339,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                     Metadata.builder()
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
-                            new IndexLifecycleMetadata(
-                                Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                                OperationMode.STOPPED
-                            )
+                            new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED)
                         )
                         .put(indexMetadata)
                         .build()
@@ -406,10 +390,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                     Metadata.builder()
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
-                            new IndexLifecycleMetadata(
-                                Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                                OperationMode.STOPPED
-                            )
+                            new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED)
                         )
                         .put(indexMetadata)
                         .build()
@@ -456,10 +437,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                     Metadata.builder()
                         .putCustom(
                             IndexLifecycleMetadata.TYPE,
-                            new IndexLifecycleMetadata(
-                                Collections.singletonMap(policyMetadata.getName(), policyMetadata),
-                                OperationMode.STOPPED
-                            )
+                            new IndexLifecycleMetadata(Map.of(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED)
                         )
                         .put(indexMetadata)
                         .build()
@@ -1008,7 +986,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
         );
         LifecyclePolicyMetadata policyWithDataAttribute = new LifecyclePolicyMetadata(
             policyToMigrate,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -1026,7 +1004,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
         );
         LifecyclePolicyMetadata policyWithOtherAttribute = new LifecyclePolicyMetadata(
             shouldntBeMigratedPolicy,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -1215,7 +1193,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
 
     public void testMigrationDoesNotRemoveComposableTemplates() {
         ComposableIndexTemplate composableIndexTemplate = ComposableIndexTemplate.builder()
-            .indexPatterns(Collections.singletonList("*"))
+            .indexPatterns(List.of("*"))
             .template(new Template(Settings.builder().put(DATA_ROUTING_REQUIRE_SETTING, "hot").build(), null, null))
             .build();
 
@@ -1285,7 +1263,7 @@ public class MetadataMigrateToDataTiersRoutingServiceTests extends ESTestCase {
                 new Phase("cold", TimeValue.ZERO, Map.of(coldAllocateAction.getWriteableName(), coldAllocateAction))
             )
         );
-        return new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong());
+        return new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong());
     }
 
     public void testMigrateLegacyIndexTemplates() {

+ 10 - 20
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java

@@ -42,9 +42,8 @@ import org.junit.Before;
 import org.mockito.Mockito;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
@@ -91,42 +90,33 @@ public class ExecuteStepsUpdateTaskTests extends ESTestCase {
         Phase mixedPhase = new Phase(
             "first_phase",
             TimeValue.ZERO,
-            Collections.singletonMap(MockAction.NAME, new MockAction(Arrays.asList(firstStep, secondStep, thirdStep)))
+            Map.of(MockAction.NAME, new MockAction(List.of(firstStep, secondStep, thirdStep)))
         );
         Phase allClusterPhase = new Phase(
             "first_phase",
             TimeValue.ZERO,
-            Collections.singletonMap(MockAction.NAME, new MockAction(Arrays.asList(firstStep, allClusterSecondStep)))
+            Map.of(MockAction.NAME, new MockAction(List.of(firstStep, allClusterSecondStep)))
         );
         Phase invalidPhase = new Phase(
             "invalid_phase",
             TimeValue.ZERO,
-            Collections.singletonMap(
-                MockAction.NAME,
-                new MockAction(Arrays.asList(new MockClusterStateActionStep(firstStepKey, invalidStepKey)))
-            )
-        );
-        LifecyclePolicy mixedPolicy = newTestLifecyclePolicy(mixedPolicyName, Collections.singletonMap(mixedPhase.getName(), mixedPhase));
-        LifecyclePolicy allClusterPolicy = newTestLifecyclePolicy(
-            allClusterPolicyName,
-            Collections.singletonMap(allClusterPhase.getName(), allClusterPhase)
-        );
-        LifecyclePolicy invalidPolicy = newTestLifecyclePolicy(
-            invalidPolicyName,
-            Collections.singletonMap(invalidPhase.getName(), invalidPhase)
+            Map.of(MockAction.NAME, new MockAction(List.of(new MockClusterStateActionStep(firstStepKey, invalidStepKey))))
         );
+        LifecyclePolicy mixedPolicy = newTestLifecyclePolicy(mixedPolicyName, Map.of(mixedPhase.getName(), mixedPhase));
+        LifecyclePolicy allClusterPolicy = newTestLifecyclePolicy(allClusterPolicyName, Map.of(allClusterPhase.getName(), allClusterPhase));
+        LifecyclePolicy invalidPolicy = newTestLifecyclePolicy(invalidPolicyName, Map.of(invalidPhase.getName(), invalidPhase));
         Map<String, LifecyclePolicyMetadata> policyMap = new HashMap<>();
         policyMap.put(
             mixedPolicyName,
-            new LifecyclePolicyMetadata(mixedPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+            new LifecyclePolicyMetadata(mixedPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         policyMap.put(
             allClusterPolicyName,
-            new LifecyclePolicyMetadata(allClusterPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+            new LifecyclePolicyMetadata(allClusterPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         policyMap.put(
             invalidPolicyName,
-            new LifecyclePolicyMetadata(invalidPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+            new LifecyclePolicyMetadata(invalidPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         policyStepsRegistry = new PolicyStepsRegistry(NamedXContentRegistry.EMPTY, client, null);
 

+ 2 - 3
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorServiceTests.java

@@ -36,7 +36,6 @@ import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata;
 import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -177,7 +176,7 @@ public class IlmHealthIndicatorServiceTests extends ESTestCase {
                     YELLOW,
                     "Index Lifecycle Management is not running",
                     new SimpleHealthIndicatorDetails(Map.of("ilm_status", status, "policies", 1, "stagnating_indices", 0)),
-                    Collections.singletonList(
+                    List.of(
                         new HealthIndicatorImpact(
                             NAME,
                             IlmHealthIndicatorService.AUTOMATION_DISABLED_IMPACT_ID,
@@ -251,7 +250,7 @@ public class IlmHealthIndicatorServiceTests extends ESTestCase {
                     YELLOW,
                     "Index Lifecycle Management is not running",
                     HealthIndicatorDetails.EMPTY,
-                    Collections.singletonList(
+                    List.of(
                         new HealthIndicatorImpact(
                             NAME,
                             IlmHealthIndicatorService.AUTOMATION_DISABLED_IMPACT_ID,

+ 6 - 7
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java

@@ -33,7 +33,6 @@ import org.junit.Before;
 import org.mockito.Mockito;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -75,18 +74,18 @@ public class IndexLifecycleInfoTransportActionTests extends ESTestCase {
         indexPolicies.put("index_3", policy1Name);
         indexPolicies.put("index_4", policy1Name);
         indexPolicies.put("index_5", policy3Name);
-        LifecyclePolicy policy1 = new LifecyclePolicy(policy1Name, Collections.emptyMap());
+        LifecyclePolicy policy1 = new LifecyclePolicy(policy1Name, Map.of());
         policies.add(policy1);
-        PolicyStats policy1Stats = new PolicyStats(Collections.emptyMap(), 4);
+        PolicyStats policy1Stats = new PolicyStats(Map.of(), 4);
 
         Map<String, Phase> phases1 = new HashMap<>();
         LifecyclePolicy policy2 = new LifecyclePolicy(policy2Name, phases1);
         policies.add(policy2);
-        PolicyStats policy2Stats = new PolicyStats(Collections.emptyMap(), 0);
+        PolicyStats policy2Stats = new PolicyStats(Map.of(), 0);
 
-        LifecyclePolicy policy3 = new LifecyclePolicy(policy3Name, Collections.emptyMap());
+        LifecyclePolicy policy3 = new LifecyclePolicy(policy3Name, Map.of());
         policies.add(policy3);
-        PolicyStats policy3Stats = new PolicyStats(Collections.emptyMap(), 1);
+        PolicyStats policy3Stats = new PolicyStats(Map.of(), 1);
 
         ClusterState clusterState = buildClusterState(policies, indexPolicies);
         Mockito.when(clusterService.state()).thenReturn(clusterState);
@@ -110,7 +109,7 @@ public class IndexLifecycleInfoTransportActionTests extends ESTestCase {
 
     private ClusterState buildClusterState(List<LifecyclePolicy> lifecyclePolicies, Map<String, String> indexPolicies) {
         Map<String, LifecyclePolicyMetadata> lifecyclePolicyMetadatasMap = lifecyclePolicies.stream()
-            .map(p -> new LifecyclePolicyMetadata(p, Collections.emptyMap(), 1, 0L))
+            .map(p -> new LifecyclePolicyMetadata(p, Map.of(), 1, 0L))
             .collect(Collectors.toMap(LifecyclePolicyMetadata::getName, Function.identity()));
         IndexLifecycleMetadata indexLifecycleMetadata = new IndexLifecycleMetadata(lifecyclePolicyMetadatasMap, OperationMode.RUNNING);
 

+ 7 - 12
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleMetadataTests.java

@@ -44,8 +44,6 @@ import org.elasticsearch.xpack.core.ilm.UnfollowAction;
 import org.elasticsearch.xpack.core.ilm.WaitForSnapshotAction;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
@@ -63,10 +61,7 @@ public class IndexLifecycleMetadataTests extends ChunkedToXContentDiffableSerial
         Map<String, LifecyclePolicyMetadata> policies = Maps.newMapWithExpectedSize(numPolicies);
         for (int i = 0; i < numPolicies; i++) {
             LifecyclePolicy policy = randomTimeseriesLifecyclePolicy(randomAlphaOfLength(4) + i);
-            policies.put(
-                policy.getName(),
-                new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-            );
+            policies.put(policy.getName(), new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         }
         return new IndexLifecycleMetadata(policies, randomFrom(OperationMode.values()));
     }
@@ -84,7 +79,7 @@ public class IndexLifecycleMetadataTests extends ChunkedToXContentDiffableSerial
     @Override
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
         return new NamedWriteableRegistry(
-            Arrays.asList(
+            List.of(
                 new NamedWriteableRegistry.Entry(
                     LifecycleType.class,
                     TimeseriesLifecycleType.TYPE,
@@ -111,7 +106,7 @@ public class IndexLifecycleMetadataTests extends ChunkedToXContentDiffableSerial
     protected NamedXContentRegistry xContentRegistry() {
         List<NamedXContentRegistry.Entry> entries = new ArrayList<>(ClusterModule.getNamedXWriteables());
         entries.addAll(
-            Arrays.asList(
+            List.of(
                 new NamedXContentRegistry.Entry(
                     LifecycleType.class,
                     new ParseField(TimeseriesLifecycleType.TYPE),
@@ -155,7 +150,7 @@ public class IndexLifecycleMetadataTests extends ChunkedToXContentDiffableSerial
                 policyName,
                 new LifecyclePolicyMetadata(
                     randomTimeseriesLifecyclePolicy(policyName),
-                    Collections.emptyMap(),
+                    Map.of(),
                     randomNonNegativeLong(),
                     randomNonNegativeLong()
                 )
@@ -192,9 +187,9 @@ public class IndexLifecycleMetadataTests extends ChunkedToXContentDiffableSerial
             Map<String, Phase> phases = Maps.newMapWithExpectedSize(numberPhases);
             for (int j = 0; j < numberPhases; j++) {
                 TimeValue after = randomTimeValue(0, 1_000_000_000, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS);
-                Map<String, LifecycleAction> actions = Collections.emptyMap();
+                Map<String, LifecycleAction> actions = Map.of();
                 if (randomBoolean()) {
-                    actions = Collections.singletonMap(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE);
+                    actions = Map.of(DeleteAction.NAME, DeleteAction.WITH_SNAPSHOT_DELETE);
                 }
                 String phaseName = randomAlphaOfLength(10);
                 phases.put(phaseName, new Phase(phaseName, after, actions));
@@ -204,7 +199,7 @@ public class IndexLifecycleMetadataTests extends ChunkedToXContentDiffableSerial
                 policyName,
                 new LifecyclePolicyMetadata(
                     newTestLifecyclePolicy(policyName, phases),
-                    Collections.emptyMap(),
+                    Map.of(),
                     randomNonNegativeLong(),
                     randomNonNegativeLong()
                 )

+ 17 - 20
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java

@@ -73,8 +73,6 @@ import org.mockito.Mockito;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -89,7 +87,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.BiFunction;
 
-import static java.util.stream.Collectors.toList;
 import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.awaitLatch;
 import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING;
@@ -248,7 +245,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
         List<Step> waitForRolloverStepList = action.toSteps(client, phaseName, null)
             .stream()
             .filter(s -> s.getKey().name().equals(WaitForRolloverReadyStep.NAME))
-            .collect(toList());
+            .toList();
         assertThat(waitForRolloverStepList.size(), is(1));
         Step waitForRolloverStep = waitForRolloverStepList.get(0);
         StepKey stepKey = waitForRolloverStep.getKey();
@@ -288,7 +285,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             .build();
         ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
         DiscoveryNode node = clusterService.localNode();
-        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         ClusterState state = ClusterState.builder(new ClusterName("cluster"))
             .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm))
             .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId()))
@@ -317,7 +314,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
         StepKey nextStepKey = new StepKey("phase", "action", "next_cluster_state_action_step");
         MockClusterStateActionStep step = new MockClusterStateActionStep(stepKey, nextStepKey);
         MockClusterStateActionStep nextStep = new MockClusterStateActionStep(nextStepKey, null);
-        MockPolicyStepsRegistry stepRegistry = createMultiStepPolicyStepRegistry(policyName, Arrays.asList(step, nextStep));
+        MockPolicyStepsRegistry stepRegistry = createMultiStepPolicyStepRegistry(policyName, List.of(step, nextStep));
         stepRegistry.setResolver((i, k) -> {
             if (stepKey.equals(k)) {
                 return step;
@@ -340,7 +337,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             .build();
         ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
         DiscoveryNode node = clusterService.localNode();
-        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         ClusterState state = ClusterState.builder(new ClusterName("cluster"))
             .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm))
             .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId()))
@@ -427,7 +424,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             .build();
         ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
         DiscoveryNode node = clusterService.localNode();
-        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         ClusterState state = ClusterState.builder(new ClusterName("cluster"))
             .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm))
             .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId()))
@@ -476,7 +473,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             .build();
         ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
         DiscoveryNode node = clusterService.localNode();
-        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         ClusterState state = ClusterState.builder(new ClusterName("cluster"))
             .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm))
             .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId()))
@@ -503,7 +500,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
         StepKey nextStepKey = new StepKey("phase", "action", "async_action_step");
         MockClusterStateActionStep step = new MockClusterStateActionStep(stepKey, nextStepKey);
         MockAsyncActionStep nextStep = new MockAsyncActionStep(nextStepKey, null);
-        MockPolicyStepsRegistry stepRegistry = createMultiStepPolicyStepRegistry(policyName, Arrays.asList(step, nextStep));
+        MockPolicyStepsRegistry stepRegistry = createMultiStepPolicyStepRegistry(policyName, List.of(step, nextStep));
         stepRegistry.setResolver((i, k) -> {
             if (stepKey.equals(k)) {
                 return step;
@@ -526,7 +523,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             .build();
         ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
         DiscoveryNode node = clusterService.localNode();
-        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         ClusterState state = ClusterState.builder(new ClusterName("cluster"))
             .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm))
             .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId()))
@@ -603,7 +600,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             .build();
         ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
         DiscoveryNode node = clusterService.localNode();
-        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         ClusterState state = ClusterState.builder(new ClusterName("cluster"))
             .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm))
             .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId()))
@@ -785,7 +782,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
         Client client = mock(Client.class);
         when(client.settings()).thenReturn(Settings.EMPTY);
         LifecyclePolicy policy = LifecyclePolicyTests.randomTimeseriesLifecyclePolicyWithAllPhases(policyName);
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Collections.emptyMap(), 1, randomNonNegativeLong());
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Map.of(), 1, randomNonNegativeLong());
         String phaseName = randomFrom(policy.getPhases().keySet());
         Phase phase = policy.getPhases().get(phaseName);
         PhaseExecutionInfo pei = new PhaseExecutionInfo(policy.getName(), phase, 1, randomNonNegativeLong());
@@ -824,7 +821,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
         StepKey stepKey = new StepKey("phase", MockAction.NAME, MockAction.NAME);
         MockAsyncActionStep step = new MockAsyncActionStep(stepKey, null);
         SortedMap<String, LifecyclePolicyMetadata> lifecyclePolicyMap = new TreeMap<>(
-            Collections.singletonMap(
+            Map.of(
                 policyName,
                 new LifecyclePolicyMetadata(
                     createPolicy(policyName, null, step.getKey()),
@@ -834,9 +831,9 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
                 )
             )
         );
-        Map<String, Step> firstStepMap = Collections.singletonMap(policyName, step);
-        Map<StepKey, Step> policySteps = Collections.singletonMap(step.getKey(), step);
-        Map<String, Map<StepKey, Step>> stepMap = Collections.singletonMap(policyName, policySteps);
+        Map<String, Step> firstStepMap = Map.of(policyName, step);
+        Map<StepKey, Step> policySteps = Map.of(step.getKey(), step);
+        Map<String, Map<StepKey, Step>> stepMap = Map.of(policyName, policySteps);
         PolicyStepsRegistry policyStepsRegistry = new PolicyStepsRegistry(
             lifecyclePolicyMap,
             firstStepMap,
@@ -897,7 +894,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
             assert unsafeStep == null || safeStep.phase().equals(unsafeStep.phase()) == false
                 : "safe and unsafe actions must be in different phases";
             Map<String, LifecycleAction> actions = new HashMap<>();
-            List<Step> steps = Collections.singletonList(new MockStep(safeStep, null));
+            List<Step> steps = List.of(new MockStep(safeStep, null));
             MockAction safeAction = new MockAction(steps, true);
             actions.put(safeAction.getWriteableName(), safeAction);
             Phase phase = new Phase(safeStep.phase(), TimeValue.timeValueMillis(0), actions);
@@ -906,7 +903,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
         if (unsafeStep != null) {
             assert MockAction.NAME.equals(unsafeStep.action()) : "The unsafe action needs to be MockAction.NAME";
             Map<String, LifecycleAction> actions = new HashMap<>();
-            List<Step> steps = Collections.singletonList(new MockStep(unsafeStep, null));
+            List<Step> steps = List.of(new MockStep(unsafeStep, null));
             MockAction unsafeAction = new MockAction(steps, false);
             actions.put(unsafeAction.getWriteableName(), unsafeAction);
             Phase phase = new Phase(unsafeStep.phase(), TimeValue.timeValueMillis(0), actions);
@@ -1233,7 +1230,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
     }
 
     public static MockPolicyStepsRegistry createOneStepPolicyStepRegistry(String policyName, Step step) {
-        return createMultiStepPolicyStepRegistry(policyName, Collections.singletonList(step));
+        return createMultiStepPolicyStepRegistry(policyName, List.of(step));
     }
 
     public static MockPolicyStepsRegistry createMultiStepPolicyStepRegistry(String policyName, List<Step> steps) {

+ 36 - 72
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java

@@ -58,9 +58,9 @@ import org.mockito.Mockito;
 import java.time.Clock;
 import java.time.Instant;
 import java.time.ZoneId;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.UUID;
@@ -114,7 +114,7 @@ public class IndexLifecycleServiceTests extends ESTestCase {
         }).when(executorService).execute(any());
         Settings settings = Settings.builder().put(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s").build();
         when(clusterService.getClusterSettings()).thenReturn(
-            new ClusterSettings(settings, Collections.singleton(LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING))
+            new ClusterSettings(settings, Set.of(LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING))
         );
         when(clusterService.lifecycleState()).thenReturn(State.STARTED);
 
@@ -154,14 +154,11 @@ public class IndexLifecycleServiceTests extends ESTestCase {
             randomStepKey(),
             randomStepKey()
         );
-        MockAction mockAction = new MockAction(Collections.singletonList(mockStep));
-        Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction));
-        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase));
+        MockAction mockAction = new MockAction(List.of(mockStep));
+        Phase phase = new Phase("phase", TimeValue.ZERO, Map.of("action", mockAction));
+        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Map.of(phase.getName(), phase));
         SortedMap<String, LifecyclePolicyMetadata> policyMap = new TreeMap<>();
-        policyMap.put(
-            policyName,
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
         IndexMetadata indexMetadata = IndexMetadata.builder(index.getName())
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
@@ -191,14 +188,11 @@ public class IndexLifecycleServiceTests extends ESTestCase {
             mockShrinkStep,
             randomStepKey()
         );
-        MockAction mockAction = new MockAction(Collections.singletonList(mockStep));
-        Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction));
-        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase));
+        MockAction mockAction = new MockAction(List.of(mockStep));
+        Phase phase = new Phase("phase", TimeValue.ZERO, Map.of("action", mockAction));
+        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Map.of(phase.getName(), phase));
         SortedMap<String, LifecyclePolicyMetadata> policyMap = new TreeMap<>();
-        policyMap.put(
-            policyName,
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
         LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder();
         lifecycleState.setPhase(mockShrinkStep.phase());
@@ -250,14 +244,11 @@ public class IndexLifecycleServiceTests extends ESTestCase {
             mockShrinkStep,
             randomStepKey()
         );
-        MockAction mockAction = new MockAction(Collections.singletonList(mockStep));
-        Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction));
-        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase));
+        MockAction mockAction = new MockAction(List.of(mockStep));
+        Phase phase = new Phase("phase", TimeValue.ZERO, Map.of("action", mockAction));
+        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Map.of(phase.getName(), phase));
         SortedMap<String, LifecyclePolicyMetadata> policyMap = new TreeMap<>();
-        policyMap.put(
-            policyName,
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
         LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder();
         lifecycleState.setPhase(mockShrinkStep.phase());
@@ -301,14 +292,11 @@ public class IndexLifecycleServiceTests extends ESTestCase {
             currentStepKey,
             randomStepKey()
         );
-        MockAction mockAction = new MockAction(Collections.singletonList(mockStep));
-        Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction));
-        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase));
+        MockAction mockAction = new MockAction(List.of(mockStep));
+        Phase phase = new Phase("phase", TimeValue.ZERO, Map.of("action", mockAction));
+        LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Map.of(phase.getName(), phase));
         SortedMap<String, LifecyclePolicyMetadata> policyMap = new TreeMap<>();
-        policyMap.put(
-            policyName,
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
         LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder();
         lifecycleState.setPhase(currentStepKey.phase());
@@ -370,9 +358,9 @@ public class IndexLifecycleServiceTests extends ESTestCase {
         } else {
             i1mockStep = new IndexLifecycleRunnerTests.MockClusterStateActionStep(i1currentStepKey, randomStepKey());
         }
-        MockAction i1mockAction = new MockAction(Collections.singletonList(i1mockStep));
-        Phase i1phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", i1mockAction));
-        LifecyclePolicy i1policy = newTestLifecyclePolicy(policy1, Collections.singletonMap(i1phase.getName(), i1phase));
+        MockAction i1mockAction = new MockAction(List.of(i1mockStep));
+        Phase i1phase = new Phase("phase", TimeValue.ZERO, Map.of("action", i1mockAction));
+        LifecyclePolicy i1policy = newTestLifecyclePolicy(policy1, Map.of(i1phase.getName(), i1phase));
         Index index1 = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
         LifecycleExecutionState.Builder i1lifecycleState = LifecycleExecutionState.builder();
         i1lifecycleState.setPhase(i1currentStepKey.phase());
@@ -387,9 +375,9 @@ public class IndexLifecycleServiceTests extends ESTestCase {
         } else {
             i2mockStep = new IndexLifecycleRunnerTests.MockClusterStateActionStep(i2currentStepKey, randomStepKey());
         }
-        MockAction mockAction = new MockAction(Collections.singletonList(i2mockStep));
-        Phase i2phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction));
-        LifecyclePolicy i2policy = newTestLifecyclePolicy(policy1, Collections.singletonMap(i2phase.getName(), i1phase));
+        MockAction mockAction = new MockAction(List.of(i2mockStep));
+        Phase i2phase = new Phase("phase", TimeValue.ZERO, Map.of("action", mockAction));
+        LifecyclePolicy i2policy = newTestLifecyclePolicy(policy1, Map.of(i2phase.getName(), i1phase));
         Index index2 = new Index(
             randomValueOtherThan(index1.getName(), () -> randomAlphaOfLengthBetween(1, 20)),
             randomAlphaOfLengthBetween(1, 20)
@@ -422,14 +410,8 @@ public class IndexLifecycleServiceTests extends ESTestCase {
         }
 
         SortedMap<String, LifecyclePolicyMetadata> policyMap = new TreeMap<>();
-        policyMap.put(
-            policy1,
-            new LifecyclePolicyMetadata(i1policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
-        policyMap.put(
-            policy2,
-            new LifecyclePolicyMetadata(i2policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMap.put(policy1, new LifecyclePolicyMetadata(i1policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
+        policyMap.put(policy2, new LifecyclePolicyMetadata(i2policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
 
         IndexMetadata i1indexMetadata = IndexMetadata.builder(index1.getName())
             .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, policy1))
@@ -533,14 +515,8 @@ public class IndexLifecycleServiceTests extends ESTestCase {
             SingleNodeShutdownMetadata.Type.REPLACE
         )) {
             ClusterState state = ClusterState.builder(ClusterName.DEFAULT).build();
-            assertThat(
-                IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "regular_node"),
-                equalTo(Collections.emptySet())
-            );
-            assertThat(
-                IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"),
-                equalTo(Collections.emptySet())
-            );
+            assertThat(IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "regular_node"), equalTo(Set.of()));
+            assertThat(IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"), equalTo(Set.of()));
 
             IndexMetadata nonDangerousIndex = IndexMetadata.builder("no_danger")
                 .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy"))
@@ -583,7 +559,7 @@ public class IndexLifecycleServiceTests extends ESTestCase {
             Map<String, IndexMetadata> indices = Map.of("no_danger", nonDangerousIndex, "danger", dangerousIndex);
 
             Metadata metadata = Metadata.builder()
-                .putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING))
+                .putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING))
                 .indices(indices)
                 .persistentSettings(settings(IndexVersion.current()).build())
                 .build();
@@ -612,14 +588,8 @@ public class IndexLifecycleServiceTests extends ESTestCase {
                 .build();
 
             // No danger yet, because no node is shutting down
-            assertThat(
-                IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "regular_node"),
-                equalTo(Collections.emptySet())
-            );
-            assertThat(
-                IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"),
-                equalTo(Collections.emptySet())
-            );
+            assertThat(IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "regular_node"), equalTo(Set.of()));
+            assertThat(IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"), equalTo(Set.of()));
 
             state = ClusterState.builder(state)
                 .metadata(
@@ -627,7 +597,7 @@ public class IndexLifecycleServiceTests extends ESTestCase {
                         .putCustom(
                             NodesShutdownMetadata.TYPE,
                             new NodesShutdownMetadata(
-                                Collections.singletonMap(
+                                Map.of(
                                     "shutdown_node",
                                     SingleNodeShutdownMetadata.builder()
                                         .setNodeId("shutdown_node")
@@ -642,15 +612,12 @@ public class IndexLifecycleServiceTests extends ESTestCase {
                 )
                 .build();
 
-            assertThat(
-                IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "regular_node"),
-                equalTo(Collections.emptySet())
-            );
+            assertThat(IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "regular_node"), equalTo(Set.of()));
             // No danger, because this is a "RESTART" type shutdown
             assertThat(
                 "restart type shutdowns are not considered dangerous",
                 IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"),
-                equalTo(Collections.emptySet())
+                equalTo(Set.of())
             );
 
             final String targetNodeName = type == SingleNodeShutdownMetadata.Type.REPLACE ? randomAlphaOfLengthBetween(10, 20) : null;
@@ -661,7 +628,7 @@ public class IndexLifecycleServiceTests extends ESTestCase {
                         .putCustom(
                             NodesShutdownMetadata.TYPE,
                             new NodesShutdownMetadata(
-                                Collections.singletonMap(
+                                Map.of(
                                     "shutdown_node",
                                     SingleNodeShutdownMetadata.builder()
                                         .setNodeId("shutdown_node")
@@ -679,10 +646,7 @@ public class IndexLifecycleServiceTests extends ESTestCase {
                 .build();
 
             // The dangerous index should be calculated as being in danger now
-            assertThat(
-                IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"),
-                equalTo(Collections.singleton("danger"))
-            );
+            assertThat(IndexLifecycleService.indicesOnShuttingDownNodesInDangerousStep(state, "shutdown_node"), equalTo(Set.of("danger")));
         }
     }
 }

+ 38 - 64
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java

@@ -48,7 +48,6 @@ import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -80,8 +79,8 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             .stream()
             .findFirst()
             .orElseThrow(() -> new AssertionError("expected next phase to be present"));
-        List<LifecyclePolicyMetadata> policyMetadatas = Collections.singletonList(
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+        List<LifecyclePolicyMetadata> policyMetadatas = List.of(
+            new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         Step.StepKey currentStep = new Step.StepKey("current_phase", "current_action", "current_step");
         Step.StepKey nextStep = new Step.StepKey(nextPhase.getName(), "next_action", "next_step");
@@ -128,8 +127,8 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             p -> p.getPhases().isEmpty(),
             () -> LifecyclePolicyTests.randomTestLifecyclePolicy("policy")
         );
-        List<LifecyclePolicyMetadata> policyMetadatas = Collections.singletonList(
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+        List<LifecyclePolicyMetadata> policyMetadatas = List.of(
+            new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         Step.StepKey currentStep = new Step.StepKey("current_phase", "current_action", "current_step");
         Step.StepKey nextStep = new Step.StepKey("current_phase", "next_action", "next_step");
@@ -179,8 +178,8 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             p -> p.getPhases().isEmpty(),
             () -> LifecyclePolicyTests.randomTestLifecyclePolicy("policy")
         );
-        List<LifecyclePolicyMetadata> policyMetadatas = Collections.singletonList(
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+        List<LifecyclePolicyMetadata> policyMetadatas = List.of(
+            new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         Step.StepKey currentStep = new Step.StepKey("current_phase", "current_action", "current_step");
         Step.StepKey nextStep = new Step.StepKey("current_phase", "current_action", "next_step");
@@ -236,8 +235,8 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             .stream()
             .findFirst()
             .orElseThrow(() -> new AssertionError("expected next phase to be present"));
-        List<LifecyclePolicyMetadata> policyMetadatas = Collections.singletonList(
-            new LifecyclePolicyMetadata(policy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
+        List<LifecyclePolicyMetadata> policyMetadatas = List.of(
+            new LifecyclePolicyMetadata(policy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
         );
         Step.StepKey currentStepKey = new Step.StepKey("current_phase", "current_action", "current_step");
         Step.StepKey nextStepKey = new Step.StepKey(nextPhase.getName(), "next_action", "next_step");
@@ -279,7 +278,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(currentStepKey.action());
         lifecycleState.setStep(currentStepKey.name());
 
-        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList());
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of());
         Index index = clusterState.metadata().index(indexName).getIndex();
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
@@ -303,7 +302,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(currentStepKey.action());
         lifecycleState.setStep(currentStepKey.name());
 
-        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList());
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of());
         Index index = clusterState.metadata().index(indexName).getIndex();
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
@@ -325,7 +324,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setPhase(currentStep.phase());
         lifecycleState.setAction(currentStep.action());
         lifecycleState.setStep(currentStep.name());
-        ClusterState clusterState = buildClusterState(indexName, Settings.builder(), lifecycleState.build(), Collections.emptyList());
+        ClusterState clusterState = buildClusterState(indexName, Settings.builder(), lifecycleState.build(), List.of());
         Index index = clusterState.metadata().index(indexName).getIndex();
 
         ClusterState newClusterState = IndexLifecycleTransition.moveClusterStateToErrorStep(
@@ -359,7 +358,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setPhase(currentStep.phase());
         lifecycleState.setAction(currentStep.action());
         lifecycleState.setStep(currentStep.name());
-        ClusterState clusterState = buildClusterState(indexName, Settings.builder(), lifecycleState.build(), Collections.emptyList());
+        ClusterState clusterState = buildClusterState(indexName, Settings.builder(), lifecycleState.build(), List.of());
         Index index = clusterState.metadata().index(indexName).getIndex();
         ClusterState newClusterState = IndexLifecycleTransition.addStepInfoToClusterState(index, clusterState, stepInfo);
         assertClusterStateStepInfo(clusterState, index, currentStep, newClusterState, stepInfo);
@@ -378,9 +377,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(currentStep.action());
         lifecycleState.setStep(currentStep.name());
         List<LifecyclePolicyMetadata> policyMetadatas = new ArrayList<>();
-        policyMetadatas.add(
-            new LifecyclePolicyMetadata(oldPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMetadatas.add(new LifecyclePolicyMetadata(oldPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas);
         Index index = clusterState.metadata().index(indexName).getIndex();
         Index[] indices = new Index[] { index };
@@ -399,7 +396,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             indexName,
             indexSettingsBuilder,
             LifecycleExecutionState.builder().build(),
-            Collections.emptyList()
+            List.of()
         );
         Index index = clusterState.metadata().index(indexName).getIndex();
         Index[] indices = new Index[] { index };
@@ -414,7 +411,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
     public void testRemovePolicyForIndexIndexDoesntExist() {
         String indexName = randomAlphaOfLength(10);
         String oldPolicyName = "old_policy";
-        LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Collections.emptyMap());
+        LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Map.of());
         Step.StepKey currentStep = AbstractStepTestCase.randomStepKey();
         Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName);
         LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder();
@@ -422,9 +419,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(currentStep.action());
         lifecycleState.setStep(currentStep.name());
         List<LifecyclePolicyMetadata> policyMetadatas = new ArrayList<>();
-        policyMetadatas.add(
-            new LifecyclePolicyMetadata(oldPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMetadatas.add(new LifecyclePolicyMetadata(oldPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas);
         Index index = new Index("doesnt_exist", "im_not_here");
         Index[] indices = new Index[] { index };
@@ -448,9 +443,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(currentStep.action());
         lifecycleState.setStep(currentStep.name());
         List<LifecyclePolicyMetadata> policyMetadatas = new ArrayList<>();
-        policyMetadatas.add(
-            new LifecyclePolicyMetadata(oldPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMetadatas.add(new LifecyclePolicyMetadata(oldPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas);
         Index index = clusterState.metadata().index(indexName).getIndex();
         Index[] indices = new Index[] { index };
@@ -475,9 +468,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(currentStep.action());
         lifecycleState.setStep(currentStep.name());
         List<LifecyclePolicyMetadata> policyMetadatas = new ArrayList<>();
-        policyMetadatas.add(
-            new LifecyclePolicyMetadata(oldPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMetadatas.add(new LifecyclePolicyMetadata(oldPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
         ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas);
         Index index = clusterState.metadata().index(indexName).getIndex();
         Index[] indices = new Index[] { index };
@@ -756,7 +747,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         LifecyclePolicy policy = createPolicy(policyName, failedStepKey, null);
         LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(
             policy,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -771,12 +762,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setStep(errorStepKey.name());
         lifecycleState.setStepTime(now);
         lifecycleState.setFailedStep(failedStepKey.name());
-        ClusterState clusterState = buildClusterState(
-            indexName,
-            indexSettingsBuilder,
-            lifecycleState.build(),
-            Collections.singletonList(policyMetadata)
-        );
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of(policyMetadata));
         Index index = clusterState.metadata().index(indexName).getIndex();
         ClusterState nextClusterState = IndexLifecycleTransition.moveClusterStateToPreviouslyFailedStep(
             clusterState,
@@ -802,7 +788,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         LifecyclePolicy policy = createPolicy(policyName, failedStepKey, null);
         LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(
             policy,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -817,12 +803,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setStep(errorStepKey.name());
         lifecycleState.setStepTime(now);
         lifecycleState.setFailedStep(failedStepKey.name());
-        ClusterState clusterState = buildClusterState(
-            indexName,
-            indexSettingsBuilder,
-            lifecycleState.build(),
-            Collections.singletonList(policyMetadata)
-        );
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of(policyMetadata));
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
             () -> IndexLifecycleTransition.moveClusterStateToPreviouslyFailedStep(clusterState, indexName, () -> now, policyRegistry, false)
@@ -840,7 +821,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             existingIndexName,
             Settings.builder(),
             LifecycleExecutionState.builder().build(),
-            Collections.emptyList()
+            List.of()
         );
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
@@ -863,7 +844,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setAction(errorStepKey.action());
         lifecycleState.setStep(errorStepKey.name());
         lifecycleState.setFailedStep(failedStepKey.name());
-        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList());
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of());
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
             () -> IndexLifecycleTransition.moveClusterStateToPreviouslyFailedStep(clusterState, indexName, () -> now, policyRegistry, false)
@@ -883,7 +864,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setPhase(failedStepKey.phase());
         lifecycleState.setAction(failedStepKey.action());
         lifecycleState.setStep(failedStepKey.name());
-        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList());
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of());
         IllegalArgumentException exception = expectThrows(
             IllegalArgumentException.class,
             () -> IndexLifecycleTransition.moveClusterStateToPreviouslyFailedStep(clusterState, indexName, () -> now, policyRegistry, false)
@@ -906,7 +887,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         LifecyclePolicy policy = createPolicy(policyName, failedStepKey, null);
         LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(
             policy,
-            Collections.emptyMap(),
+            Map.of(),
             randomNonNegativeLong(),
             randomNonNegativeLong()
         );
@@ -923,12 +904,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         lifecycleState.setFailedStep(failedStepKey.name());
         String initialStepInfo = randomAlphaOfLengthBetween(10, 50);
         lifecycleState.setStepInfo(initialStepInfo);
-        ClusterState clusterState = buildClusterState(
-            indexName,
-            indexSettingsBuilder,
-            lifecycleState.build(),
-            Collections.singletonList(policyMetadata)
-        );
+        ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), List.of(policyMetadata));
         Index index = clusterState.metadata().index(indexName).getIndex();
         ClusterState nextClusterState = IndexLifecycleTransition.moveClusterStateToPreviouslyFailedStep(
             clusterState,
@@ -976,13 +952,11 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         Map<String, LifecycleAction> actions = new HashMap<>();
         actions.put("set_priority", new SetPriorityAction(100));
         Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-        Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+        Map<String, Phase> phases = Map.of("hot", hotPhase);
         LifecyclePolicy currentPolicy = new LifecyclePolicy("my-policy", phases);
 
         List<LifecyclePolicyMetadata> policyMetadatas = new ArrayList<>();
-        policyMetadatas.add(
-            new LifecyclePolicyMetadata(currentPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-        );
+        policyMetadatas.add(new LifecyclePolicyMetadata(currentPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()));
 
         Step.StepKey errorStepKey = new Step.StepKey("hot", RolloverAction.NAME, ErrorStep.NAME);
         PolicyStepsRegistry stepsRegistry = createOneStepPolicyStepRegistry("my-policy", new ErrorStep(errorStepKey));
@@ -1040,9 +1014,9 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
         actions.put("set_priority", new SetPriorityAction(100));
         Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-        Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+        Map<String, Phase> phases = Map.of("hot", hotPhase);
         LifecyclePolicy newPolicy = new LifecyclePolicy("my-policy", phases);
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(newPolicy, Collections.emptyMap(), 2L, 2L);
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(newPolicy, Map.of(), 2L, 2L);
 
         ClusterState existingState = ClusterState.builder(ClusterState.EMPTY_STATE)
             .metadata(Metadata.builder(Metadata.EMPTY_METADATA).put(meta, false).build())
@@ -1185,7 +1159,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         actions.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
         actions.put("set_priority", new SetPriorityAction(100));
         Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
-        Map<String, Phase> phases = Collections.singletonMap("hot", hotPhase);
+        Map<String, Phase> phases = Map.of("hot", hotPhase);
         LifecyclePolicy currentPolicy = new LifecyclePolicy("my-policy", phases);
 
         {
@@ -1195,10 +1169,10 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             Map<String, LifecycleAction> actionsWithoutRollover = new HashMap<>();
             actionsWithoutRollover.put("set_priority", new SetPriorityAction(100));
             Phase hotPhaseNoRollover = new Phase("hot", TimeValue.ZERO, actionsWithoutRollover);
-            Map<String, Phase> phasesNoRollover = Collections.singletonMap("hot", hotPhaseNoRollover);
+            Map<String, Phase> phasesNoRollover = Map.of("hot", hotPhaseNoRollover);
             LifecyclePolicyMetadata updatedPolicyMetadata = new LifecyclePolicyMetadata(
                 new LifecyclePolicy("my-policy", phasesNoRollover),
-                Collections.emptyMap(),
+                Map.of(),
                 2L,
                 2L
             );
@@ -1233,10 +1207,10 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             Map<String, LifecycleAction> actionsWitoutSetPriority = new HashMap<>();
             actionsWitoutSetPriority.put("rollover", new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
             Phase hotPhaseNoSetPriority = new Phase("hot", TimeValue.ZERO, actionsWitoutSetPriority);
-            Map<String, Phase> phasesWithoutSetPriority = Collections.singletonMap("hot", hotPhaseNoSetPriority);
+            Map<String, Phase> phasesWithoutSetPriority = Map.of("hot", hotPhaseNoSetPriority);
             LifecyclePolicyMetadata updatedPolicyMetadata = new LifecyclePolicyMetadata(
                 new LifecyclePolicy("my-policy", phasesWithoutSetPriority),
-                Collections.emptyMap(),
+                Map.of(),
                 2L,
                 2L
             );
@@ -1275,7 +1249,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
             assert unsafeStep == null || safeStep.phase().equals(unsafeStep.phase()) == false
                 : "safe and unsafe actions must be in different phases";
             Map<String, LifecycleAction> actions = new HashMap<>();
-            List<Step> steps = Collections.singletonList(new MockStep(safeStep, null));
+            List<Step> steps = List.of(new MockStep(safeStep, null));
             MockAction safeAction = new MockAction(steps, true);
             actions.put(safeAction.getWriteableName(), safeAction);
             Phase phase = new Phase(safeStep.phase(), TimeValue.timeValueMillis(0), actions);
@@ -1284,7 +1258,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
         if (unsafeStep != null) {
             assert MockAction.NAME.equals(unsafeStep.action()) : "The unsafe action needs to be MockAction.NAME";
             Map<String, LifecycleAction> actions = new HashMap<>();
-            List<Step> steps = Collections.singletonList(new MockStep(unsafeStep, null));
+            List<Step> steps = List.of(new MockStep(unsafeStep, null));
             MockAction unsafeAction = new MockAction(steps, false);
             actions.put(unsafeAction.getWriteableName(), unsafeAction);
             Phase phase = new Phase(unsafeStep.phase(), TimeValue.timeValueMillis(0), actions);

+ 2 - 5
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTaskTests.java

@@ -28,7 +28,7 @@ import org.elasticsearch.xpack.core.ilm.Step;
 import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 import org.junit.Before;
 
-import java.util.Collections;
+import java.util.Map;
 
 import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
 import static org.hamcrest.Matchers.containsString;
@@ -53,10 +53,7 @@ public class MoveToErrorStepUpdateTaskTests extends ESTestCase {
             .build();
         index = indexMetadata.getIndex();
         IndexLifecycleMetadata ilmMeta = new IndexLifecycleMetadata(
-            Collections.singletonMap(
-                policy,
-                new LifecyclePolicyMetadata(lifecyclePolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-            ),
+            Map.of(policy, new LifecyclePolicyMetadata(lifecyclePolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())),
             OperationMode.RUNNING
         );
         Metadata metadata = Metadata.builder()

+ 3 - 7
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTaskTests.java

@@ -29,7 +29,6 @@ import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 import org.junit.Before;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -67,10 +66,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
         index = indexMetadata.getIndex();
         lifecyclePolicy = LifecyclePolicyTests.randomTestLifecyclePolicy(policy);
         IndexLifecycleMetadata ilmMeta = new IndexLifecycleMetadata(
-            Collections.singletonMap(
-                policy,
-                new LifecyclePolicyMetadata(lifecyclePolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-            ),
+            Map.of(policy, new LifecyclePolicyMetadata(lifecyclePolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())),
             OperationMode.RUNNING
         );
         Metadata metadata = Metadata.builder()
@@ -95,7 +91,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
         AlwaysExistingStepRegistry stepRegistry = new AlwaysExistingStepRegistry(client);
         stepRegistry.update(
             new IndexLifecycleMetadata(
-                Map.of(policy, new LifecyclePolicyMetadata(lifecyclePolicy, Collections.emptyMap(), 2L, 2L)),
+                Map.of(policy, new LifecyclePolicyMetadata(lifecyclePolicy, Map.of(), 2L, 2L)),
                 OperationMode.RUNNING
             )
         );
@@ -169,7 +165,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
         AlwaysExistingStepRegistry stepRegistry = new AlwaysExistingStepRegistry(client);
         stepRegistry.update(
             new IndexLifecycleMetadata(
-                Map.of(policy, new LifecyclePolicyMetadata(lifecyclePolicy, Collections.emptyMap(), 2L, 2L)),
+                Map.of(policy, new LifecyclePolicyMetadata(lifecyclePolicy, Map.of(), 2L, 2L)),
                 OperationMode.RUNNING
             )
         );

+ 13 - 17
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java

@@ -46,7 +46,6 @@ import org.elasticsearch.xpack.core.ilm.ShrinkStep;
 import org.elasticsearch.xpack.core.ilm.Step;
 import org.mockito.Mockito;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -76,7 +75,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
     public void testGetFirstStep() {
         String policyName = randomAlphaOfLengthBetween(2, 10);
         Step expectedFirstStep = new MockStep(MOCK_STEP_KEY, null);
-        Map<String, Step> firstStepMap = Collections.singletonMap(policyName, expectedFirstStep);
+        Map<String, Step> firstStepMap = Map.of(policyName, expectedFirstStep);
         PolicyStepsRegistry registry = new PolicyStepsRegistry(null, firstStepMap, null, NamedXContentRegistry.EMPTY, null, null);
         Step actualFirstStep = registry.getFirstStep(policyName);
         assertThat(actualFirstStep, sameInstance(expectedFirstStep));
@@ -85,7 +84,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
     public void testGetFirstStepUnknownPolicy() {
         String policyName = randomAlphaOfLengthBetween(2, 10);
         Step expectedFirstStep = new MockStep(MOCK_STEP_KEY, null);
-        Map<String, Step> firstStepMap = Collections.singletonMap(policyName, expectedFirstStep);
+        Map<String, Step> firstStepMap = Map.of(policyName, expectedFirstStep);
         PolicyStepsRegistry registry = new PolicyStepsRegistry(null, firstStepMap, null, NamedXContentRegistry.EMPTY, null, null);
         Step actualFirstStep = registry.getFirstStep(policyName + "unknown");
         assertNull(actualFirstStep);
@@ -95,7 +94,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         Client client = mock(Client.class);
         Mockito.when(client.settings()).thenReturn(Settings.EMPTY);
         LifecyclePolicy policy = LifecyclePolicyTests.randomTimeseriesLifecyclePolicyWithAllPhases("policy");
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Collections.emptyMap(), 1, randomNonNegativeLong());
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Map.of(), 1, randomNonNegativeLong());
         String phaseName = randomFrom(policy.getPhases().keySet());
         Phase phase = policy.getPhases().get(phaseName);
         PhaseExecutionInfo pei = new PhaseExecutionInfo(policy.getName(), phase, 1, randomNonNegativeLong());
@@ -119,7 +118,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         Step.StepKey errorStepKey = new Step.StepKey(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10), ErrorStep.NAME);
         Step expectedStep = new ErrorStep(errorStepKey);
         Index index = new Index("test", "uuid");
-        Map<Index, List<Step>> indexSteps = Collections.singletonMap(index, Collections.singletonList(expectedStep));
+        Map<Index, List<Step>> indexSteps = Map.of(index, List.of(expectedStep));
         PolicyStepsRegistry registry = new PolicyStepsRegistry(null, null, null, NamedXContentRegistry.EMPTY, null, null);
         Step actualStep = registry.getStep(emptyMetadata(index), errorStepKey);
         assertThat(actualStep, equalTo(expectedStep));
@@ -143,7 +142,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         Client client = mock(Client.class);
         Mockito.when(client.settings()).thenReturn(Settings.EMPTY);
         LifecyclePolicy policy = LifecyclePolicyTests.randomTimeseriesLifecyclePolicy("policy");
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Collections.emptyMap(), 1, randomNonNegativeLong());
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Map.of(), 1, randomNonNegativeLong());
         IndexMetadata indexMetadata = IndexMetadata.builder("test")
             .settings(indexSettings(IndexVersion.current(), 1, 0).put(LifecycleSettings.LIFECYCLE_NAME, "policy").build())
             .build();
@@ -158,7 +157,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         Client client = mock(Client.class);
         Mockito.when(client.settings()).thenReturn(Settings.EMPTY);
         LifecyclePolicy policy = LifecyclePolicyTests.randomTimeseriesLifecyclePolicyWithAllPhases("policy");
-        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Collections.emptyMap(), 1, randomNonNegativeLong());
+        LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Map.of(), 1, randomNonNegativeLong());
         String phaseName = randomFrom(policy.getPhases().keySet());
         Phase phase = policy.getPhases().get(phaseName);
         PhaseExecutionInfo pei = new PhaseExecutionInfo(policy.getName(), phase, 1, randomNonNegativeLong());
@@ -193,7 +192,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
             headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
             headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
         }
-        Map<String, LifecyclePolicyMetadata> policyMap = Collections.singletonMap(
+        Map<String, LifecyclePolicyMetadata> policyMap = Map.of(
             newPolicy.getName(),
             new LifecyclePolicyMetadata(newPolicy, headers, randomNonNegativeLong(), randomNonNegativeLong())
         );
@@ -271,7 +270,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         assertThat(registry.getStepMap(), equalTo(registryStepMap));
 
         // remove policy
-        lifecycleMetadata = new IndexLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING);
+        lifecycleMetadata = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING);
         currentState = ClusterState.builder(currentState)
             .metadata(Metadata.builder(metadata).putCustom(IndexLifecycleMetadata.TYPE, lifecycleMetadata))
             .build();
@@ -291,7 +290,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
             headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
             headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
         }
-        Map<String, LifecyclePolicyMetadata> policyMap = Collections.singletonMap(
+        Map<String, LifecyclePolicyMetadata> policyMap = Map.of(
             newPolicy.getName(),
             new LifecyclePolicyMetadata(newPolicy, headers, randomNonNegativeLong(), randomNonNegativeLong())
         );
@@ -316,10 +315,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         // swap out policy
         newPolicy = LifecyclePolicyTests.randomTestLifecyclePolicy(policyName);
         lifecycleMetadata = new IndexLifecycleMetadata(
-            Collections.singletonMap(
-                policyName,
-                new LifecyclePolicyMetadata(newPolicy, Collections.emptyMap(), randomNonNegativeLong(), randomNonNegativeLong())
-            ),
+            Map.of(policyName, new LifecyclePolicyMetadata(newPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())),
             OperationMode.RUNNING
         );
         currentState = ClusterState.builder(currentState)
@@ -356,7 +352,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
             headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
             headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
         }
-        Map<String, LifecyclePolicyMetadata> policyMap = Collections.singletonMap(
+        Map<String, LifecyclePolicyMetadata> policyMap = Map.of(
             newPolicy.getName(),
             new LifecyclePolicyMetadata(newPolicy, headers, randomNonNegativeLong(), randomNonNegativeLong())
         );
@@ -411,7 +407,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
         assertThat(((ShrinkStep) gotStep).getNumberOfShards(), equalTo(1));
 
         // Update the policy with the new policy, but keep the phase the same
-        policyMap = Collections.singletonMap(
+        policyMap = Map.of(
             updatedPolicy.getName(),
             new LifecyclePolicyMetadata(updatedPolicy, headers, randomNonNegativeLong(), randomNonNegativeLong())
         );
@@ -457,7 +453,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
             .build();
 
         SortedMap<String, LifecyclePolicyMetadata> metas = new TreeMap<>();
-        metas.put("policy", new LifecyclePolicyMetadata(policy, Collections.emptyMap(), 1, randomNonNegativeLong()));
+        metas.put("policy", new LifecyclePolicyMetadata(policy, Map.of(), 1, randomNonNegativeLong()));
         IndexLifecycleMetadata meta = new IndexLifecycleMetadata(metas, OperationMode.RUNNING);
 
         PolicyStepsRegistry registry = new PolicyStepsRegistry(REGISTRY, client, null);

+ 1 - 2
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/StagnatingIndicesFinderTests.java

@@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.LongSupplier;
-import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
@@ -61,7 +60,7 @@ public class StagnatingIndicesFinderTests extends ESTestCase {
             assertEquals(expectedMaxTimeOnStep, maxTimeOnStep);
             assertEquals(expectedMaxRetriesPerStep, maxRetriesPerStep);
             return rc;
-        }).collect(Collectors.toList());
+        }).toList();
         // Per the evaluator, the timeSupplier _must_ be called only twice
         when(mockedTimeSupplier.getAsLong()).thenReturn(instant, instant);
 

+ 3 - 2
x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportStopILMActionTests.java

@@ -24,7 +24,8 @@ import org.elasticsearch.xpack.core.ilm.StopILMRequest;
 import org.elasticsearch.xpack.core.ilm.action.ILMActions;
 import org.mockito.ArgumentMatcher;
 
-import static java.util.Collections.emptyMap;
+import java.util.Map;
+
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
@@ -50,7 +51,7 @@ public class TransportStopILMActionTests extends ESTestCase {
             ILMActions.STOP.name(),
             "description",
             new TaskId(randomLong() + ":" + randomLong()),
-            emptyMap()
+            Map.of()
         );
         StopILMRequest request = new StopILMRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
         transportStopILMAction.masterOperation(task, request, ClusterState.EMPTY_STATE, ActionListener.noop());