Skip to content

Commit 3655f68

Browse files
RUM-9511: Pr fixes
1 parent cbec8ea commit 3655f68

File tree

5 files changed

+49
-62
lines changed

5 files changed

+49
-62
lines changed

gradle/libs.versions.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ timber = "5.0.1"
9292
coroutines = "1.4.2"
9393

9494
# Local Server
95-
ktorClient = "2.3.13"
96-
ktor = "1.6.8"
95+
ktor = "2.3.13"
9796
ktorServer = "3.0.0-rc-1"
9897

9998
# Otel
@@ -251,11 +250,11 @@ ktorServerNetty = { module = "io.ktor:ktor-server-netty", version.ref = "ktorSer
251250
ktorServerSSE = { module = "io.ktor:ktor-server-sse", version.ref = "ktorServer" }
252251

253252
# ktor client
254-
ktorClientCore = { module = "io.ktor:ktor-client-core", version.ref = "ktorClient" }
255-
ktorClientOkHttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClient" }
256-
ktorContentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktorClient" }
257-
ktorSerializationKotlinxJson = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClient" }
258-
ktorClientMock = { module = "io.ktor:ktor-client-mock", version.ref = "ktorClient" }
253+
ktorClientCore = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
254+
ktorClientOkHttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
255+
ktorContentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
256+
ktorSerializationKotlinxJson = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
257+
ktorClientMock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
259258

260259
# Otel
261260
jctools = { module = "org.jctools:jctools-core", version.ref = "jctools" }

sample/benchmark/src/main/java/com/datadog/benchmark/sample/BenchmarkConfigHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ import javax.inject.Singleton
1212

1313
@Singleton
1414
internal class BenchmarkConfigHolder @Inject constructor() {
15-
var config: BenchmarkConfig? = null
15+
lateinit var config: BenchmarkConfig
1616
}

sample/benchmark/src/main/java/com/datadog/benchmark/sample/activities/scenarios/RumAutoScenarioActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.datadog.benchmark.sample.di.activity.BenchmarkActivityComponent
1616
import com.datadog.benchmark.sample.navigation.NavigationGraphInitializer
1717
import com.datadog.benchmark.sample.ui.rumauto.RumAutoBottomNavBar
1818
import com.datadog.benchmark.sample.ui.rumauto.RumAutoScenarioNavigator
19-
import com.datadog.benchmark.sample.ui.rumauto.RumAutoScenarioTab
2019
import com.datadog.sample.benchmark.R
2120
import com.datadog.sample.benchmark.databinding.FragmentRumAutoHostBinding
2221
import javax.inject.Inject
@@ -41,7 +40,7 @@ internal class RumAutoScenarioActivity : BaseScenarioActivity() {
4140
setContentView(binding.root)
4241

4342
binding.rumAutoBottomNavbar.setContent {
44-
val currentTab: RumAutoScenarioTab? by rumAutoScenarioNavigator.currentTab.collectAsStateWithLifecycle(null)
43+
val currentTab by rumAutoScenarioNavigator.currentTab.collectAsStateWithLifecycle(null)
4544

4645
currentTab?.let { tab ->
4746
RumAutoBottomNavBar(tab) {

sample/benchmark/src/main/java/com/datadog/benchmark/sample/di/app/AppModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal interface AppModule {
2626
fun provideBenchmarkConfig(
2727
holder: BenchmarkConfigHolder
2828
): BenchmarkConfig {
29-
return holder.config!!
29+
return holder.config
3030
}
3131
}
3232
}

sample/benchmark/src/test/java/com/datadog/benchmark/sample/network/KtorHttpClientUtilsTest.kt

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
package com.datadog.benchmark.sample.network
88

9-
import fr.xgouchet.elmyr.junit5.ForgeExtension
109
import io.ktor.client.HttpClient
1110
import io.ktor.client.engine.mock.MockEngine
1211
import io.ktor.client.engine.mock.respond
@@ -24,103 +23,93 @@ import kotlinx.serialization.json.Json
2423
import org.junit.jupiter.api.Assertions.assertEquals
2524
import org.junit.jupiter.api.Assertions.assertInstanceOf
2625
import org.junit.jupiter.api.Test
27-
import org.junit.jupiter.api.extension.ExtendWith
28-
import org.junit.jupiter.api.extension.Extensions
29-
import org.mockito.junit.jupiter.MockitoExtension
30-
import org.mockito.junit.jupiter.MockitoSettings
31-
import org.mockito.quality.Strictness
32-
33-
@Extensions(
34-
ExtendWith(MockitoExtension::class),
35-
ExtendWith(ForgeExtension::class)
36-
)
37-
@MockitoSettings(strictness = Strictness.LENIENT)
26+
3827
class KtorHttpClientUtilsTest {
3928
@Test
4029
fun `M return deserialized body W safeGet() { server returns 200 and proper json }`() {
41-
val mockEngine = MockEngine { request ->
30+
// Given
31+
val mockEngine = MockEngine {
4232
respond(
4333
content = Json.Default.encodeToString(ResponseData(1)),
4434
status = HttpStatusCode.OK,
4535
headers = headersOf(HttpHeaders.ContentType, "application/json")
4636
)
4737
}
4838

49-
val client = HttpClient(mockEngine) {
50-
install(ContentNegotiation) {
51-
json(Json { ignoreUnknownKeys = true })
52-
}
53-
}
39+
val client = createClient(mockEngine)
5440

5541
val url = URLBuilder("").build()
5642

57-
runBlocking {
58-
val response = client.safeGet<ResponseData>(url)
59-
assertEquals(ResponseData(1), response.optionalResult)
60-
}
43+
// When
44+
val response = runBlocking { client.safeGet<ResponseData>(url) }
45+
46+
// Then
47+
assertEquals(ResponseData(1), response.optionalResult)
6148
}
6249

6350
@Test
6451
fun `M return ServerError W safeGet() { server returns 500 }`() {
65-
val mockEngine = MockEngine { request ->
52+
// Given
53+
val mockEngine = MockEngine {
6654
respondError(status = HttpStatusCode.InternalServerError)
6755
}
6856

69-
val client = HttpClient(mockEngine) {
70-
install(ContentNegotiation) {
71-
json(Json { ignoreUnknownKeys = true })
72-
}
73-
}
57+
val client = createClient(mockEngine)
7458

7559
val url = URLBuilder("").build()
7660

77-
runBlocking {
78-
val response = client.safeGet<ResponseData>(url)
79-
assertEquals(KtorHttpResponse.ServerError(HttpStatusCode.InternalServerError), response)
80-
}
61+
// When
62+
val response = runBlocking { client.safeGet<ResponseData>(url) }
63+
64+
// Then
65+
assertEquals(KtorHttpResponse.ServerError(HttpStatusCode.InternalServerError), response)
8166
}
8267

8368
@Test
8469
fun `M return ClientError W safeGet() { server returns 404 }`() {
85-
val mockEngine = MockEngine { request ->
70+
// Given
71+
val mockEngine = MockEngine {
8672
respondError(status = HttpStatusCode.NotFound)
8773
}
8874

89-
val client = HttpClient(mockEngine) {
90-
install(ContentNegotiation) {
91-
json(Json { ignoreUnknownKeys = true })
92-
}
93-
}
75+
val client = createClient(mockEngine)
9476

9577
val url = URLBuilder("").build()
9678

97-
runBlocking {
98-
val response = client.safeGet<ResponseData>(url)
99-
assertEquals(KtorHttpResponse.ClientError(HttpStatusCode.NotFound), response)
100-
}
79+
// When
80+
val response = runBlocking { client.safeGet<ResponseData>(url) }
81+
82+
// Then
83+
assertEquals(KtorHttpResponse.ClientError(HttpStatusCode.NotFound), response)
10184
}
10285

10386
@Test
10487
fun `M return UnknownException W safeGet() { server returns 200 and invalid json }`() {
105-
val mockEngine = MockEngine { request ->
88+
// Given
89+
val mockEngine = MockEngine {
10690
respond(
10791
content = "some_invalid_json",
10892
status = HttpStatusCode.OK,
10993
headers = headersOf(HttpHeaders.ContentType, "application/json")
11094
)
11195
}
11296

113-
val client = HttpClient(mockEngine) {
114-
install(ContentNegotiation) {
115-
json(Json { ignoreUnknownKeys = true })
116-
}
117-
}
97+
val client = createClient(mockEngine)
11898

11999
val url = URLBuilder("").build()
120100

121-
runBlocking {
122-
val response = client.safeGet<ResponseData>(url)
123-
assertInstanceOf(KtorHttpResponse.UnknownException::class.java, response)
101+
// When
102+
val response = runBlocking { client.safeGet<ResponseData>(url) }
103+
104+
// Then
105+
assertInstanceOf(KtorHttpResponse.UnknownException::class.java, response)
106+
}
107+
108+
private fun createClient(engine: MockEngine): HttpClient {
109+
return HttpClient(engine) {
110+
install(ContentNegotiation) {
111+
json(Json { ignoreUnknownKeys = true })
112+
}
124113
}
125114
}
126115
}

0 commit comments

Comments
 (0)