Skip to content

Commit

Permalink
[#8965] Apply SharedTestLifeCycle to HttpWebServer
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 23, 2022
1 parent c67ce21 commit 504d876
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,29 @@

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;

import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.pluginit.utils.WebServer;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.ImportPlugin;
import com.navercorp.pinpoint.test.plugin.JvmVersion;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointConfig;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.ImportPlugin;
import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;

import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingMessage;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.interceptor.MessageSenderInterceptor;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.message.Message;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Properties;

import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.annotation;
import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event;

Expand All @@ -53,35 +51,24 @@
@Dependency({"org.apache.cxf:cxf-rt-rs-client:[3.0.0][3.0.16][3.1.0][3.1.16],[3.2.1,)", WebServer.VERSION, PluginITConstants.VERSION})
@ImportPlugin({"com.navercorp.pinpoint:pinpoint-cxf-plugin", "com.navercorp.pinpoint:pinpoint-jdk-http-plugin"})
@PinpointConfig("cxf/pinpoint-cxf-test.config")
@SharedTestLifeCycleClass(HttpWebServer.class)
public class CxfClientIT {

private static WebServer webServer;

private static String ADDRESS;

public static String getADDRESS() {
return ADDRESS;
}

public static void setADDRESS(String ADDRESS) {
CxfClientIT.ADDRESS = ADDRESS;
@SharedTestBeforeAllResult
public static void setBeforeAllResult(Properties beforeAllResult) {
ADDRESS = beforeAllResult.getProperty("ADDRESS");
}

@BeforeSharedClass
public static void BeforeClass() throws Exception {
webServer = WebServer.newTestWebServer();
setADDRESS(webServer.getCallHttpUrl());
}

@AfterSharedClass
public static void AfterClass() {
webServer = WebServer.cleanup(webServer);
public String getAddress() {
return ADDRESS;
}

@Test
public void test() throws Exception {

String address = getADDRESS();
String address = getAddress();

String json = "{\"id\" : 12345, \"name\" : \"victor\"}";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.plugin.cxf;

import com.navercorp.pinpoint.pluginit.utils.WebServer;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle;

import java.util.Properties;

public class HttpWebServer implements SharedTestLifeCycle {
private WebServer webServer;

@Override
public Properties beforeAll() {
try {
webServer = WebServer.newTestWebServer();

Properties properties = new Properties();
properties.setProperty("ADDRESS", webServer.getCallHttpUrl());
properties.setProperty("HOST_PORT", webServer.getHostAndPort());
return properties;
} catch (Exception e) {
throw new RuntimeException("webserver start error", e);
}
}

@Override
public void afterAll() {
webServer = WebServer.cleanup(webServer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@
*/
package com.navercorp.pinpoint.plugin.httpclient3;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.pluginit.utils.WebServer;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.ImportPlugin;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.shared.AfterSharedClass;
import com.navercorp.pinpoint.test.plugin.shared.BeforeSharedClass;
import java.util.Properties;

/**
* @author jaehong.kim
Expand All @@ -45,32 +44,20 @@
@PinpointAgent(AgentPath.PATH)
@ImportPlugin("com.navercorp.pinpoint:pinpoint-httpclient3-plugin")
@Dependency({ "commons-httpclient:commons-httpclient:[3.0],[3.0.1],[3.1]", WebServer.VERSION, PluginITConstants.VERSION})
@SharedTestLifeCycleClass(HttpWebServer.class)
public class HttpClientIT {

private static com.navercorp.pinpoint.pluginit.utils.WebServer webServer;

// ---------- For @BeforeSharedClass, @AfterSharedClass //
private static String CALL_URL;
private static String ADDRESS;

public static String getCallUrl() {
return CALL_URL;
@SharedTestBeforeAllResult
public static void setBeforeAllResult(Properties beforeAllResult) {
ADDRESS = beforeAllResult.getProperty("ADDRESS");
}

public static void setCallUrl(String callUrl) {
CALL_URL = callUrl;
public String getAddress() {
return ADDRESS;
}
// ---------- //

@BeforeSharedClass
public static void sharedSetUp() throws Exception {
webServer = WebServer.newTestWebServer();
setCallUrl(webServer.getCallHttpUrl());
}

@AfterSharedClass
public static void AfterClass() {
webServer = WebServer.cleanup(webServer);
}

private static final long CONNECTION_TIMEOUT = 10000;
private static final int SO_TIMEOUT = 10000;
Expand All @@ -81,7 +68,7 @@ public void test() {
client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
client.getParams().setSoTimeout(SO_TIMEOUT);

GetMethod method = new GetMethod(getCallUrl());
GetMethod method = new GetMethod(getAddress());

// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.plugin.httpclient3;

import com.navercorp.pinpoint.pluginit.utils.WebServer;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle;

import java.util.Properties;

public class HttpWebServer implements SharedTestLifeCycle {
private WebServer webServer;

@Override
public Properties beforeAll() {
try {
webServer = WebServer.newTestWebServer();

Properties properties = new Properties();
properties.setProperty("ADDRESS", webServer.getCallHttpUrl());
properties.setProperty("HOST_PORT", webServer.getHostAndPort());
return properties;
} catch (Exception e) {
throw new RuntimeException("webserver start error", e);
}
}

@Override
public void afterAll() {
webServer = WebServer.cleanup(webServer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;

import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
Expand Down Expand Up @@ -55,14 +56,15 @@
@ImportPlugin("com.navercorp.pinpoint:pinpoint-httpclient4-plugin")
@Dependency({"org.apache.httpcomponents:httpclient:[4.3],[4.3.1],[4.3.2],[4.3.3],[4.3.4],[4.3.6],[4.4],[4.4.1],[4.5],[4.5.1],[4.5.2],[4.5.3],[4.5.4],[4.3.5]",
WebServer.VERSION, PluginITConstants.VERSION})
@SharedTestLifeCycleClass(HttpWebServer.class)
public class CloaeableHttpClientIT extends HttpClientITBase {

@Test
public void test() throws Exception {
HttpGet httpget = new HttpGet(getCallUrl());
HttpGet httpget = new HttpGet(getAddress());

try (CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = httpclient.execute(httpget)) {
CloseableHttpResponse response = httpclient.execute(httpget)) {

HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;

import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
Expand Down Expand Up @@ -57,6 +58,7 @@
@ImportPlugin("com.navercorp.pinpoint:pinpoint-httpclient4-plugin")
@Dependency({"org.apache.httpcomponents:httpasyncclient:[4.0],[4.0.1],[4.0.2],[4.1],[4.1.1],[4.1.2],[4.1.3]",
WebServer.VERSION, PluginITConstants.VERSION})
@SharedTestLifeCycleClass(HttpWebServer.class)
public class ClosableAsyncHttpClientIT extends HttpClientITBase {

@Test
Expand All @@ -65,7 +67,7 @@ public void test() throws Exception {
httpClient.start();

try {
HttpPost httpRequest = new HttpPost(getCallUrl());
HttpPost httpRequest = new HttpPost(getAddress());

List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("param1", "value1"));
Expand All @@ -86,7 +88,7 @@ public void test() throws Exception {

verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", CloseableHttpAsyncClient.class.getMethod("execute", HttpUriRequest.class, FutureCallback.class)));
final String destinationId = getHostPort();
final String httpUrl = getCallUrl();
final String httpUrl = getAddress();
verifier.verifyTrace(async(
event("HTTP_CLIENT_4", Class.forName("org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl").getMethod("start"), null, null, destinationId,
annotation("http.url", httpUrl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@

package com.navercorp.pinpoint.plugin.httpclient4;

import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.*;
import static org.junit.Assert.*;

import java.io.IOException;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.pluginit.utils.AgentPath;
import com.navercorp.pinpoint.pluginit.utils.PluginITConstants;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.ImportPlugin;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import java.io.IOException;

import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.annotation;
import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event;
import static org.junit.Assert.assertTrue;

@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;

import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpRequest;
import org.apache.http.client.HttpClient;
Expand Down Expand Up @@ -55,13 +56,14 @@
@ImportPlugin("com.navercorp.pinpoint:pinpoint-httpclient4-plugin")
@Dependency({"org.apache.httpcomponents:httpclient:[4.0],[4.0.1],[4.0.2],[4.0.3],[4.1],[4.1.1],[4.1.2],[4.1.3],[4.2],[4.2.1],[4.2.2],[4.2.3],[4.2.4],[4.2.4],[4.2.6],[4.3.3]",
WebServer.VERSION, PluginITConstants.VERSION})
@SharedTestLifeCycleClass(HttpWebServer.class)
public class HttpClientIT extends HttpClientITBase {

@Test
public void test() throws Exception {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost post = new HttpPost(getCallUrl());
HttpPost post = new HttpPost(getAddress());
post.addHeader("Content-Type", "application/json;charset=UTF-8");

ResponseHandler<String> responseHandler = new BasicResponseHandler();
Expand Down
Loading

0 comments on commit 504d876

Please sign in to comment.