wu-sheng closed pull request #704: [Agent] Unsupport the async function of 
jetty client plugin
URL: https://github.com/apache/incubator-skywalking/pull/704
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java
deleted file mode 100644
index 490be9d74..000000000
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptor.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- *
- */
-
-
-package org.apache.skywalking.apm.plugin.jetty.v9.client;
-
-import java.lang.reflect.Method;
-import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
-import org.apache.skywalking.apm.agent.core.context.tag.Tags;
-import org.eclipse.jetty.client.HttpRequest;
-import org.eclipse.jetty.http.HttpFields;
-import org.apache.skywalking.apm.agent.core.context.CarrierItem;
-import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
-import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
-import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
-
-public class AsyncHttpRequestSendInterceptor implements 
InstanceMethodsAroundInterceptor {
-
-    @Override
-    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes,
-        MethodInterceptResult result) throws Throwable {
-        HttpRequest request = (HttpRequest)objInst;
-        ContextCarrier contextCarrier = new ContextCarrier();
-        AbstractSpan span = 
ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, 
request.getHost() + ":" + request.getPort());
-        span.setComponent(ComponentsDefine.JETTY_CLIENT);
-        Tags.HTTP.METHOD.set(span, request.getMethod().asString());
-        Tags.URL.set(span, request.getURI().toString());
-        SpanLayer.asHttp(span);
-
-        CarrierItem next = contextCarrier.items();
-        HttpFields field = request.getHeaders();
-        while (next.hasNext()) {
-            next = next.next();
-            field.add(next.getHeadKey(), next.getHeadValue());
-        }
-
-        EnhancedInstance callBackResult = (EnhancedInstance)allArguments[0];
-        callBackResult.setSkyWalkingDynamicField(ContextManager.capture());
-    }
-
-    @Override
-    public Object afterMethod(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes,
-        Object ret) throws Throwable {
-        ContextManager.stopSpan();
-        return ret;
-    }
-
-    @Override public void handleMethodException(EnhancedInstance objInst, 
Method method, Object[] allArguments,
-        Class<?>[] argumentsTypes, Throwable t) {
-        ContextManager.activeSpan().errorOccurred().log(t);
-    }
-}
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java
deleted file mode 100644
index 677fbff99..000000000
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptor.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- *
- */
-
-
-package org.apache.skywalking.apm.plugin.jetty.v9.client;
-
-import java.lang.reflect.Method;
-import org.apache.skywalking.apm.agent.core.context.tag.Tags;
-import org.eclipse.jetty.client.api.Result;
-import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
-import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
-import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
-import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
-
-public class CompleteListenerInterceptor implements 
InstanceMethodsAroundInterceptor {
-    @Override
-    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes,
-        MethodInterceptResult result) throws Throwable {
-        ContextSnapshot contextSnapshot = 
(ContextSnapshot)objInst.getSkyWalkingDynamicField();
-        if (contextSnapshot != null) {
-            Result callBackResult = (Result)allArguments[0];
-
-            AbstractSpan abstractSpan = 
ContextManager.createLocalSpan("CallBack/" + 
callBackResult.getRequest().getURI().getPath());
-            ContextManager.continued(contextSnapshot);
-
-            if (callBackResult.isFailed()) {
-                abstractSpan.errorOccurred().log(callBackResult.getFailure());
-                Tags.STATUS_CODE.set(abstractSpan, 
Integer.toString(callBackResult.getResponse().getStatus()));
-            }
-            abstractSpan.setComponent(ComponentsDefine.JETTY_CLIENT);
-            abstractSpan.setLayer(SpanLayer.HTTP);
-        }
-    }
-
-    @Override
-    public Object afterMethod(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes,
-        Object ret) throws Throwable {
-        ContextSnapshot contextSnapshot = 
(ContextSnapshot)objInst.getSkyWalkingDynamicField();
-        if (contextSnapshot != null) {
-            ContextManager.stopSpan();
-        }
-        return ret;
-    }
-
-    @Override public void handleMethodException(EnhancedInstance objInst, 
Method method, Object[] allArguments,
-        Class<?>[] argumentsTypes, Throwable t) {
-        ContextManager.activeSpan().errorOccurred().log(t);
-    }
-}
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java
index d595ae8d1..63fc9c58e 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptor.java
@@ -16,22 +16,22 @@
  *
  */
 
-
 package org.apache.skywalking.apm.plugin.jetty.v9.client;
 
 import java.lang.reflect.Method;
 import org.apache.skywalking.apm.agent.core.context.CarrierItem;
 import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
 import org.apache.skywalking.apm.agent.core.context.tag.Tags;
 import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
 import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
 import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
 import org.eclipse.jetty.client.HttpRequest;
 import org.eclipse.jetty.http.HttpFields;
