4242import java .util .HashMap ;
4343import java .util .List ;
4444import java .util .Map ;
45- import java .util .concurrent .CountDownLatch ;
4645import java .util .concurrent .ExecutionException ;
4746import java .util .concurrent .atomic .AtomicInteger ;
48- import java .util .concurrent .atomic .AtomicReference ;
4947import java .util .stream .Collectors ;
5048import java .util .stream .IntStream ;
5149
@@ -72,13 +70,11 @@ public class S3ClientsManagerTests extends ESTestCase {
7270 private ClusterService clusterService ;
7371 private S3Service s3Service ;
7472 private S3ClientsManager s3ClientsManager ;
75- private final AtomicReference <CountDownLatch > clientRefsCloseLatchRef = new AtomicReference <>();
7673
7774 @ Override
7875 public void setUp () throws Exception {
7976 super .setUp ();
8077 s3SecretsIdGenerators = ConcurrentCollections .newConcurrentMap ();
81- clientRefsCloseLatchRef .set (null );
8278 clientNames = IntStream .range (0 , between (2 , 5 )).mapToObj (i -> randomIdentifier () + "_" + i ).toList ();
8379
8480 final Settings .Builder builder = Settings .builder ();
@@ -296,6 +292,25 @@ public void testClusterAndProjectClients() {
296292 assertFalse (projectClient .hasReferences ());
297293 }
298294
295+ public void testClientsHolderAfterManagerClosed () {
296+ final ProjectId projectId = randomUniqueProjectId ();
297+ final String clientName = randomFrom (clientNames );
298+
299+ s3ClientsManager .close ();
300+ // New holder can be added after the manager is closed, but no actual client can be created
301+ updateProjectInClusterState (projectId , newProjectClientsSecrets (projectId , clientName ));
302+ try (var clientsHolder = s3ClientsManager .getClientsHolders ().get (projectId )) {
303+ assertNotNull (clientsHolder );
304+ assertFalse (clientsHolder .isClosed ());
305+
306+ final IllegalStateException e = expectThrows (
307+ IllegalStateException .class ,
308+ () -> s3ClientsManager .client (projectId , createRepositoryMetadata (clientName ))
309+ );
310+ assertThat (e .getMessage (), containsString ("s3 clients manager is closed" ));
311+ }
312+ }
313+
299314 public void testProjectClientsDisabled () {
300315 final var clusterService = spy (this .clusterService );
301316 final S3Service s3ServiceWithNoProjectSupport = new S3Service (
0 commit comments