Skip to content

Commit 922327b

Browse files
committed
more assertion
1 parent 39fa184 commit 922327b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3ClientsManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ final AmazonS3Reference client(RepositoryMetadata repositoryMetadata) {
290290
}
291291
if (closed.get()) {
292292
// Not adding a new client once the manager is closed since there won't be anything to close it
293-
throw new IllegalStateException("clients holder is closed");
293+
throw new IllegalStateException("Project [" + projectId() + "] clients holder is closed");
294294
}
295295
// The close() method maybe called after we checked it, it is ok since we are already inside the synchronized block.
296296
// The clearCache() will clear the newly added client.

modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3ClientsManagerTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testDoesNotCreateClientWhenSecretsAreNotConfigured() {
152152
assertThat(getClientsHoldersExcludeDefaultProject(), anEmptyMap());
153153
}
154154

155-
public void testClientsLifeCycleForSingleProject() {
155+
public void testClientsLifeCycleForSingleProject() throws Exception {
156156
final ProjectId projectId = randomUniqueProjectId();
157157
final String clientName = randomFrom(clientNames);
158158
final String anotherClientName = randomValueOtherThan(clientName, () -> randomFrom(clientNames));
@@ -197,13 +197,22 @@ public void testClientsLifeCycleForSingleProject() {
197197
antherClient.decRef();
198198
}
199199

200+
final var clientsHolder = s3ClientsManager.getClientsHolders().get(projectId);
201+
200202
// Remove project secrets
201203
if (randomBoolean()) {
202204
updateProjectInClusterState(projectId, Map.of());
203205
} else {
204206
removeProjectFromClusterState(projectId);
205207
}
206208
assertClientNotFound(projectId, clientName);
209+
210+
assertBusy(() -> assertTrue(clientsHolder.isClosed()));
211+
final var e = expectThrows(
212+
IllegalStateException.class,
213+
() -> clientsHolder.client(createRepositoryMetadata(randomFrom(clientName, anotherClientName)))
214+
);
215+
assertThat(e.getMessage(), containsString("Project [" + projectId + "] clients holder is closed"));
207216
}
208217

209218
public void testClientsForMultipleProjects() throws InterruptedException {

0 commit comments

Comments
 (0)