@@ -194,15 +194,17 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
194
194
// appear immediately so wait here.
195
195
assertBusy (() -> {
196
196
try {
197
- String aliasesResponse = EntityUtils . toString ( client (). performRequest ( new Request ( "GET" , "/_aliases" )). getEntity () );
198
- assertThat (aliasesResponse ,
199
- containsString ( " \" " + AnomalyDetectorsIndex . jobResultsAliasedName ( "custom-" + indexName ) + "\" :{\" aliases\" :{" ));
197
+ String aliasesResponse = getAliases ( );
198
+ assertThat (aliasesResponse , containsString ( " \" " + AnomalyDetectorsIndex . jobResultsAliasedName ( "custom-" + indexName )
199
+ + "\" :{\" aliases\" :{" ));
200
200
assertThat (aliasesResponse , containsString ("\" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId1 )
201
- + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId1 + "\" ,\" boost\" :1.0}}}}" ));
202
- assertThat (aliasesResponse , containsString ("\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId1 ) + "\" :{}" ));
201
+ + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId1 + "\" ,\" boost\" :1.0}}},\" is_hidden\" :true}" ));
202
+ assertThat (aliasesResponse , containsString ("\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId1 )
203
+ + "\" :{\" is_hidden\" :true}" ));
203
204
assertThat (aliasesResponse , containsString ("\" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId2 )
204
- + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId2 + "\" ,\" boost\" :1.0}}}}" ));
205
- assertThat (aliasesResponse , containsString ("\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId2 ) + "\" :{}" ));
205
+ + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId2 + "\" ,\" boost\" :1.0}}},\" is_hidden\" :true}" ));
206
+ assertThat (aliasesResponse , containsString ("\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId2 )
207
+ + "\" :{\" is_hidden\" :true}" ));
206
208
} catch (ResponseException e ) {
207
209
throw new AssertionError (e );
208
210
}
@@ -270,7 +272,7 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
270
272
client ().performRequest (new Request ("DELETE" , MachineLearning .BASE_PATH + "anomaly_detectors/" + jobId1 ));
271
273
272
274
// check that indices still exist, but no longer have job1 entries and aliases are gone
273
- responseAsString = EntityUtils . toString ( client (). performRequest ( new Request ( "GET" , "/_aliases" )). getEntity () );
275
+ responseAsString = getAliases ( );
274
276
assertThat (responseAsString , not (containsString (AnomalyDetectorsIndex .jobResultsAliasedName (jobId1 ))));
275
277
assertThat (responseAsString , containsString (AnomalyDetectorsIndex .jobResultsAliasedName (jobId2 ))); //job2 still exists
276
278
@@ -286,7 +288,7 @@ public void testCreateJobsWithIndexNameOption() throws Exception {
286
288
287
289
// Delete the second job and verify aliases are gone, and original concrete/custom index is gone
288
290
client ().performRequest (new Request ("DELETE" , MachineLearning .BASE_PATH + "anomaly_detectors/" + jobId2 ));
289
- responseAsString = EntityUtils . toString ( client (). performRequest ( new Request ( "GET" , "/_aliases" )). getEntity () );
291
+ responseAsString = getAliases ( );
290
292
assertThat (responseAsString , not (containsString (AnomalyDetectorsIndex .jobResultsAliasedName (jobId2 ))));
291
293
292
294
refreshAllIndices ();
@@ -626,6 +628,7 @@ public void testMultiIndexDelete() throws Exception {
626
628
extraIndex1 .setJsonEntity ("{\n " +
627
629
" \" aliases\" : {\n " +
628
630
" \" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId )+ "\" : {\n " +
631
+ " \" is_hidden\" : true,\n " +
629
632
" \" filter\" : {\n " +
630
633
" \" term\" : {\" " + Job .ID + "\" : \" " + jobId + "\" }\n " +
631
634
" }\n " +
@@ -637,6 +640,7 @@ public void testMultiIndexDelete() throws Exception {
637
640
extraIndex2 .setJsonEntity ("{\n " +
638
641
" \" aliases\" : {\n " +
639
642
" \" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId )+ "\" : {\n " +
643
+ " \" is_hidden\" : true,\n " +
640
644
" \" filter\" : {\n " +
641
645
" \" term\" : {\" " + Job .ID + "\" : \" " + jobId + "\" }\n " +
642
646
" }\n " +
@@ -784,6 +788,9 @@ public void testDelete_multipleRequest() throws Exception {
784
788
assertNull (recreationException .get ().getMessage (), recreationException .get ());
785
789
}
786
790
791
+ String expectedReadAliasString = "\" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId )
792
+ + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId + "\" ,\" boost\" :1.0}}},\" is_hidden\" :true}" ;
793
+ String expectedWriteAliasString = "\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId ) + "\" :{\" is_hidden\" :true}" ;
787
794
try {
788
795
// The idea of the code above is that the deletion is sufficiently time-consuming that
789
796
// all threads enter the deletion call before the first one exits it. Usually this happens,
@@ -796,9 +803,8 @@ public void testDelete_multipleRequest() throws Exception {
796
803
// if there's been a race between deletion and recreation these are what will be missing.
797
804
String aliases = getAliases ();
798
805
799
- assertThat (aliases , containsString ("\" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId )
800
- + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId + "\" ,\" boost\" :1.0}}}}" ));
801
- assertThat (aliases , containsString ("\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId ) + "\" :{}" ));
806
+ assertThat (aliases , containsString (expectedReadAliasString ));
807
+ assertThat (aliases , containsString (expectedWriteAliasString ));
802
808
803
809
804
810
} catch (ResponseException missingJobException ) {
@@ -807,9 +813,8 @@ public void testDelete_multipleRequest() throws Exception {
807
813
808
814
// The job aliases should be deleted
809
815
String aliases = getAliases ();
810
- assertThat (aliases , not (containsString ("\" " + AnomalyDetectorsIndex .jobResultsAliasedName (jobId )
811
- + "\" :{\" filter\" :{\" term\" :{\" job_id\" :{\" value\" :\" " + jobId + "\" ,\" boost\" :1.0}}}}" )));
812
- assertThat (aliases , not (containsString ("\" " + AnomalyDetectorsIndex .resultsWriteAlias (jobId ) + "\" :{}" )));
816
+ assertThat (aliases , not (containsString (expectedReadAliasString )));
817
+ assertThat (aliases , not (containsString (expectedWriteAliasString )));
813
818
}
814
819
815
820
assertEquals (numThreads , recreationGuard .get ());
0 commit comments