From ecf32018d966ad54d6ec26b479acf0ebe7fc2fb3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:01:59 +0000 Subject: [PATCH 1/2] fix(client): cancel okhttp call when future cancelled --- increase-java-client-okhttp/build.gradle.kts | 1 + .../api/client/okhttp/OkHttpClient.kt | 34 ++++++++------ .../api/client/okhttp/OkHttpClientTest.kt | 44 +++++++++++++++++++ 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 increase-java-client-okhttp/src/test/kotlin/com/increase/api/client/okhttp/OkHttpClientTest.kt diff --git a/increase-java-client-okhttp/build.gradle.kts b/increase-java-client-okhttp/build.gradle.kts index 5ce7b3e69..1b2dc95d0 100644 --- a/increase-java-client-okhttp/build.gradle.kts +++ b/increase-java-client-okhttp/build.gradle.kts @@ -11,4 +11,5 @@ dependencies { testImplementation(kotlin("test")) testImplementation("org.assertj:assertj-core:3.25.3") + testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2") } diff --git a/increase-java-client-okhttp/src/main/kotlin/com/increase/api/client/okhttp/OkHttpClient.kt b/increase-java-client-okhttp/src/main/kotlin/com/increase/api/client/okhttp/OkHttpClient.kt index fa78a9f40..29560cac0 100644 --- a/increase-java-client-okhttp/src/main/kotlin/com/increase/api/client/okhttp/OkHttpClient.kt +++ b/increase-java-client-okhttp/src/main/kotlin/com/increase/api/client/okhttp/OkHttpClient.kt @@ -13,6 +13,7 @@ import java.io.IOException import java.io.InputStream import java.net.Proxy import java.time.Duration +import java.util.concurrent.CancellationException import java.util.concurrent.CompletableFuture import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory @@ -29,8 +30,8 @@ import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink -class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient) : - HttpClient { +class OkHttpClient +private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient { override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse { val call = newCall(request, requestOptions) @@ -50,20 +51,25 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC ): CompletableFuture { val future = CompletableFuture() - request.body?.run { future.whenComplete { _, _ -> close() } } - - newCall(request, requestOptions) - .enqueue( - object : Callback { - override fun onResponse(call: Call, response: Response) { - future.complete(response.toResponse()) - } + val call = newCall(request, requestOptions) + call.enqueue( + object : Callback { + override fun onResponse(call: Call, response: Response) { + future.complete(response.toResponse()) + } - override fun onFailure(call: Call, e: IOException) { - future.completeExceptionally(IncreaseIoException("Request failed", e)) - } + override fun onFailure(call: Call, e: IOException) { + future.completeExceptionally(IncreaseIoException("Request failed", e)) } - ) + } + ) + + future.whenComplete { _, e -> + if (e is CancellationException) { + call.cancel() + } + request.body?.close() + } return future } diff --git a/increase-java-client-okhttp/src/test/kotlin/com/increase/api/client/okhttp/OkHttpClientTest.kt b/increase-java-client-okhttp/src/test/kotlin/com/increase/api/client/okhttp/OkHttpClientTest.kt new file mode 100644 index 000000000..1fdbab5c8 --- /dev/null +++ b/increase-java-client-okhttp/src/test/kotlin/com/increase/api/client/okhttp/OkHttpClientTest.kt @@ -0,0 +1,44 @@ +package com.increase.api.client.okhttp + +import com.github.tomakehurst.wiremock.client.WireMock.* +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import com.increase.api.core.http.HttpMethod +import com.increase.api.core.http.HttpRequest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.ResourceLock + +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class OkHttpClientTest { + + private lateinit var baseUrl: String + private lateinit var httpClient: OkHttpClient + + @BeforeEach + fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) { + baseUrl = wmRuntimeInfo.httpBaseUrl + httpClient = OkHttpClient.builder().build() + } + + @Test + fun executeAsync_whenFutureCancelled_cancelsUnderlyingCall() { + stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) + val responseFuture = + httpClient.executeAsync( + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build() + ) + val call = httpClient.okHttpClient.dispatcher.runningCalls().single() + + responseFuture.cancel(false) + + // Should have cancelled the underlying call + assertThat(call.isCanceled()).isTrue() + } +} From 851675903b776023606a9a3cf1bedacfd8545b42 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:02:25 +0000 Subject: [PATCH 2/2] release: 0.370.1 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ README.md | 10 +++++----- build.gradle.kts | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 16b219fd3..f6742392e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.370.0" + ".": "0.370.1" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fb5a34338..39a984b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.370.1 (2025-11-26) + +Full Changelog: [v0.370.0...v0.370.1](https://github.com/Increase/increase-java/compare/v0.370.0...v0.370.1) + +### Bug Fixes + +* **client:** cancel okhttp call when future cancelled ([ecf3201](https://github.com/Increase/increase-java/commit/ecf32018d966ad54d6ec26b479acf0ebe7fc2fb3)) + ## 0.370.0 (2025-11-26) Full Changelog: [v0.369.0...v0.370.0](https://github.com/Increase/increase-java/compare/v0.369.0...v0.370.0) diff --git a/README.md b/README.md index 932bcb81d..4d87d09b3 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.increase.api/increase-java)](https://central.sonatype.com/artifact/com.increase.api/increase-java/0.370.0) -[![javadoc](https://javadoc.io/badge2/com.increase.api/increase-java/0.370.0/javadoc.svg)](https://javadoc.io/doc/com.increase.api/increase-java/0.370.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.increase.api/increase-java)](https://central.sonatype.com/artifact/com.increase.api/increase-java/0.370.1) +[![javadoc](https://javadoc.io/badge2/com.increase.api/increase-java/0.370.1/javadoc.svg)](https://javadoc.io/doc/com.increase.api/increase-java/0.370.1) @@ -13,7 +13,7 @@ The Increase Java SDK is similar to the Increase Kotlin SDK but with minor diffe -The REST API documentation can be found on [increase.com](https://increase.com/documentation). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.increase.api/increase-java/0.370.0). +The REST API documentation can be found on [increase.com](https://increase.com/documentation). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.increase.api/increase-java/0.370.1). @@ -24,7 +24,7 @@ The REST API documentation can be found on [increase.com](https://increase.com/d ### Gradle ```kotlin -implementation("com.increase.api:increase-java:0.370.0") +implementation("com.increase.api:increase-java:0.370.1") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.increase.api:increase-java:0.370.0") com.increase.api increase-java - 0.370.0 + 0.370.1 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 811961cea..053ce6f17 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.increase.api" - version = "0.370.0" // x-release-please-version + version = "0.370.1" // x-release-please-version } subprojects {