Enable concurrency test for apache http client 4.0
MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy
@@ -12,9 +12,15 @@ import java.util.function.Consumer
import org.apache.http.HttpHost
import org.apache.http.HttpRequest
import org.apache.http.HttpResponse
+import org.apache.http.client.params.ClientPNames
+import org.apache.http.conn.ClientConnectionManager
+import org.apache.http.conn.ClientConnectionManagerFactory
+import org.apache.http.conn.scheme.SchemeRegistry
import org.apache.http.impl.client.DefaultHttpClient
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager
import org.apache.http.message.BasicHeader
import org.apache.http.message.BasicHttpRequest
+import org.apache.http.params.BasicHttpParams
import org.apache.http.params.HttpConnectionParams
import org.apache.http.params.HttpParams
import org.apache.http.protocol.BasicHttpContext
@@ -22,16 +28,24 @@ import spock.lang.Shared
abstract class ApacheHttpClientTest<T extends HttpRequest> extends HttpClientTest<T> implements AgentTestTrait {
@Shared
- def client = new DefaultHttpClient()
+ DefaultHttpClient client
def setupSpec() {
- HttpParams httpParams = client.getParams()
+ HttpParams httpParams = new BasicHttpParams()
HttpConnectionParams.setConnectionTimeout(httpParams, CONNECT_TIMEOUT_MS)
+ httpParams.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ThreadSafeClientConnManagerFactory.getName())
+ client = new DefaultHttpClient(httpParams)
}
+ static class ThreadSafeClientConnManagerFactory implements ClientConnectionManagerFactory {
@Override
- boolean testCausality() {
- false
+ ClientConnectionManager newInstance(HttpParams httpParams, SchemeRegistry schemeRegistry) {
+ return new ThreadSafeClientConnManager(httpParams, schemeRegistry)
+ }
+ }
+
+ def cleanupSpec() {
+ client.getConnectionManager().shutdown()
}
@Override

Enable concurrency test for apache http client 4.0 (#4020)