Skip to content

Commit 190d4d9

Browse files
Merge pull request #99 from OneBusAway/release-please--branches--main--changes--next
release: 0.1.0-alpha.43
2 parents 3930d0f + c27b9cd commit 190d4d9

File tree

7 files changed

+80
-21
lines changed

7 files changed

+80
-21
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.1.0-alpha.42"
2+
".": "0.1.0-alpha.43"
33
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.1.0-alpha.43 (2025-11-27)
4+
5+
Full Changelog: [v0.1.0-alpha.42...v0.1.0-alpha.43](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.42...v0.1.0-alpha.43)
6+
7+
### Bug Fixes
8+
9+
* **client:** cancel okhttp call when future cancelled ([cdbf828](https://github.com/OneBusAway/java-sdk/commit/cdbf828a4f00dfff3c6cff8ef87cae984c297cb7))
10+
311
## 0.1.0-alpha.42 (2025-11-14)
412

513
Full Changelog: [v0.1.0-alpha.41...v0.1.0-alpha.42](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.41...v0.1.0-alpha.42)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<!-- x-release-please-start-version -->
44

5-
[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.42)
6-
[![javadoc](https://javadoc.io/badge2/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.42/javadoc.svg)](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.42)
5+
[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.43)
6+
[![javadoc](https://javadoc.io/badge2/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.43/javadoc.svg)](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.43)
77

88
<!-- x-release-please-end -->
99

@@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/).
1515

1616
<!-- x-release-please-start-version -->
1717

18-
The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). Javadocs are available on [javadoc.io](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.42).
18+
The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). Javadocs are available on [javadoc.io](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.43).
1919

2020
<!-- x-release-please-end -->
2121

@@ -26,7 +26,7 @@ The REST API documentation can be found on [developer.onebusaway.org](https://de
2626
### Gradle
2727

2828
```kotlin
29-
implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.42")
29+
implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.43")
3030
```
3131

3232
### Maven
@@ -35,7 +35,7 @@ implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.42")
3535
<dependency>
3636
<groupId>org.onebusaway</groupId>
3737
<artifactId>onebusaway-sdk-java</artifactId>
38-
<version>0.1.0-alpha.42</version>
38+
<version>0.1.0-alpha.43</version>
3939
</dependency>
4040
```
4141

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repositories {
88

99
allprojects {
1010
group = "org.onebusaway"
11-
version = "0.1.0-alpha.42" // x-release-please-version
11+
version = "0.1.0-alpha.43" // x-release-please-version
1212
}
1313

1414
subprojects {

onebusaway-sdk-java-client-okhttp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ dependencies {
1111

1212
testImplementation(kotlin("test"))
1313
testImplementation("org.assertj:assertj-core:3.25.3")
14+
testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2")
1415
}

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io.IOException
44
import java.io.InputStream
55
import java.net.Proxy
66
import java.time.Duration
7+
import java.util.concurrent.CancellationException
78
import java.util.concurrent.CompletableFuture
89
import javax.net.ssl.HostnameVerifier
910
import javax.net.ssl.SSLSocketFactory
@@ -30,8 +31,8 @@ import org.onebusaway.core.http.HttpRequestBody
3031
import org.onebusaway.core.http.HttpResponse
3132
import org.onebusaway.errors.OnebusawaySdkIoException
3233

33-
class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient) :
34-
HttpClient {
34+
class OkHttpClient
35+
private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient {
3536

3637
override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
3738
val call = newCall(request, requestOptions)
@@ -51,20 +52,25 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC
5152
): CompletableFuture<HttpResponse> {
5253
val future = CompletableFuture<HttpResponse>()
5354

54-
request.body?.run { future.whenComplete { _, _ -> close() } }
55-
56-
newCall(request, requestOptions)
57-
.enqueue(
58-
object : Callback {
59-
override fun onResponse(call: Call, response: Response) {
60-
future.complete(response.toResponse())
61-
}
55+
val call = newCall(request, requestOptions)
56+
call.enqueue(
57+
object : Callback {
58+
override fun onResponse(call: Call, response: Response) {
59+
future.complete(response.toResponse())
60+
}
6261

63-
override fun onFailure(call: Call, e: IOException) {
64-
future.completeExceptionally(OnebusawaySdkIoException("Request failed", e))
65-
}
62+
override fun onFailure(call: Call, e: IOException) {
63+
future.completeExceptionally(OnebusawaySdkIoException("Request failed", e))
6664
}
67-
)
65+
}
66+
)
67+
68+
future.whenComplete { _, e ->
69+
if (e is CancellationException) {
70+
call.cancel()
71+
}
72+
request.body?.close()
73+
}
6874

6975
return future
7076
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.onebusaway.client.okhttp
2+
3+
import com.github.tomakehurst.wiremock.client.WireMock.*
4+
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
5+
import com.github.tomakehurst.wiremock.junit5.WireMockTest
6+
import org.assertj.core.api.Assertions.assertThat
7+
import org.junit.jupiter.api.BeforeEach
8+
import org.junit.jupiter.api.Test
9+
import org.junit.jupiter.api.parallel.ResourceLock
10+
import org.onebusaway.core.http.HttpMethod
11+
import org.onebusaway.core.http.HttpRequest
12+
13+
@WireMockTest
14+
@ResourceLock("https://github.com/wiremock/wiremock/issues/169")
15+
internal class OkHttpClientTest {
16+
17+
private lateinit var baseUrl: String
18+
private lateinit var httpClient: OkHttpClient
19+
20+
@BeforeEach
21+
fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) {
22+
baseUrl = wmRuntimeInfo.httpBaseUrl
23+
httpClient = OkHttpClient.builder().build()
24+
}
25+
26+
@Test
27+
fun executeAsync_whenFutureCancelled_cancelsUnderlyingCall() {
28+
stubFor(post(urlPathEqualTo("/something")).willReturn(ok()))
29+
val responseFuture =
30+
httpClient.executeAsync(
31+
HttpRequest.builder()
32+
.method(HttpMethod.POST)
33+
.baseUrl(baseUrl)
34+
.addPathSegment("something")
35+
.build()
36+
)
37+
val call = httpClient.okHttpClient.dispatcher.runningCalls().single()
38+
39+
responseFuture.cancel(false)
40+
41+
// Should have cancelled the underlying call
42+
assertThat(call.isCanceled()).isTrue()
43+
}
44+
}

0 commit comments

Comments
 (0)