2020import org .elasticsearch .action .search .SearchRequest ;
2121import org .elasticsearch .action .search .SearchResponse ;
2222import org .elasticsearch .action .search .SearchType ;
23+ import org .elasticsearch .action .search .TransportSearchAction ;
2324import org .elasticsearch .action .support .IndicesOptions ;
2425import org .elasticsearch .action .support .PlainActionFuture ;
2526import org .elasticsearch .cluster .block .ClusterBlockException ;
@@ -92,17 +93,18 @@ String openReaders(TimeValue keepAlive, String... indices) {
9293 }
9394
9495 public void testCloseFreezeAndOpen () throws Exception {
95- createIndex ("index" , Settings .builder ().put ("index.number_of_shards" , 2 ).build ());
96- client ().prepareIndex ("index" ).setId ("1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
97- client ().prepareIndex ("index" ).setId ("2" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
98- client ().prepareIndex ("index" ).setId ("3" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
99- assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest ("index" )).actionGet ());
96+ String indexName = "index" ;
97+ createIndex (indexName , Settings .builder ().put ("index.number_of_shards" , 2 ).build ());
98+ client ().prepareIndex (indexName ).setId ("1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
99+ client ().prepareIndex (indexName ).setId ("2" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
100+ client ().prepareIndex (indexName ).setId ("3" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
101+ assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest (indexName )).actionGet ());
100102 expectThrows (
101103 ClusterBlockException .class ,
102- () -> client ().prepareIndex ("index" ).setId ("4" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ()
104+ () -> client ().prepareIndex (indexName ).setId ("4" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ()
103105 );
104106 IndicesService indexServices = getInstanceFromNode (IndicesService .class );
105- Index index = resolveIndex ("index" );
107+ Index index = resolveIndex (indexName );
106108 IndexService indexService = indexServices .indexServiceSafe (index );
107109 IndexShard shard = indexService .getShard (0 );
108110 Engine engine = IndexShardTestCase .getEngine (shard );
@@ -141,7 +143,7 @@ public void testCloseFreezeAndOpen() throws Exception {
141143 } while (searchResponse .getHits ().getHits ().length > 0 );
142144 client ().prepareClearScroll ().addScrollId (searchResponse .getScrollId ()).get ();
143145
144- String pitId = openReaders (TimeValue .timeValueMinutes (1 ), "index" );
146+ String pitId = openReaders (TimeValue .timeValueMinutes (1 ), indexName );
145147 try {
146148 for (int from = 0 ; from < 3 ; from ++) {
147149 searchResponse = client ().prepareSearch ()
@@ -160,6 +162,7 @@ public void testCloseFreezeAndOpen() throws Exception {
160162 assertFalse (((FrozenEngine ) engine ).isReaderOpen ());
161163 }
162164 }
165+ assertWarnings (TransportSearchAction .FROZEN_INDICES_DEPRECATION_MESSAGE .replace ("{}" , indexName ));
163166 } finally {
164167 client ().execute (ClosePointInTimeAction .INSTANCE , new ClosePointInTimeRequest (pitId )).get ();
165168 }
@@ -177,11 +180,12 @@ public void testSearchAndGetAPIsAreThrottled() throws IOException {
177180 .endObject ()
178181 .endObject ()
179182 .endObject ();
180- createIndex ("index" , Settings .builder ().put ("index.number_of_shards" , 2 ).build (), mapping );
183+ String indexName = "index" ;
184+ createIndex (indexName , Settings .builder ().put ("index.number_of_shards" , 2 ).build (), mapping );
181185 for (int i = 0 ; i < 10 ; i ++) {
182- client ().prepareIndex ("index" ).setId ("" + i ).setSource ("field" , "foo bar baz" ).get ();
186+ client ().prepareIndex (indexName ).setId ("" + i ).setSource ("field" , "foo bar baz" ).get ();
183187 }
184- assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest ("index" )).actionGet ());
188+ assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest (indexName )).actionGet ());
185189 int numRequests = randomIntBetween (20 , 50 );
186190 int numRefreshes = 0 ;
187191 for (int i = 0 ; i < numRequests ; i ++) {
@@ -190,29 +194,30 @@ public void testSearchAndGetAPIsAreThrottled() throws IOException {
190194 // searcher and rewrite the request outside of the search-throttle thread pool
191195 switch (randomFrom (Arrays .asList (0 , 1 , 2 ))) {
192196 case 0 :
193- client ().prepareGet ("index" , "" + randomIntBetween (0 , 9 )).get ();
197+ client ().prepareGet (indexName , "" + randomIntBetween (0 , 9 )).get ();
194198 break ;
195199 case 1 :
196- client ().prepareSearch ("index" )
200+ client ().prepareSearch (indexName )
197201 .setIndicesOptions (IndicesOptions .STRICT_EXPAND_OPEN_FORBID_CLOSED )
198202 .setSearchType (SearchType .QUERY_THEN_FETCH )
199203 .get ();
200204 // in total 4 refreshes 1x query & 1x fetch per shard (we have 2)
201205 numRefreshes += 3 ;
202206 break ;
203207 case 2 :
204- client ().prepareTermVectors ("index" , "" + randomIntBetween (0 , 9 )).get ();
208+ client ().prepareTermVectors (indexName , "" + randomIntBetween (0 , 9 )).get ();
205209 break ;
206210 case 3 :
207- client ().prepareExplain ("index" , "" + randomIntBetween (0 , 9 )).setQuery (new MatchAllQueryBuilder ()).get ();
211+ client ().prepareExplain (indexName , "" + randomIntBetween (0 , 9 )).setQuery (new MatchAllQueryBuilder ()).get ();
208212 break ;
209213
210214 default :
211215 assert false ;
212216 }
213217 }
214- IndicesStatsResponse index = client ().admin ().indices ().prepareStats ("index" ).clear ().setRefresh (true ).get ();
218+ IndicesStatsResponse index = client ().admin ().indices ().prepareStats (indexName ).clear ().setRefresh (true ).get ();
215219 assertEquals (numRefreshes , index .getTotal ().refresh .getTotal ());
220+ assertWarnings (TransportSearchAction .FROZEN_INDICES_DEPRECATION_MESSAGE .replace ("{}" , indexName ));
216221 }
217222
218223 public void testFreezeAndUnfreeze () {
@@ -298,26 +303,28 @@ public void testUnfreezeClosedIndices() {
298303 }
299304
300305 public void testFreezePattern () {
301- createIndex ("test-idx" , Settings .builder ().put ("index.number_of_shards" , 1 ).build ());
302- client ().prepareIndex ("test-idx" ).setId ("1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
306+ String indexName = "test-idx" ;
307+ createIndex (indexName , Settings .builder ().put ("index.number_of_shards" , 1 ).build ());
308+ client ().prepareIndex (indexName ).setId ("1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
303309 createIndex ("test-idx-1" , Settings .builder ().put ("index.number_of_shards" , 1 ).build ());
304310 client ().prepareIndex ("test-idx-1" ).setId ("1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
305- assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest ("test-idx" )).actionGet ());
306- assertIndexFrozen ("test-idx" );
311+ assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest (indexName )).actionGet ());
312+ assertIndexFrozen (indexName );
307313
308- IndicesStatsResponse index = client ().admin ().indices ().prepareStats ("test-idx" ).clear ().setRefresh (true ).get ();
314+ IndicesStatsResponse index = client ().admin ().indices ().prepareStats (indexName ).clear ().setRefresh (true ).get ();
309315 assertEquals (0 , index .getTotal ().refresh .getTotal ());
310- assertHitCount (client ().prepareSearch ("test-idx" ).setIndicesOptions (IndicesOptions .STRICT_EXPAND_OPEN_FORBID_CLOSED ).get (), 1 );
311- index = client ().admin ().indices ().prepareStats ("test-idx" ).clear ().setRefresh (true ).get ();
316+ assertHitCount (client ().prepareSearch (indexName ).setIndicesOptions (IndicesOptions .STRICT_EXPAND_OPEN_FORBID_CLOSED ).get (), 1 );
317+ index = client ().admin ().indices ().prepareStats (indexName ).clear ().setRefresh (true ).get ();
312318 assertEquals (1 , index .getTotal ().refresh .getTotal ());
313319
314320 assertAcked (client ().execute (FreezeIndexAction .INSTANCE , new FreezeRequest ("test*" )).actionGet ());
315- assertIndexFrozen ("test-idx" );
321+ assertIndexFrozen (indexName );
316322 assertIndexFrozen ("test-idx-1" );
317- index = client ().admin ().indices ().prepareStats ("test-idx" ).clear ().setRefresh (true ).get ();
323+ index = client ().admin ().indices ().prepareStats (indexName ).clear ().setRefresh (true ).get ();
318324 assertEquals (1 , index .getTotal ().refresh .getTotal ());
319325 index = client ().admin ().indices ().prepareStats ("test-idx-1" ).clear ().setRefresh (true ).get ();
320326 assertEquals (0 , index .getTotal ().refresh .getTotal ());
327+ assertWarnings (TransportSearchAction .FROZEN_INDICES_DEPRECATION_MESSAGE .replace ("{}" , indexName ));
321328 }
322329
323330 public void testCanMatch () throws IOException {
0 commit comments