File tree Expand file tree Collapse file tree
modern-treasury-java-core/src
main/kotlin/com/moderntreasury/api/core
test/kotlin/com/moderntreasury/api/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,7 +103,9 @@ private constructor(
103103 webhookKey = clientOptions.webhookKey
104104 }
105105
106- fun httpClient (httpClient : HttpClient ) = apply { this .httpClient = httpClient }
106+ fun httpClient (httpClient : HttpClient ) = apply {
107+ this .httpClient = PhantomReachableClosingHttpClient (httpClient)
108+ }
107109
108110 fun checkJacksonVersionCompatibility (checkJacksonVersionCompatibility : Boolean ) = apply {
109111 this .checkJacksonVersionCompatibility = checkJacksonVersionCompatibility
@@ -269,14 +271,12 @@ private constructor(
269271
270272 return ClientOptions (
271273 httpClient,
272- PhantomReachableClosingHttpClient (
273- RetryingHttpClient .builder()
274- .httpClient(httpClient)
275- .clock(clock)
276- .maxRetries(maxRetries)
277- .idempotencyHeader(" Idempotency-Key" )
278- .build()
279- ),
274+ RetryingHttpClient .builder()
275+ .httpClient(httpClient)
276+ .clock(clock)
277+ .maxRetries(maxRetries)
278+ .idempotencyHeader(" Idempotency-Key" )
279+ .build(),
280280 checkJacksonVersionCompatibility,
281281 jsonMapper,
282282 streamHandlerExecutor
Original file line number Diff line number Diff line change 1+ // File generated from our OpenAPI spec by Stainless.
2+
3+ package com.moderntreasury.api.core
4+
5+ import com.moderntreasury.api.core.http.HttpClient
6+ import org.assertj.core.api.Assertions.assertThat
7+ import org.junit.jupiter.api.Test
8+ import org.junit.jupiter.api.extension.ExtendWith
9+ import org.mockito.junit.jupiter.MockitoExtension
10+ import org.mockito.kotlin.mock
11+ import org.mockito.kotlin.never
12+ import org.mockito.kotlin.verify
13+
14+ @ExtendWith(MockitoExtension ::class )
15+ internal class ClientOptionsTest {
16+
17+ @Test
18+ fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient () {
19+ val httpClient = mock<HttpClient >()
20+ var clientOptions =
21+ ClientOptions .builder()
22+ .httpClient(httpClient)
23+ .apiKey(" My API Key" )
24+ .organizationId(" my-organization-ID" )
25+ .build()
26+ verify(httpClient, never()).close()
27+
28+ // Overwrite the `clientOptions` variable so that the original `ClientOptions` is GC'd.
29+ clientOptions = clientOptions.toBuilder().build()
30+ System .gc()
31+ Thread .sleep(100 )
32+
33+ verify(httpClient, never()).close()
34+ // This exists so that `clientOptions` is still reachable.
35+ assertThat(clientOptions).isEqualTo(clientOptions)
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments