Set http client read timeout only for the read timeout test (#9194)
This commit is contained in:
parent
5f72b43779
commit
7e7d7ca866
|
@ -17,19 +17,40 @@ import spock.lang.Shared
|
|||
class JaxRsClientV1Test extends HttpClientTest<WebResource.Builder> implements AgentTestTrait {
|
||||
|
||||
@Shared
|
||||
Client client = Client.create()
|
||||
Client client = buildClient(false)
|
||||
|
||||
def setupSpec() {
|
||||
@Shared
|
||||
Client clientWithReadTimeout = buildClient(true)
|
||||
|
||||
def buildClient(boolean readTimeout) {
|
||||
def client = Client.create()
|
||||
client.setConnectTimeout(CONNECT_TIMEOUT_MS)
|
||||
client.setReadTimeout(READ_TIMEOUT_MS)
|
||||
if (readTimeout) {
|
||||
client.setReadTimeout(READ_TIMEOUT_MS)
|
||||
}
|
||||
// Add filters to ensure spans aren't duplicated.
|
||||
client.addFilter(new LoggingFilter())
|
||||
client.addFilter(new GZIPContentEncodingFilter())
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
Client getClient(URI uri) {
|
||||
if (uri.toString().contains("/read-timeout")) {
|
||||
return clientWithReadTimeout
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
@Override
|
||||
def cleanupSpec() {
|
||||
client?.destroy()
|
||||
clientWithReadTimeout?.destroy()
|
||||
}
|
||||
|
||||
@Override
|
||||
WebResource.Builder buildRequest(String method, URI uri, Map<String, String> headers) {
|
||||
def resource = client.resource(uri).requestBuilder
|
||||
def resource = getClient(uri).resource(uri).requestBuilder
|
||||
headers.each { resource.header(it.key, it.value) }
|
||||
return resource
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions
|
|||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -29,14 +28,23 @@ public class SpringRestTemplateTest extends AbstractHttpClientTest<HttpEntity<St
|
|||
@RegisterExtension
|
||||
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent();
|
||||
|
||||
static RestTemplate restTemplate;
|
||||
static RestTemplate restTemplate = buildClient(false);
|
||||
static RestTemplate restTemplateWithReadTimeout = buildClient(true);
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
private static RestTemplate buildClient(boolean readTimeout) {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setConnectTimeout((int) CONNECTION_TIMEOUT.toMillis());
|
||||
factory.setReadTimeout((int) READ_TIMEOUT.toMillis());
|
||||
restTemplate = new RestTemplate(factory);
|
||||
if (readTimeout) {
|
||||
factory.setReadTimeout((int) READ_TIMEOUT.toMillis());
|
||||
}
|
||||
return new RestTemplate(factory);
|
||||
}
|
||||
|
||||
private static RestTemplate getClient(URI uri) {
|
||||
if (uri.toString().contains("/read-timeout")) {
|
||||
return restTemplateWithReadTimeout;
|
||||
}
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +59,7 @@ public class SpringRestTemplateTest extends AbstractHttpClientTest<HttpEntity<St
|
|||
HttpEntity<String> request, String method, URI uri, Map<String, String> headers)
|
||||
throws Exception {
|
||||
try {
|
||||
return restTemplate
|
||||
return getClient(uri)
|
||||
.exchange(uri, HttpMethod.valueOf(method), request, String.class)
|
||||
.getStatusCode()
|
||||
.value();
|
||||
|
|
Loading…
Reference in New Issue