9595import static org .hamcrest .Matchers .not ;
9696import static org .hamcrest .Matchers .notNullValue ;
9797import static org .hamcrest .Matchers .nullValue ;
98+ import static org .hamcrest .Matchers .oneOf ;
9899import static org .mockito .ArgumentMatchers .any ;
99100import static org .mockito .ArgumentMatchers .anyString ;
100101import static org .mockito .ArgumentMatchers .eq ;
@@ -315,10 +316,13 @@ public void testIndexHealthChangeListeners() {
315316 final AtomicReference <IndexState > previousState = new AtomicReference <>();
316317 final AtomicReference <IndexState > currentState = new AtomicReference <>();
317318 final TriConsumer <ProjectId , IndexState , IndexState > listener = (projId , prevState , state ) -> {
318- projectIdRef .set (projId );
319- previousState .set (prevState );
320- currentState .set (state );
321- listenerCalled .set (true );
319+ assertThat (projId , oneOf (ProjectId .DEFAULT , projectId ));
320+ if (projId .equals (projectId )) {
321+ projectIdRef .set (projId );
322+ previousState .set (prevState );
323+ currentState .set (state );
324+ listenerCalled .set (true );
325+ }
322326 };
323327 manager .addStateListener (listener );
324328
@@ -573,9 +577,11 @@ public void testIndexOutOfDateListeners() {
573577 manager .clusterChanged (new ClusterChangedEvent ("test-event" , clusterState , clusterState ));
574578 AtomicBoolean upToDateChanged = new AtomicBoolean ();
575579 manager .addStateListener ((projId , prev , current ) -> {
576- assertThat (projId , equalTo (projectId ));
577- listenerCalled .set (true );
578- upToDateChanged .set (prev .isIndexUpToDate != current .isIndexUpToDate );
580+ assertThat (projId , oneOf (ProjectId .DEFAULT , projectId ));
581+ if (projId .equals (projectId )) {
582+ listenerCalled .set (true );
583+ upToDateChanged .set (prev .isIndexUpToDate != current .isIndexUpToDate );
584+ }
579585 });
580586 assertThat (manager .getProject (projectId ).isIndexUpToDate (), is (true ));
581587
@@ -779,7 +785,7 @@ public void testGetRoleMappingsCleanupMigrationStatus() {
779785 metadataBuilder .put (builder .build ());
780786
781787 // No role mappings in cluster state yet
782- metadataBuilder .putCustom (RoleMappingMetadata .TYPE , new RoleMappingMetadata (Set .of ()));
788+ metadataBuilder .getProject ( projectId ). putCustom (RoleMappingMetadata .TYPE , new RoleMappingMetadata (Set .of ()));
783789
784790 assertThat (
785791 SecurityIndexManager .getRoleMappingsCleanupMigrationStatus (
@@ -803,10 +809,13 @@ public void testGetRoleMappingsCleanupMigrationStatus() {
803809 metadataBuilder .put (builder .build ());
804810
805811 // Role mappings in cluster state with fallback name
806- metadataBuilder .putCustom (
807- RoleMappingMetadata .TYPE ,
808- new RoleMappingMetadata (Set .of (new ExpressionRoleMapping (RoleMappingMetadata .FALLBACK_NAME , null , null , null , null , true )))
809- );
812+ metadataBuilder .getProject (projectId )
813+ .putCustom (
814+ RoleMappingMetadata .TYPE ,
815+ new RoleMappingMetadata (
816+ Set .of (new ExpressionRoleMapping (RoleMappingMetadata .FALLBACK_NAME , null , null , null , null , true ))
817+ )
818+ );
810819
811820 assertThat (
812821 SecurityIndexManager .getRoleMappingsCleanupMigrationStatus (
@@ -830,10 +839,11 @@ public void testGetRoleMappingsCleanupMigrationStatus() {
830839 metadataBuilder .put (builder .build ());
831840
832841 // Role mappings in cluster state
833- metadataBuilder .putCustom (
834- RoleMappingMetadata .TYPE ,
835- new RoleMappingMetadata (Set .of (new ExpressionRoleMapping ("role_mapping_1" , null , null , null , null , true )))
836- );
842+ metadataBuilder .getProject (projectId )
843+ .putCustom (
844+ RoleMappingMetadata .TYPE ,
845+ new RoleMappingMetadata (Set .of (new ExpressionRoleMapping ("role_mapping_1" , null , null , null , null , true )))
846+ );
837847
838848 assertThat (
839849 SecurityIndexManager .getRoleMappingsCleanupMigrationStatus (
@@ -1090,7 +1100,7 @@ private ClusterState.Builder createClusterState(
10901100 String mappings ,
10911101 Map <String , SystemIndexDescriptor .MappingsVersion > compatibilityVersions
10921102 ) {
1093- final Metadata metadata = Metadata .builder ()
1103+ final Metadata metadata = Metadata .builder (Metadata . EMPTY_METADATA )
10941104 .put (createProjectMetadata (projectId , indexName , aliasName , format , state , mappings ))
10951105 .build ();
10961106 final GlobalRoutingTable routingTable = GlobalRoutingTableTestHelper .buildRoutingTable (metadata , RoutingTable .Builder ::addAsNew );
@@ -1141,7 +1151,10 @@ public static ClusterState state(ProjectId projectId) {
11411151 .masterNodeId ("1" )
11421152 .localNodeId ("1" )
11431153 .build ();
1144- final Metadata metadata = Metadata .builder ().put (ProjectMetadata .builder (projectId )).generateClusterUuidIfNeeded ().build ();
1154+ final Metadata metadata = Metadata .builder (Metadata .EMPTY_METADATA )
1155+ .put (ProjectMetadata .builder (projectId ))
1156+ .generateClusterUuidIfNeeded ()
1157+ .build ();
11451158 return ClusterState .builder (CLUSTER_NAME ).nodes (nodes ).metadata (metadata ).build ();
11461159 }
11471160
0 commit comments