@@ -593,57 +593,6 @@ public void getConfigurationsFromIndex_SecurityIndexNotInitiallyReady() throws I
593593 assertThat (result .size (), is (CType .values ().size ()));
594594 }
595595
596- @ Test
597- public void afterIndexShardStarted_whenSecurityIndexUpdated () throws InterruptedException , TimeoutException {
598- Settings settings = Settings .builder ().build ();
599- IndexShard indexShard = mock (IndexShard .class );
600- ShardRouting shardRouting = mock (ShardRouting .class );
601- ShardId shardId = mock (ShardId .class );
602- Index index = mock (Index .class );
603- ClusterState mockClusterState = mock (ClusterState .class );
604- RestoreInProgress mockRestore = mock (RestoreInProgress .class );
605- RestoreInProgress .Entry mockEntry = mock (RestoreInProgress .Entry .class );
606- ExecutorService executorService = mock (ExecutorService .class );
607- ThreadPool threadPool = mock (ThreadPool .class );
608- ConfigurationRepository configurationRepository = spy (createConfigurationRepository (settings , threadPool ));
609-
610- // Setup mock behavior
611- when (indexShard .shardId ()).thenReturn (shardId );
612- when (shardId .getIndex ()).thenReturn (index );
613- when (index .getName ()).thenReturn (ConfigConstants .OPENDISTRO_SECURITY_DEFAULT_CONFIG_INDEX );
614- when (indexShard .routingEntry ()).thenReturn (shardRouting );
615- when (clusterService .state ()).thenReturn (mockClusterState );
616- when (mockClusterState .custom (RestoreInProgress .TYPE )).thenReturn (mockRestore );
617- when (threadPool .generic ()).thenReturn (executorService );
618-
619- // when replica shard updated
620- when (shardRouting .primary ()).thenReturn (false );
621- configurationRepository .afterIndexShardStarted (indexShard );
622- verify (executorService , never ()).execute (any ());
623- verify (configurationRepository , never ()).reloadConfiguration (any (), null );
624-
625- // when primary shard updated
626- doReturn (true ).when (configurationRepository ).reloadConfiguration (any (), null );
627- when (shardRouting .primary ()).thenReturn (true );
628- when (mockRestore .iterator ()).thenReturn (Collections .singletonList (mockEntry ).iterator ());
629- when (mockEntry .indices ()).thenReturn (Collections .singletonList (ConfigConstants .OPENDISTRO_SECURITY_DEFAULT_CONFIG_INDEX ));
630- ArgumentCaptor <Runnable > successRunnableCaptor = ArgumentCaptor .forClass (Runnable .class );
631- configurationRepository .afterIndexShardStarted (indexShard );
632- verify (executorService ).execute (successRunnableCaptor .capture ());
633- successRunnableCaptor .getValue ().run ();
634- verify (configurationRepository ).reloadConfiguration (CType .values (), null );
635-
636- // When there is error in checking if restored from snapshot
637- Mockito .reset (configurationRepository , executorService );
638- ArgumentCaptor <Runnable > errorRunnableCaptor = ArgumentCaptor .forClass (Runnable .class );
639- when (clusterService .state ()).thenThrow (new RuntimeException ("ClusterState exception" ));
640- when (shardRouting .primary ()).thenReturn (true );
641- configurationRepository .afterIndexShardStarted (indexShard );
642- verify (executorService ).execute (errorRunnableCaptor .capture ());
643- errorRunnableCaptor .getValue ().run ();
644- verify (configurationRepository , never ()).reloadConfiguration (any (), null );
645- }
646-
647596 void assertClusterState (final ArgumentCaptor <ClusterStateUpdateTask > clusterStateUpdateTaskCaptor ) throws Exception {
648597 final var initializedStateUpdate = clusterStateUpdateTaskCaptor .getValue ();
649598 assertThat (initializedStateUpdate .priority (), is (Priority .IMMEDIATE ));
0 commit comments