| 
42 | 42 | import java.util.Map;  | 
43 | 43 | import java.util.concurrent.ExecutionException;  | 
44 | 44 | import java.util.concurrent.atomic.AtomicInteger;  | 
 | 45 | +import java.util.concurrent.atomic.AtomicReference;  | 
45 | 46 | import java.util.stream.Collectors;  | 
46 | 47 | import java.util.stream.IntStream;  | 
47 | 48 | 
 
  | 
 | 
51 | 52 | import static org.hamcrest.Matchers.containsString;  | 
52 | 53 | import static org.hamcrest.Matchers.equalTo;  | 
53 | 54 | import static org.hamcrest.Matchers.hasKey;  | 
 | 55 | +import static org.hamcrest.Matchers.instanceOf;  | 
54 | 56 | import static org.hamcrest.Matchers.not;  | 
55 | 57 | import static org.hamcrest.Matchers.sameInstance;  | 
56 | 58 | import static org.mockito.ArgumentMatchers.any;  | 
@@ -204,15 +206,19 @@ public void testClientsLifeCycleForSingleProject() throws Exception {  | 
204 | 206 |         }  | 
205 | 207 |         assertClientNotFound(projectId, clientName);  | 
206 | 208 | 
 
  | 
 | 209 | +        final AtomicReference<Exception> exceptionRef = new AtomicReference<>();  | 
207 | 210 |         assertBusy(() -> {  | 
208 | 211 |             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 | +            }  | 
214 | 217 |         });  | 
215 | 218 | 
 
  | 
 | 219 | +        final var e = exceptionRef.get();  | 
 | 220 | +        assertThat(e, instanceOf(AlreadyClosedException.class));  | 
 | 221 | +        assertThat(e.getMessage(), containsString("Project [" + projectId + "] clients holder is closed"));  | 
216 | 222 |     }  | 
217 | 223 | 
 
  | 
218 | 224 |     public void testClientsForMultipleProjects() throws InterruptedException {  | 
 | 
0 commit comments