-import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.eclipse.jetty.http.HttpMethod;
 
 public class SyncHttpRequestSendInterceptor implements 
InstanceMethodsAroundInterceptor {
 
@@ -42,7 +42,19 @@ public void beforeMethod(EnhancedInstance objInst, Method 
method, Object[] allAr
         ContextCarrier contextCarrier = new ContextCarrier();
         AbstractSpan span = 
ContextManager.createExitSpan(request.getURI().getPath(), contextCarrier, 
request.getHost() + ":" + request.getPort());
         span.setComponent(ComponentsDefine.JETTY_CLIENT);
-        Tags.HTTP.METHOD.set(span, "GET");
+        HttpMethod httpMethod = HttpMethod.GET;
+
+        /**
+         * The method is null if the client using GET method.
+         *
+         * @see org.eclipse.jetty.client.HttpRequest#GET(String uri)
+         * @see org.eclipse.jetty.client.HttpRequest( 
org.eclipse.jetty.client.HttpClient client, long conversation, java.net.URI uri)
+         */
+        if (request.getMethod() != null) {
+            httpMethod = request.getMethod();
+        }
+
+        Tags.HTTP.METHOD.set(span, httpMethod.asString());
         Tags.URL.set(span, request.getURI().toString());
         SpanLayer.asHttp(span);
 
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java
deleted file mode 100644
index ee6347513..000000000
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/CompleteListenerInstrumentation.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- *
- */
-
-
-package org.apache.skywalking.apm.plugin.jetty.v9.client.define;
-
-import net.bytebuddy.description.method.MethodDescription;
-import net.bytebuddy.matcher.ElementMatcher;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
-import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
-
-import static net.bytebuddy.matcher.ElementMatchers.named;
-import static 
org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
-
-/**
- * {@link CompleteListenerInstrumentation} enhance the <code>onComplete</code> 
method in all class of hierarchy
- * <code>org.eclipse.jetty.client.api.Response$CompleteListener</code> by 
<code>org.apache.skywalking.apm.plugin.jetty.client.CompleteListenerInterceptor</code>
- *
- * @author zhangxin
- */
-public class CompleteListenerInstrumentation extends 
ClassInstanceMethodsEnhancePluginDefine {
-
-    private static final String ENHANCE_CLASS = 
"org.eclipse.jetty.client.api.Response$CompleteListener";
-    private static final String ENHANCE_METHOD = "onComplete";
-    public static final String SEND_INTERCEPTOR = 
"org.apache.skywalking.apm.plugin.jetty.client.CompleteListenerInterceptor";
-
-    @Override protected ConstructorInterceptPoint[] 
getConstructorsInterceptPoints() {
-        return new ConstructorInterceptPoint[0];
-    }
-
-    @Override protected InstanceMethodsInterceptPoint[] 
getInstanceMethodsInterceptPoints() {
-        return new InstanceMethodsInterceptPoint[] {
-            new InstanceMethodsInterceptPoint() {
-                @Override
-                public ElementMatcher<MethodDescription> getMethodsMatcher() {
-                    return named(ENHANCE_METHOD);
-                }
-
-                @Override
-                public String getMethodsInterceptor() {
-                    return SEND_INTERCEPTOR;
-                }
-
-                @Override
-                public boolean isOverrideArgs() {
-                    return false;
-                }
-            }
-        };
-    }
-
-    @Override protected ClassMatch enhanceClass() {
-        return byHierarchyMatch(new String[] {ENHANCE_CLASS});
-    }
-}
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java
index 2946eac1f..147006dee 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java
@@ -21,15 +21,14 @@
 
 import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.matcher.ElementMatcher;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
 import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
 import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
 
 import static net.bytebuddy.matcher.ElementMatchers.named;
 import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
-import static 
org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
 
 /**
  * {@link HttpRequestInstrumentation} enhance the <code>send</code> method 
without argument in
@@ -43,8 +42,7 @@
 
     private static final String ENHANCE_CLASS = 
"org.eclipse.jetty.client.HttpRequest";
     private static final String ENHANCE_CLASS_NAME = "send";
-    public static final String ASYNC_SEND_INTERCEPTOR = 
"org.apache.skywalking.apm.plugin.jetty.client.AsyncHttpRequestSendInterceptor";
-    public static final String SYNC_SEND_INTERCEPTOR = 
"org.apache.skywalking.apm.plugin.jetty.client.SyncHttpRequestSendInterceptor";
+    public static final String SYNC_SEND_INTERCEPTOR = 
"org.apache.skywalking.apm.plugin.jetty.v9.client.SyncHttpRequestSendInterceptor";
 
     @Override protected ConstructorInterceptPoint[] 
getConstructorsInterceptPoints() {
         return new ConstructorInterceptPoint[0];
@@ -62,20 +60,6 @@
                     return SYNC_SEND_INTERCEPTOR;
                 }
 
-                @Override public boolean isOverrideArgs() {
-                    return false;
-                }
-            },
-            new InstanceMethodsInterceptPoint() {
-                //async call interceptor point
-                @Override public ElementMatcher<MethodDescription> 
getMethodsMatcher() {
-                    return 
named(ENHANCE_CLASS_NAME).and(takesArgumentWithType(0, 
"org.eclipse.jetty.client.api.Response$CompleteListener"));
-                }
-
-                @Override public String getMethodsInterceptor() {
-                    return ASYNC_SEND_INTERCEPTOR;
-                }
-
                 @Override public boolean isOverrideArgs() {
                     return false;
                 }
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def
index 2a8febe61..32e602e04 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def
+++ 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/resources/skywalking-plugin.def
@@ -1,2 +1 @@
-jetty-client-9.x=org.apache.skywalking.apm.plugin.jetty.v9.client.define.CompleteListenerInstrumentation
 
jetty-client-9.x=org.apache.skywalking.apm.plugin.jetty.v9.client.define.HttpRequestInstrumentation
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java
deleted file mode 100644
index ca8f7f3ef..000000000
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/AsyncHttpRequestSendInterceptorTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- *
- */
-
-
-package org.apache.skywalking.apm.plugin.jetty.v9.client;
-
-import java.net.URI;
-import java.util.List;
-import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
-import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
-import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
-import org.apache.skywalking.apm.agent.test.helper.SpanHelper;
-import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
-import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
-import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
-import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.HttpRequest;
-import org.eclipse.jetty.http.HttpMethod;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
-import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
-public class AsyncHttpRequestSendInterceptorTest {
-
-    @SegmentStoragePoint
-    private SegmentStorage segmentStorage;
-    @Rule
-    public AgentServiceRule serviceRule = new AgentServiceRule();
-    @Mock
-    private HttpClient httpClient;
-    @Mock
-    private EnhancedInstance callBackEnhanceInstance;
-
-    private Object[] allArguments;
-    private Class[] argumentTypes;
-    private MockHttpRequest enhancedInstance;
-    private AsyncHttpRequestSendInterceptor interceptor;
-    private URI uri = URI.create("http://localhost:8080/test";);
-
-    @Before
-    public void setUp() throws Exception {
-        enhancedInstance = new MockHttpRequest(httpClient, uri);
-        allArguments = new Object[] {"OperationKey", "OperationValue"};
-        argumentTypes = new Class[] {String.class, String.class};
-
-        interceptor = new AsyncHttpRequestSendInterceptor();
-        allArguments = new Object[] {callBackEnhanceInstance};
-    }
-
-    @Test
-    public void testMethodsAround() throws Throwable {
-        interceptor.beforeMethod(enhancedInstance, null, allArguments, 
argumentTypes, null);
-        interceptor.afterMethod(enhancedInstance, null, allArguments, 
argumentTypes, null);
-
-        assertThat(segmentStorage.getTraceSegments().size(), is(1));
-        TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
-
-        Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
-        AbstractTracingSpan finishedSpan = 
SegmentHelper.getSpans(traceSegment).get(0);
-
-        List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
-        assertThat(tags.size(), is(2));
-        assertThat(tags.get(0).getValue(), is("POST"));
-        assertThat(tags.get(1).getValue(), is(uri.toString()));
-
-        Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan));
-    }
-
-    @Test
-    public void testMethodsAroundError() throws Throwable {
-        interceptor.beforeMethod(enhancedInstance, null, allArguments, 
argumentTypes, null);
-        interceptor.handleMethodException(enhancedInstance, null, 
allArguments, argumentTypes, new RuntimeException());
-        interceptor.afterMethod(enhancedInstance, null, allArguments, 
argumentTypes, null);
-
-        assertThat(segmentStorage.getTraceSegments().size(), is(1));
-        TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
-
-        Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
-        AbstractTracingSpan finishedSpan = 
SegmentHelper.getSpans(traceSegment).get(0);
-
-        List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
-        assertThat(tags.size(), is(2));
-        assertThat(tags.get(0).getValue(), is("POST"));
-        assertThat(tags.get(1).getValue(), is(uri.toString()));
-
-        Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
-        SpanAssert.assertException(SpanHelper.getLogs(finishedSpan).get(0), 
RuntimeException.class);
-
-    }
-
-    private class MockHttpRequest extends HttpRequest implements 
EnhancedInstance {
-        public MockHttpRequest(HttpClient httpClient, URI uri) {
-            super(httpClient, uri);
-        }
-
-        @Override public Object getSkyWalkingDynamicField() {
-            return null;
-        }
-
-        @Override public void setSkyWalkingDynamicField(Object value) {
-
-        }
-
-        @Override public HttpMethod getMethod() {
-            return HttpMethod.POST;
-        }
-
-        @Override public URI getURI() {
-            return uri;
-        }
-    }
-}
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java
deleted file mode 100644
index bcea6c153..000000000
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/CompleteListenerInterceptorTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- *
- */
-
-
-package org.apache.skywalking.apm.plugin.jetty.v9.client;
-
-import java.net.URI;
-import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
-import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId;
-import org.apache.skywalking.apm.agent.core.context.ids.ID;
-import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
-import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
-import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
-import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
-import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
-import org.eclipse.jetty.client.HttpRequest;
-import org.eclipse.jetty.client.HttpResponse;
-import org.eclipse.jetty.client.api.Result;
-import org.eclipse.jetty.http.HttpFields;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.when;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
-public class CompleteListenerInterceptorTest {
-
-    @SegmentStoragePoint
-    private SegmentStorage segmentStorage;
-    @Rule
-    public AgentServiceRule serviceRule = new AgentServiceRule();
-    @Mock
-    private Result result;
-    @Mock
-    private HttpRequest httpRequest;
-    @Mock
-    private HttpResponse httpResponse;
-    private Object[] allArguments;
-    private Class[] argumentTypes;
-    private CompleteListenerInterceptor interceptor;
-
-    @Mock
-    private ContextSnapshot contextSnapshot;
-
-    private EnhancedInstance objectInstanceWithoutSnapshot = new 
EnhancedInstance() {
-        @Override
-        public Object getSkyWalkingDynamicField() {
-            return null;
-        }
-
-        @Override
-        public void setSkyWalkingDynamicField(Object value) {
-
-        }
-    };
-
-    private EnhancedInstance objectInstanceWithSnapshot = new 
EnhancedInstance() {
-        @Override
-        public Object getSkyWalkingDynamicField() {
-            return contextSnapshot;
-        }
-
-        @Override
-        public void setSkyWalkingDynamicField(Object value) {
-
-        }
-    };
-
-    @Before
-    public void setUp() {
-        interceptor = new CompleteListenerInterceptor();
-        when(result.getResponse()).thenReturn(httpResponse);
-        
when(httpRequest.getURI()).thenReturn(URI.create("http://localhost:8080/test";));
-        when(result.getRequest()).thenReturn(httpRequest);
-        allArguments = new Object[] {result};
-        argumentTypes = new Class[] {result.getClass()};
-        when(contextSnapshot.isValid()).thenReturn(true);
-        when(contextSnapshot.getEntryApplicationInstanceId()).thenReturn(1);
-        when(contextSnapshot.getSpanId()).thenReturn(2);
-        when(contextSnapshot.getTraceSegmentId()).thenReturn(mock(ID.class));
-        
when(contextSnapshot.getDistributedTraceId()).thenReturn(mock(DistributedTraceId.class));
-        when(contextSnapshot.getEntryOperationName()).thenReturn("1");
-        when(contextSnapshot.getParentOperationName()).thenReturn("2");
-    }
-
-    @Test
-    public void testMethodAroundWithoutSnapshot() throws Throwable {
-        interceptor.beforeMethod(objectInstanceWithoutSnapshot, null, 
allArguments, argumentTypes, null);
-        interceptor.afterMethod(objectInstanceWithoutSnapshot, null, 
allArguments, argumentTypes, null);
-        assertThat(segmentStorage.getTraceSegments().size(), is(0));
-    }
-
-    @Test
-    public void testMethodAroundWithSnapshot() throws Throwable {
-        HttpFields fields = new HttpFields();
-        when(httpResponse.getHeaders()).thenReturn(fields);
-        interceptor.beforeMethod(objectInstanceWithSnapshot, null, 
allArguments, argumentTypes, null);
-        interceptor.afterMethod(objectInstanceWithSnapshot, null, 
allArguments, argumentTypes, null);
-
-        assertThat(segmentStorage.getTraceSegments().size(), is(1));
-        TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
-        assertThat(traceSegment.getRefs().size(), is(1));
-    }
-}
diff --git 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java
 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java
index cddb0b7a7..625e2d059 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/client/SyncHttpRequestSendInterceptorTest.java
@@ -63,7 +63,7 @@
     private Object[] allArguments;
     private Class[] argumentTypes;
     private MockHttpRequest enhancedInstance;
-    private AsyncHttpRequestSendInterceptor interceptor;
+    private SyncHttpRequestSendInterceptor interceptor;
     private URI uri = URI.create("http://localhost:8080/test";);
 
     @Before
@@ -72,7 +72,7 @@ public void setUp() throws Exception {
         allArguments = new Object[] {"OperationKey", "OperationValue"};
         argumentTypes = new Class[] {String.class, String.class};
 
-        interceptor = new AsyncHttpRequestSendInterceptor();
+        interceptor = new SyncHttpRequestSendInterceptor();
         allArguments = new Object[] {callBackEnhanceInstance};
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to