Skip to content

Commit 60b086d

Browse files
committed
Add current behavior test
1 parent 5b1c7fe commit 60b086d

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

cloudplatform/connectivity-apache-httpclient4/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DefaultHttpClientCacheTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sap.cloud.sdk.cloudplatform.connectivity;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatCode;
45
import static org.assertj.core.api.Assertions.assertThatThrownBy;
56

67
import java.util.ArrayList;
@@ -12,6 +13,7 @@
1213
import java.util.concurrent.TimeUnit;
1314
import java.util.concurrent.atomic.AtomicLong;
1415

16+
import lombok.SneakyThrows;
1517
import org.apache.http.client.HttpClient;
1618
import org.apache.http.client.methods.HttpGet;
1719
import org.apache.http.client.methods.HttpUriRequest;
@@ -357,6 +359,37 @@ void testInvalidatePrincipalCacheEntriesWithUserTokenExchangeDestination()
357359
assertThat(unclearedClientWithoutDestination).isSameAs(sut.tryGetHttpClient(FACTORY).get());
358360
}
359361

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+
360393
@Test
361394
void testPrincipalPropagationIsPrincipalIsolated()
362395
{

0 commit comments

Comments
 (0)