/* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import io.opentelemetry.auto.test.base.HttpClientTest import okhttp3.Headers import okhttp3.MediaType import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody import okhttp3.internal.http.HttpMethod import spock.lang.Timeout import java.util.concurrent.TimeUnit @Timeout(5) class OkHttp3Test extends HttpClientTest { def client = new OkHttpClient.Builder() .connectTimeout(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS) .readTimeout(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS) .writeTimeout(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS) .build() @Override int doRequest(String method, URI uri, Map headers, Closure callback) { def body = HttpMethod.requiresRequestBody(method) ? RequestBody.create(MediaType.parse("text/plain"), "") : null def request = new Request.Builder() .url(uri.toURL()) .method(method, body) .headers(Headers.of(headers)).build() def response = client.newCall(request).execute() callback?.call() return response.code() } boolean testRedirects() { false } }