-
-
Notifications
You must be signed in to change notification settings - Fork 469
Replace RestTemplate with OkHttp for system tests #4239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f951e32
Also use port when checking if a request is made to Sentry DSN
adinauer 47602d2
changelog
adinauer 282d7cd
Add a param to control whether the test script should rebuild before …
adinauer 0b67b60
Add system tests for distributed tracing
adinauer 1675387
reuse util classes for system tests
adinauer 8a31db1
add schema
adinauer a3be332
Add distributed tracing tests to more modules
adinauer 3c4b712
use mono.just for post body
adinauer a98146c
Replace RestTemplate with OkHttp in system tests
adinauer bce6071
Format code
getsentry-bot 941f1d5
format + api
adinauer 66f48ca
Merge branch 'main' into feat/replace-resttemplate-with-okhttp
adinauer 125cd4e
Update buildSrc/src/main/java/Config.kt
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sentry-system-test-support/src/main/kotlin/io/sentry/systemtest/ResponseTypes.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 61 additions & 5 deletions
66
...ystem-test-support/src/main/kotlin/io/sentry/systemtest/util/LoggingInsecureRestClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,69 @@ | ||
| package io.sentry.systemtest.util | ||
|
|
||
| import org.springframework.http.client.BufferingClientHttpRequestFactory | ||
| import org.springframework.web.client.RestTemplate | ||
| import com.fasterxml.jackson.databind.ObjectMapper | ||
| import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
| import okhttp3.Credentials | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.Request | ||
| import okhttp3.RequestBody | ||
| import okhttp3.RequestBody.Companion.toRequestBody | ||
| import okhttp3.Response | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| open class LoggingInsecureRestClient { | ||
| val logger = LoggerFactory.getLogger(LoggingInsecureRestClient::class.java) | ||
| var lastKnownStatusCode: Int? = null | ||
|
|
||
| protected fun restTemplate(): RestTemplate { | ||
| return RestTemplate().also { | ||
| it.requestFactory = BufferingClientHttpRequestFactory(it.requestFactory) | ||
| protected inline fun <reified T> callTyped(requestBuilder: Request.Builder, useAuth: Boolean, extraHeaders: Map<String, String>? = null): T? { | ||
| val response = call(requestBuilder, useAuth, extraHeaders) | ||
| val responseBody = response?.body?.string() | ||
| if (response?.isSuccessful != true) { | ||
| return null | ||
| } | ||
| return responseBody?.let { objectMapper().readValue(it, T::class.java) } | ||
| } | ||
|
|
||
| protected fun call(requestBuilder: Request.Builder, useAuth: Boolean, extraHeaders: Map<String, String>? = null): Response? { | ||
| try { | ||
| val request = requestBuilder.also { originalRequest -> | ||
| var modifiedRequest = originalRequest | ||
|
|
||
| if (useAuth) { | ||
| modifiedRequest = modifiedRequest.header( | ||
| "Authorization", | ||
| Credentials.basic("user", "password") | ||
| ) | ||
| } | ||
|
|
||
| extraHeaders?.forEach { key, value -> | ||
| modifiedRequest = modifiedRequest.header(key, value) | ||
| } | ||
|
|
||
| modifiedRequest | ||
| }.build() | ||
| val call = client().newCall(request) | ||
| val response = call.execute() | ||
| lastKnownStatusCode = response.code | ||
| return response | ||
| } catch (e: Exception) { | ||
| lastKnownStatusCode = null | ||
| logger.error("Request failed", e) | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| protected fun client(): OkHttpClient { | ||
| return OkHttpClient.Builder() | ||
| .build() | ||
| } | ||
|
|
||
| protected fun objectMapper(): ObjectMapper { | ||
| return jacksonObjectMapper() | ||
| } | ||
|
|
||
| protected fun toRequestBody(o: Any?): RequestBody { | ||
| val stringValue = objectMapper().writeValueAsString(o) | ||
| return stringValue.toRequestBody("application/json; charset=utf-8".toMediaType()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.