@@ -102,10 +102,9 @@ public void testShardLock() throws Exception {
102102 } catch (ShardLockObtainFailedException ex ) {
103103 // expected
104104 }
105- for (Path path : env .indexPaths (index )) {
106- Files .createDirectories (path .resolve ("0" ));
107- Files .createDirectories (path .resolve ("1" ));
108- }
105+ Path path = env .indexPath (index );
106+ Files .createDirectories (path .resolve ("0" ));
107+ Files .createDirectories (path .resolve ("1" ));
109108 try {
110109 env .lockAllForIndex (index , idxSettings , "3" , randomIntBetween (0 , 10 ));
111110 fail ("shard 0 is locked" );
@@ -135,10 +134,9 @@ public void testAvailableIndexFolders() throws Exception {
135134 Set <String > actualPaths = new HashSet <>();
136135 for (int i = 0 ; i < numIndices ; i ++) {
137136 Index index = new Index ("foo" + i , "fooUUID" + i );
138- for (Path path : env .indexPaths (index )) {
139- Files .createDirectories (path .resolve (MetadataStateFormat .STATE_DIR_NAME ));
140- actualPaths .add (path .getFileName ().toString ());
141- }
137+ Path path = env .indexPath (index );
138+ Files .createDirectories (path .resolve (MetadataStateFormat .STATE_DIR_NAME ));
139+ actualPaths .add (path .getFileName ().toString ());
142140 }
143141
144142 assertThat (actualPaths , equalTo (env .availableIndexFolders ()));
@@ -153,12 +151,11 @@ public void testAvailableIndexFoldersWithExclusions() throws Exception {
153151 Set <String > actualPaths = new HashSet <>();
154152 for (int i = 0 ; i < numIndices ; i ++) {
155153 Index index = new Index ("foo" + i , "fooUUID" + i );
156- for (Path path : env .indexPaths (index )) {
157- Files .createDirectories (path .resolve (MetadataStateFormat .STATE_DIR_NAME ));
158- actualPaths .add (path .getFileName ().toString ());
159- }
154+ Path path = env .indexPath (index );
155+ Files .createDirectories (path .resolve (MetadataStateFormat .STATE_DIR_NAME ));
156+ actualPaths .add (path .getFileName ().toString ());
160157 if (randomBoolean ()) {
161- excludedPaths .add (env .indexPaths (index )[ 0 ] .getFileName ().toString ());
158+ excludedPaths .add (env .indexPath (index ).getFileName ().toString ());
162159 }
163160 }
164161
@@ -173,17 +170,15 @@ public void testResolveIndexFolders() throws Exception {
173170 Map <String , List <Path >> actualIndexDataPaths = new HashMap <>();
174171 for (int i = 0 ; i < numIndices ; i ++) {
175172 Index index = new Index ("foo" + i , "fooUUID" + i );
176- Path [] indexPaths = env .indexPaths (index );
177- for (Path path : indexPaths ) {
178- Files .createDirectories (path );
179- String fileName = path .getFileName ().toString ();
180- List <Path > paths = actualIndexDataPaths .get (fileName );
181- if (paths == null ) {
182- paths = new ArrayList <>();
183- }
184- paths .add (path );
185- actualIndexDataPaths .put (fileName , paths );
173+ Path path = env .indexPath (index );
174+ Files .createDirectories (path );
175+ String fileName = path .getFileName ().toString ();
176+ List <Path > paths = actualIndexDataPaths .get (fileName );
177+ if (paths == null ) {
178+ paths = new ArrayList <>();
186179 }
180+ paths .add (path );
181+ actualIndexDataPaths .put (fileName , paths );
187182 }
188183 for (Map .Entry <String , List <Path >> actualIndexDataPathEntry : actualIndexDataPaths .entrySet ()) {
189184 List <Path > actual = actualIndexDataPathEntry .getValue ();
@@ -200,20 +195,18 @@ public void testDeleteSafe() throws Exception {
200195 final ShardLock fooLock = env .shardLock (new ShardId (index , 0 ), "1" );
201196 assertEquals (new ShardId (index , 0 ), fooLock .getShardId ());
202197
203- for (Path path : env .indexPaths (index )) {
204- Files .createDirectories (path .resolve ("0" ));
205- Files .createDirectories (path .resolve ("1" ));
206- }
198+ Path path = env .indexPath (index );
199+ Files .createDirectories (path .resolve ("0" ));
200+ Files .createDirectories (path .resolve ("1" ));
207201
208202 expectThrows (ShardLockObtainFailedException .class ,
209203 () -> env .deleteShardDirectorySafe (new ShardId (index , 0 ), idxSettings , shardPaths -> {
210204 assert false : "should not be called " + shardPaths ;
211205 }));
212206
213- for (Path path : env .indexPaths (index )) {
214- assertTrue (Files .exists (path .resolve ("0" )));
215- assertTrue (Files .exists (path .resolve ("1" )));
216- }
207+ path = env .indexPath (index );
208+ assertTrue (Files .exists (path .resolve ("0" )));
209+ assertTrue (Files .exists (path .resolve ("1" )));
217210
218211 {
219212 SetOnce <Path []> listener = new SetOnce <>();
@@ -224,10 +217,9 @@ public void testDeleteSafe() throws Exception {
224217 }
225218 }
226219
227- for (Path path : env .indexPaths (index )) {
228- assertTrue (Files .exists (path .resolve ("0" )));
229- assertFalse (Files .exists (path .resolve ("1" )));
230- }
220+ path = env .indexPath (index );
221+ assertTrue (Files .exists (path .resolve ("0" )));
222+ assertFalse (Files .exists (path .resolve ("1" )));
231223
232224 expectThrows (ShardLockObtainFailedException .class ,
233225 () -> env .deleteIndexDirectorySafe (index , randomIntBetween (0 , 10 ), idxSettings , indexPaths -> {
@@ -236,9 +228,8 @@ public void testDeleteSafe() throws Exception {
236228
237229 fooLock .close ();
238230
239- for (Path path : env .indexPaths (index )) {
240- assertTrue (Files .exists (path ));
241- }
231+ path = env .indexPath (index );
232+ assertTrue (Files .exists (path ));
242233
243234 final AtomicReference <Throwable > threadException = new AtomicReference <>();
244235 final CountDownLatch latch = new CountDownLatch (1 );
@@ -274,12 +265,11 @@ protected void doRun() throws Exception {
274265
275266 final SetOnce <Path []> listener = new SetOnce <>();
276267 env .deleteIndexDirectorySafe (index , 5000 , idxSettings , listener ::set );
277- assertArrayEquals ( env . indexPaths ( index ), listener . get ( ));
268+ assertThat ( listener . get ()[ 0 ], equalTo ( env . indexPath ( index ) ));
278269 assertNull (threadException .get ());
279270
280- for (Path path : env .indexPaths (index )) {
281- assertFalse (Files .exists (path ));
282- }
271+ path = env .indexPath (index );
272+ assertFalse (Files .exists (path ));
283273 latch .await ();
284274 assertTrue ("LockedShards: " + env .lockedShards (), env .lockedShards ().isEmpty ());
285275 env .close ();
@@ -361,7 +351,7 @@ public void testCustomDataPaths() throws Exception {
361351 equalTo (dataPath .resolve ("indices/" + index .getUUID () + "/0" )));
362352
363353 assertThat ("index paths uses the regular template" ,
364- env .indexPaths (index )[ 0 ] , equalTo (dataPath .resolve ("indices/" + index .getUUID ())));
354+ env .indexPath (index ), equalTo (dataPath .resolve ("indices/" + index .getUUID ())));
365355
366356 assertThat (env .availableShardPaths (sid ), equalTo (env .availableShardPaths (sid )));
367357 assertThat (env .resolveCustomLocation ("/tmp/foo" , sid ).toAbsolutePath (),
@@ -372,7 +362,7 @@ public void testCustomDataPaths() throws Exception {
372362 equalTo (dataPath .resolve ("indices/" + index .getUUID () + "/0" )));
373363
374364 assertThat ("index paths uses the regular template" ,
375- env .indexPaths (index )[ 0 ] , equalTo (dataPath .resolve ("indices/" + index .getUUID ())));
365+ env .indexPath (index ), equalTo (dataPath .resolve ("indices/" + index .getUUID ())));
376366
377367 env .close ();
378368 }
@@ -415,10 +405,8 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException {
415405
416406 Path indexPath ;
417407 try (NodeEnvironment env = newNodeEnvironment (settings )) {
418- for (Path path : env .indexPaths (index )) {
419- Files .createDirectories (path .resolve (MetadataStateFormat .STATE_DIR_NAME ));
420- }
421- indexPath = env .indexPaths (index )[0 ];
408+ indexPath = env .indexPath (index );
409+ Files .createDirectories (indexPath .resolve (MetadataStateFormat .STATE_DIR_NAME ));
422410 }
423411
424412 verifyFailsOnMetadata (noDataNoMasterSettings , indexPath );
@@ -430,9 +418,7 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException {
430418
431419 // test that we can create data=false env with only meta information. Also create shard data for following asserts
432420 try (NodeEnvironment env = newNodeEnvironment (noDataSettings )) {
433- for (Path path : env .indexPaths (index )) {
434- Files .createDirectories (path .resolve (shardDataDirName ));
435- }
421+ Files .createDirectories (env .indexPath (index ).resolve (shardDataDirName ));
436422 }
437423
438424 verifyFailsOnShardData (noDataSettings , indexPath , shardDataDirName );
@@ -448,9 +434,7 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException {
448434
449435 // test that we can create data=true, master=true env. Also remove state dir to leave only shard data for following asserts
450436 try (NodeEnvironment env = newNodeEnvironment (settings )) {
451- for (Path path : env .indexPaths (index )) {
452- Files .delete (path .resolve (MetadataStateFormat .STATE_DIR_NAME ));
453- }
437+ Files .delete (env .indexPath (index ).resolve (MetadataStateFormat .STATE_DIR_NAME ));
454438 }
455439
456440 // assert that we fail on shard data even without the metadata dir.
0 commit comments