Skip to content

Commit b995e28

Browse files
committed
check 1st exception
1 parent 34cd066 commit b995e28

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Map;
4343
import java.util.concurrent.ExecutionException;
4444
import java.util.concurrent.atomic.AtomicInteger;
45+
import java.util.concurrent.atomic.AtomicReference;
4546
import java.util.stream.Collectors;
4647
import java.util.stream.IntStream;
4748

@@ -51,6 +52,7 @@
5152
import static org.hamcrest.Matchers.containsString;
5253
import static org.hamcrest.Matchers.equalTo;
5354
import static org.hamcrest.Matchers.hasKey;
55+
import static org.hamcrest.Matchers.instanceOf;
5456
import static org.hamcrest.Matchers.not;
5557
import static org.hamcrest.Matchers.sameInstance;
5658
import static org.mockito.ArgumentMatchers.any;
@@ -204,15 +206,19 @@ public void testClientsLifeCycleForSingleProject() throws Exception {
204206
}
205207
assertClientNotFound(projectId, clientName);
206208

209+
final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
207210
assertBusy(() -> {
208211
assertTrue(clientsHolder.isClosed());
209-
final var e = expectThrows(AlreadyClosedException.class, () -> {
210-
var client = clientsHolder.client(createRepositoryMetadata(randomFrom(clientName, anotherClientName)));
211-
client.decRef();
212-
});
213-
assertThat(e.getMessage(), containsString("Project [" + projectId + "] clients holder is closed"));
212+
try (var client = clientsHolder.client(createRepositoryMetadata(randomFrom(clientName, anotherClientName)))) {
213+
fail("client should be closed"); // the cache is still being cleared out
214+
} catch (Exception e) {
215+
exceptionRef.compareAndSet(null, e); // the first exception must be expected and is checked below
216+
}
214217
});
215218

219+
final var e = exceptionRef.get();
220+
assertThat(e, instanceOf(AlreadyClosedException.class));
221+
assertThat(e.getMessage(), containsString("Project [" + projectId + "] clients holder is closed"));
216222
}
217223

218224
public void testClientsForMultipleProjects() throws InterruptedException {

0 commit comments

Comments
 (0)