@@ -321,38 +321,31 @@ private RepositoryData addRandomSnapshotsToRepoData(RepositoryData repoData, boo
321
321
return repoData ;
322
322
}
323
323
324
+ private String getShardIdentifier (String indexUUID , String shardId ) {
325
+ return String .join ("/" , indexUUID , shardId );
326
+ }
327
+
324
328
public void testRemoteStoreShardCleanupTask () {
325
- // todo: move it to separate class and add more scenarios.
326
329
AtomicBoolean executed1 = new AtomicBoolean (false );
327
330
Runnable task1 = () -> executed1 .set (true );
328
331
String indexName = "test-idx" ;
329
332
String testIndexUUID = "test-idx-uuid" ;
330
333
ShardId shardId = new ShardId (new Index (indexName , testIndexUUID ), 0 );
331
334
332
- // Scenario 1: pending = empty, ongoing = false => executed
335
+ // just adding random shards in ongoing cleanups.
336
+ RemoteStoreShardCleanupTask .ongoingRemoteDirectoryCleanups .add (getShardIdentifier (testIndexUUID , "1" ));
337
+ RemoteStoreShardCleanupTask .ongoingRemoteDirectoryCleanups .add (getShardIdentifier (testIndexUUID , "2" ));
338
+
339
+ // Scenario 1: ongoing = false => executed
333
340
RemoteStoreShardCleanupTask remoteStoreShardCleanupTask = new RemoteStoreShardCleanupTask (task1 , testIndexUUID , shardId );
334
341
remoteStoreShardCleanupTask .run ();
335
342
assertTrue (executed1 .get ());
336
343
337
- // Scenario 2: pending = empty, ongoing = true => pending = currentTask
344
+ // Scenario 2: ongoing = true => currentTask skipped.
338
345
executed1 .set (false );
339
- String shardIdentifier = String .join ("/" , testIndexUUID , String .valueOf (shardId .id ()));
340
- RemoteStoreShardCleanupTask .ongoingRemoteDirectoryCleanups .add (shardIdentifier );
341
-
346
+ RemoteStoreShardCleanupTask .ongoingRemoteDirectoryCleanups .add (getShardIdentifier (testIndexUUID , "0" ));
342
347
remoteStoreShardCleanupTask = new RemoteStoreShardCleanupTask (task1 , testIndexUUID , shardId );
343
348
remoteStoreShardCleanupTask .run ();
344
349
assertFalse (executed1 .get ());
345
- assertSame (RemoteStoreShardCleanupTask .pendingRemoteDirectoryCleanups .get (shardIdentifier ), task1 );
346
-
347
- // Scenario3: pending = anotherTask, ongoing = true => pending = currentTask
348
- AtomicBoolean executed2 = new AtomicBoolean (false );
349
- Runnable task2 = () -> executed2 .set (true );
350
- RemoteStoreShardCleanupTask .pendingRemoteDirectoryCleanups .put (shardIdentifier , task1 );
351
- RemoteStoreShardCleanupTask .ongoingRemoteDirectoryCleanups .add (shardIdentifier );
352
-
353
- remoteStoreShardCleanupTask = new RemoteStoreShardCleanupTask (task2 , testIndexUUID , shardId );
354
- remoteStoreShardCleanupTask .run ();
355
- assertFalse (executed1 .get ());
356
- assertSame (RemoteStoreShardCleanupTask .pendingRemoteDirectoryCleanups .get (shardIdentifier ), task2 );
357
350
}
358
351
}
0 commit comments