|
1 | 1 | package com.sap.cloud.sdk.cloudplatform.connectivity; |
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatCode; |
4 | 5 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
5 | 6 |
|
6 | 7 | import java.util.ArrayList; |
|
12 | 13 | import java.util.concurrent.TimeUnit; |
13 | 14 | import java.util.concurrent.atomic.AtomicLong; |
14 | 15 |
|
| 16 | +import lombok.SneakyThrows; |
15 | 17 | import org.apache.http.client.HttpClient; |
16 | 18 | import org.apache.http.client.methods.HttpGet; |
17 | 19 | import org.apache.http.client.methods.HttpUriRequest; |
@@ -357,6 +359,37 @@ void testInvalidatePrincipalCacheEntriesWithUserTokenExchangeDestination() |
357 | 359 | assertThat(unclearedClientWithoutDestination).isSameAs(sut.tryGetHttpClient(FACTORY).get()); |
358 | 360 | } |
359 | 361 |
|
| 362 | + @SneakyThrows |
| 363 | + @Test |
| 364 | + void testHttpClientWrapperWithDestinationIsCalledWhenDestinationIsProvided() |
| 365 | + { |
| 366 | + final DefaultHttpDestination destination1 = DefaultHttpDestination.builder("http://foo.com").build(); |
| 367 | + final HttpClient client1 = sut.tryGetHttpClient(destination1, FACTORY).get(); |
| 368 | + assertThat(((HttpClientWrapper) client1).getDestination()).isSameAs(destination1); |
| 369 | + |
| 370 | + final DefaultHttpDestination destination2 = DefaultHttpDestination.builder("http://foo.com").build(); |
| 371 | + final HttpClient client2 = sut.tryGetHttpClient(destination2, FACTORY).get(); |
| 372 | + assertThat(((HttpClientWrapper) client2).getDestination()).isSameAs(destination2); |
| 373 | + |
| 374 | + // Verify the destinations are equal but not the same reference |
| 375 | + assertThat(destination1).isEqualTo(destination2); |
| 376 | + assertThat(destination1).isNotSameAs(destination2); |
| 377 | + |
| 378 | + // Http clients are distinct instances, since the cache key contains the destination reference and not its content |
| 379 | + assertThat(client1).isNotSameAs(client2); |
| 380 | + |
| 381 | + // When using the exact same destination object, the same http-client wrapper should be returned |
| 382 | + final HttpClient client1Again = sut.tryGetHttpClient(destination1, FACTORY).get(); |
| 383 | + assertThat(client1Again).isSameAs(client1); |
| 384 | + assertThat(((HttpClientWrapper) client1Again).getDestination()).isSameAs(destination1); |
| 385 | + |
| 386 | + // simulate garbage collection |
| 387 | + ((HttpClientWrapper) client1).close(); |
| 388 | + |
| 389 | + // since client1 inherited client2 connection manager, client2 is shut down as well |
| 390 | + assertThatCode(() -> client2.execute(new HttpGet())).hasMessage("Connection pool shut down"); |
| 391 | + } |
| 392 | + |
360 | 393 | @Test |
361 | 394 | void testPrincipalPropagationIsPrincipalIsolated() |
362 | 395 | { |
|
0 commit comments