File tree Expand file tree Collapse file tree 2 files changed +41
-8
lines changed
main/kotlin/com/openlayer/api/core
test/kotlin/com/openlayer/api/core Expand file tree Collapse file tree 2 files changed +41
-8
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,9 @@ private constructor(
87
87
apiKey = clientOptions.apiKey
88
88
}
89
89
90
- fun httpClient (httpClient : HttpClient ) = apply { this .httpClient = httpClient }
90
+ fun httpClient (httpClient : HttpClient ) = apply {
91
+ this .httpClient = PhantomReachableClosingHttpClient (httpClient)
92
+ }
91
93
92
94
fun checkJacksonVersionCompatibility (checkJacksonVersionCompatibility : Boolean ) = apply {
93
95
this .checkJacksonVersionCompatibility = checkJacksonVersionCompatibility
@@ -234,13 +236,11 @@ private constructor(
234
236
235
237
return ClientOptions (
236
238
httpClient,
237
- PhantomReachableClosingHttpClient (
238
- RetryingHttpClient .builder()
239
- .httpClient(httpClient)
240
- .clock(clock)
241
- .maxRetries(maxRetries)
242
- .build()
243
- ),
239
+ RetryingHttpClient .builder()
240
+ .httpClient(httpClient)
241
+ .clock(clock)
242
+ .maxRetries(maxRetries)
243
+ .build(),
244
244
checkJacksonVersionCompatibility,
245
245
jsonMapper,
246
246
clock,
Original file line number Diff line number Diff line change
1
+ // File generated from our OpenAPI spec by Stainless.
2
+
3
+ package com.openlayer.api.core
4
+
5
+ import com.openlayer.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().httpClient(httpClient).apiKey(" My API Key" ).build()
22
+ verify(httpClient, never()).close()
23
+
24
+ // Overwrite the `clientOptions` variable so that the original `ClientOptions` is GC'd.
25
+ clientOptions = clientOptions.toBuilder().build()
26
+ System .gc()
27
+ Thread .sleep(100 )
28
+
29
+ verify(httpClient, never()).close()
30
+ // This exists so that `clientOptions` is still reachable.
31
+ assertThat(clientOptions).isEqualTo(clientOptions)
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments