2626import org .elasticsearch .cluster .ClusterState ;
2727import org .elasticsearch .cluster .block .ClusterBlocks ;
2828import org .elasticsearch .cluster .metadata .IndexMetadata ;
29+ import org .elasticsearch .cluster .metadata .ProjectId ;
2930import org .elasticsearch .cluster .service .ClusterService ;
3031import org .elasticsearch .common .settings .ClusterSettings ;
3132import org .elasticsearch .common .settings .Settings ;
@@ -85,9 +86,11 @@ public class GeoIpDownloaderTests extends ESTestCase {
8586 private ThreadPool threadPool ;
8687 private MockClient client ;
8788 private GeoIpDownloader geoIpDownloader ;
89+ private ProjectId projectId ;
8890
8991 @ Before
9092 public void setup () throws IOException {
93+ projectId = randomProjectIdOrDefault ();
9194 httpClient = mock (HttpClient .class );
9295 when (httpClient .getBytes (anyString ())).thenReturn ("[]" .getBytes (StandardCharsets .UTF_8 ));
9396 clusterService = mock (ClusterService .class );
@@ -107,7 +110,7 @@ public void setup() throws IOException {
107110 )
108111 )
109112 );
110- ClusterState state = createClusterState (new PersistentTasksCustomMetadata (1L , Map .of ()));
113+ ClusterState state = createClusterState (projectId , new PersistentTasksCustomMetadata (1L , Map .of ()));
111114 when (clusterService .state ()).thenReturn (state );
112115 client = new MockClient (threadPool );
113116 geoIpDownloader = new GeoIpDownloader (
@@ -124,7 +127,8 @@ public void setup() throws IOException {
124127 Map .of (),
125128 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
126129 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
127- () -> true
130+ () -> true ,
131+ projectId
128132 ) {
129133 {
130134 GeoIpTaskParams geoIpTaskParams = mock (GeoIpTaskParams .class );
@@ -296,7 +300,8 @@ public void testProcessDatabaseNew() throws IOException {
296300 Map .of (),
297301 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
298302 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
299- () -> true
303+ () -> true ,
304+ randomProjectIdOrDefault ()
300305 ) {
301306 @ Override
302307 protected void updateTimestamp (String name , GeoIpTaskState .Metadata metadata ) {
@@ -347,7 +352,8 @@ public void testProcessDatabaseUpdate() throws IOException {
347352 Map .of (),
348353 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
349354 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
350- () -> true
355+ () -> true ,
356+ randomProjectIdOrDefault ()
351357 ) {
352358 @ Override
353359 protected void updateTimestamp (String name , GeoIpTaskState .Metadata metadata ) {
@@ -400,7 +406,8 @@ public void testProcessDatabaseSame() throws IOException {
400406 Map .of (),
401407 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
402408 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
403- () -> true
409+ () -> true ,
410+ randomProjectIdOrDefault ()
404411 ) {
405412 @ Override
406413 protected void updateTimestamp (String name , GeoIpTaskState .Metadata newMetadata ) {
@@ -450,7 +457,8 @@ public void testCleanDatabases() throws IOException {
450457 Map .of (),
451458 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
452459 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
453- () -> true
460+ () -> true ,
461+ randomProjectIdOrDefault ()
454462 ) {
455463 @ Override
456464 void updateDatabases () throws IOException {
@@ -495,7 +503,8 @@ public void testUpdateTaskState() {
495503 Map .of (),
496504 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
497505 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
498- () -> true
506+ () -> true ,
507+ randomProjectIdOrDefault ()
499508 ) {
500509 @ Override
501510 public void updatePersistentTaskState (PersistentTaskState state , ActionListener <PersistentTask <?>> listener ) {
@@ -525,7 +534,8 @@ public void testUpdateTaskStateError() {
525534 Map .of (),
526535 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
527536 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
528- () -> true
537+ () -> true ,
538+ randomProjectIdOrDefault ()
529539 ) {
530540 @ Override
531541 public void updatePersistentTaskState (PersistentTaskState state , ActionListener <PersistentTask <?>> listener ) {
@@ -566,7 +576,8 @@ public void testUpdateDatabases() throws IOException {
566576 Map .of (),
567577 () -> GeoIpDownloaderTaskExecutor .POLL_INTERVAL_SETTING .getDefault (Settings .EMPTY ),
568578 () -> GeoIpDownloaderTaskExecutor .EAGER_DOWNLOAD_SETTING .getDefault (Settings .EMPTY ),
569- atLeastOneGeoipProcessor ::get
579+ atLeastOneGeoipProcessor ::get ,
580+ projectId
570581 ) {
571582 @ Override
572583 void processDatabase (Map <String , Object > databaseInfo ) {
@@ -584,10 +595,11 @@ public void testUpdateDatabasesWriteBlock() throws IOException {
584595 /*
585596 * Here we make sure that we bail out before making an httpClient request if there is write block on the .geoip_databases index
586597 */
587- ClusterState state = createClusterState (new PersistentTasksCustomMetadata (1L , Map .of ()));
588- var geoIpIndex = state .getMetadata ().getProject ().getIndicesLookup ().get (GeoIpDownloader .DATABASES_INDEX ).getWriteIndex ().getName ();
598+ ClusterState state = createClusterState (projectId , new PersistentTasksCustomMetadata (1L , Map .of ()));
599+ var geoIpIndex = state .getMetadata ().getProject (projectId ).getIndicesLookup ().get (GeoIpDownloader .DATABASES_INDEX ).getWriteIndex ()
600+ .getName ();
589601 state = ClusterState .builder (state )
590- .blocks (new ClusterBlocks .Builder ().addIndexBlock (geoIpIndex , IndexMetadata .INDEX_READ_ONLY_ALLOW_DELETE_BLOCK ))
602+ .blocks (new ClusterBlocks .Builder ().addIndexBlock (projectId , geoIpIndex , IndexMetadata .INDEX_READ_ONLY_ALLOW_DELETE_BLOCK ))
591603 .build ();
592604 when (clusterService .state ()).thenReturn (state );
593605 geoIpDownloader .updateDatabases ();
@@ -599,7 +611,7 @@ public void testUpdateDatabasesIndexNotReady() throws IOException {
599611 * Here we make sure that we bail out before making an httpClient request if there are unallocated shards on the .geoip_databases
600612 * index
601613 */
602- ClusterState state = createClusterState (new PersistentTasksCustomMetadata (1L , Map .of ()), true );
614+ ClusterState state = createClusterState (projectId , new PersistentTasksCustomMetadata (1L , Map .of ()), true );
603615 when (clusterService .state ()).thenReturn (state );
604616 geoIpDownloader .updateDatabases ();
605617 verifyNoInteractions (httpClient );
0 commit comments