|
14 | 14 | import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
|
15 | 15 | import software.amazon.awssdk.regions.Region;
|
16 | 16 |
|
| 17 | +import org.apache.lucene.store.AlreadyClosedException; |
17 | 18 | import org.elasticsearch.cluster.ClusterState;
|
18 | 19 | import org.elasticsearch.cluster.metadata.Metadata;
|
19 | 20 | import org.elasticsearch.cluster.metadata.ProjectId;
|
|
41 | 42 | import java.util.Map;
|
42 | 43 | import java.util.concurrent.ExecutionException;
|
43 | 44 | import java.util.concurrent.atomic.AtomicInteger;
|
| 45 | +import java.util.concurrent.atomic.AtomicReference; |
44 | 46 | import java.util.stream.Collectors;
|
45 | 47 | import java.util.stream.IntStream;
|
46 | 48 |
|
|
50 | 52 | import static org.hamcrest.Matchers.containsString;
|
51 | 53 | import static org.hamcrest.Matchers.equalTo;
|
52 | 54 | import static org.hamcrest.Matchers.hasKey;
|
| 55 | +import static org.hamcrest.Matchers.instanceOf; |
53 | 56 | import static org.hamcrest.Matchers.not;
|
54 | 57 | import static org.hamcrest.Matchers.sameInstance;
|
55 | 58 | import static org.mockito.ArgumentMatchers.any;
|
@@ -203,11 +206,18 @@ public void testClientsLifeCycleForSingleProject() throws Exception {
|
203 | 206 | }
|
204 | 207 | assertClientNotFound(projectId, clientName);
|
205 | 208 |
|
206 |
| - assertBusy(() -> assertTrue(clientsHolder.isClosed())); |
207 |
| - final var e = expectThrows( |
208 |
| - IllegalStateException.class, |
209 |
| - () -> clientsHolder.client(createRepositoryMetadata(randomFrom(clientName, anotherClientName))) |
210 |
| - ); |
| 209 | + final AtomicReference<Exception> exceptionRef = new AtomicReference<>(); |
| 210 | + assertBusy(() -> { |
| 211 | + assertTrue(clientsHolder.isClosed()); |
| 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 | + } |
| 217 | + }); |
| 218 | + |
| 219 | + final var e = exceptionRef.get(); |
| 220 | + assertThat(e, instanceOf(AlreadyClosedException.class)); |
211 | 221 | assertThat(e.getMessage(), containsString("Project [" + projectId + "] clients holder is closed"));
|
212 | 222 | }
|
213 | 223 |
|
@@ -306,8 +316,8 @@ public void testClientsHolderAfterManagerClosed() {
|
306 | 316 | assertNotNull(clientsHolder);
|
307 | 317 | assertFalse(clientsHolder.isClosed());
|
308 | 318 |
|
309 |
| - final IllegalStateException e = expectThrows( |
310 |
| - IllegalStateException.class, |
| 319 | + final var e = expectThrows( |
| 320 | + AlreadyClosedException.class, |
311 | 321 | () -> s3ClientsManager.client(projectId, createRepositoryMetadata(clientName))
|
312 | 322 | );
|
313 | 323 | assertThat(e.getMessage(), containsString("s3 clients manager is closed"));
|
|
0 commit comments