Merge branch 'master' into feature/423
This commit is contained in:
commit
5566c0d337
|
|
@ -12,7 +12,7 @@ Sky Walking | [English](README.md)
|
|||
|
||||
|
||||
* 自动java探针,**不需要修改应用程序源代码**
|
||||
* 高性能探针,针对单实例5000tps的应用,在**不需要采样的情况下**,只增加**10%**的CPU开销。
|
||||
* 高性能探针,针对单实例5000tps的应用,在**全量采集的情况下**,只增加**10%**的CPU开销。
|
||||
* [中间件,框架与类库支持列表](https://github.com/wu-sheng/sky-walking/wiki/3.2-supported-list).
|
||||
* 手动探针
|
||||
* [使用OpenTracing手动探针API](http://opentracing.io/documentation/pages/supported-tracers)
|
||||
|
|
@ -54,9 +54,9 @@ This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDU
|
|||
|
||||
# Test reports
|
||||
- 自动化集成测试报告
|
||||
- [Java探针测试报告](https://github.com/sky-walking/agent-integration-test-report)
|
||||
- [Java探针测试报告](https://github.com/SkywalkingTest/agent-integration-test-report)
|
||||
- 性能测试报告
|
||||
- [Java探针测试报告](https://sky-walking.github.io/Agent-Benchmarks/)
|
||||
- [Java探针测试报告](https://skywalkingtest.github.io/Agent-Benchmarks/)
|
||||
|
||||
# Contact Us
|
||||
* 直接提交Issue
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener, FirstSpanListener {
|
||||
public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener,FirstSpanListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SegmentCostSpanListener.class);
|
||||
|
||||
|
|
@ -50,10 +50,7 @@ public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListe
|
|||
@Override
|
||||
public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
|
||||
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
|
||||
SegmentCostDataDefine.SegmentCost segmentCost = new SegmentCostDataDefine.SegmentCost();
|
||||
segmentCost.setSegmentId(segmentId);
|
||||
segmentCost.setApplicationId(applicationId);
|
||||
|
|
@ -71,6 +68,11 @@ public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListe
|
|||
isError = isError || spanObject.getIsError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
|
||||
isError = isError || spanObject.getIsError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseExit(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
|
||||
isError = isError || spanObject.getIsError();
|
||||
|
|
@ -96,4 +98,4 @@ public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListe
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<jetty.version>9.4.2.v20170220</jetty.version>
|
||||
<grpc.version>1.4.0</grpc.version>
|
||||
<bytebuddy.version>1.7.6</bytebuddy.version>
|
||||
|
||||
<shade.package>org.skywalking.apm.dependencies</shade.package>
|
||||
<shade.com.lmax.disruptor.source>com.lmax.disruptor</shade.com.lmax.disruptor.source>
|
||||
|
|
@ -65,12 +66,12 @@
|
|||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>${bytebuddy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy-agent</artifactId>
|
||||
<version>1.5.7</version>
|
||||
<version>${bytebuddy.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
package org.skywalking.apm.agent.core.boot;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author zhangkewei
|
||||
*/
|
||||
public class DefaultNamedThreadFactory implements ThreadFactory {
|
||||
private static final AtomicInteger BOOT_SERVICE_SEQ = new AtomicInteger(0);
|
||||
private final AtomicInteger threadSeq = new AtomicInteger(0);
|
||||
private final String namePrefix;
|
||||
public DefaultNamedThreadFactory(String name) {
|
||||
namePrefix = "SkywalkingAgent-" + BOOT_SERVICE_SEQ.incrementAndGet() + "-" + name + "-";
|
||||
}
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r,namePrefix + threadSeq.getAndIncrement());
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ public class NoopSpan implements AbstractSpan {
|
|||
}
|
||||
|
||||
@Override public AbstractSpan errorOccurred() {
|
||||
return null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.skywalking.apm.agent.core.boot.BootService;
|
||||
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
|
||||
|
|
@ -57,7 +58,6 @@ public class JVMService implements BootService, Runnable {
|
|||
private volatile ScheduledFuture<?> collectMetricFuture;
|
||||
private volatile ScheduledFuture<?> sendMetricFuture;
|
||||
private Sender sender;
|
||||
|
||||
@Override
|
||||
public void beforeBoot() throws Throwable {
|
||||
queue = new LinkedBlockingQueue(Config.Jvm.BUFFER_SIZE);
|
||||
|
|
@ -68,10 +68,10 @@ public class JVMService implements BootService, Runnable {
|
|||
@Override
|
||||
public void boot() throws Throwable {
|
||||
collectMetricFuture = Executors
|
||||
.newSingleThreadScheduledExecutor()
|
||||
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-produce"))
|
||||
.scheduleAtFixedRate(this, 0, 1, TimeUnit.SECONDS);
|
||||
sendMetricFuture = Executors
|
||||
.newSingleThreadScheduledExecutor()
|
||||
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-consume"))
|
||||
.scheduleAtFixedRate(sender, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.skywalking.apm.agent.core.boot.BootService;
|
||||
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
|
||||
|
|
@ -89,7 +90,7 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList
|
|||
@Override
|
||||
public void boot() throws Throwable {
|
||||
applicationRegisterFuture = Executors
|
||||
.newSingleThreadScheduledExecutor()
|
||||
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("AppAndServiceRegisterClient"))
|
||||
.scheduleAtFixedRate(this, 0, Config.Collector.APP_AND_SERVICE_REGISTER_CHECK_INTERVAL, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +106,7 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug("AppAndServiceRegisterClient running, status:{}.",status);
|
||||
boolean shouldTry = true;
|
||||
while (CONNECTED.equals(status) && shouldTry) {
|
||||
shouldTry = false;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.skywalking.apm.agent.core.boot.BootService;
|
||||
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +40,7 @@ public class CollectorDiscoveryService implements BootService {
|
|||
|
||||
@Override
|
||||
public void boot() throws Throwable {
|
||||
future = Executors.newSingleThreadScheduledExecutor()
|
||||
future = Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("CollectorDiscoveryService"))
|
||||
.scheduleAtFixedRate(new DiscoveryRestServiceClient(), 0,
|
||||
Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.skywalking.apm.agent.core.boot.BootService;
|
||||
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
|
||||
import org.skywalking.apm.logging.ILog;
|
||||
import org.skywalking.apm.logging.LogManager;
|
||||
|
||||
import static org.skywalking.apm.agent.core.conf.Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
|
|
@ -58,8 +58,8 @@ public class GRPCChannelManager implements BootService, Runnable {
|
|||
@Override
|
||||
public void boot() throws Throwable {
|
||||
connectCheckFuture = Executors
|
||||
.newSingleThreadScheduledExecutor()
|
||||
.scheduleAtFixedRate(this, 0, GRPC_CHANNEL_CHECK_INTERVAL, TimeUnit.SECONDS);
|
||||
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("GRPCChannelManager"))
|
||||
.scheduleAtFixedRate(this, 0, Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -71,15 +71,18 @@ public class GRPCChannelManager implements BootService, Runnable {
|
|||
public void shutdown() throws Throwable {
|
||||
connectCheckFuture.cancel(true);
|
||||
managedChannel.shutdownNow();
|
||||
logger.debug("Selected collector grpc service shutdown.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug("Selected collector grpc service running, reconnect:{}.",reconnect);
|
||||
if (reconnect) {
|
||||
if (RemoteDownstreamConfig.Collector.GRPC_SERVERS.size() > 0) {
|
||||
int index = random.nextInt() % RemoteDownstreamConfig.Collector.GRPC_SERVERS.size();
|
||||
String server = RemoteDownstreamConfig.Collector.GRPC_SERVERS.get(index);
|
||||
String server = "";
|
||||
try {
|
||||
int index = Math.abs(random.nextInt()) % RemoteDownstreamConfig.Collector.GRPC_SERVERS.size();
|
||||
server = RemoteDownstreamConfig.Collector.GRPC_SERVERS.get(index);
|
||||
String[] ipAndPort = server.split(":");
|
||||
ManagedChannelBuilder<?> channelBuilder =
|
||||
NettyChannelBuilder.forAddress(ipAndPort[0], Integer.parseInt(ipAndPort[1]))
|
||||
|
|
@ -100,7 +103,7 @@ public class GRPCChannelManager implements BootService, Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
logger.debug("Selected collector grpc service is not available. Wait {} seconds to retry", GRPC_CHANNEL_CHECK_INTERVAL);
|
||||
logger.debug("Selected collector grpc service is not available. Wait {} seconds to retry", Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.skywalking.apm.agent.core.boot.BootService;
|
||||
import org.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
|
||||
import org.skywalking.apm.logging.ILog;
|
||||
|
|
@ -63,7 +64,7 @@ public class SamplingService implements BootService {
|
|||
on = true;
|
||||
this.resetSamplingFactor();
|
||||
ScheduledExecutorService service = Executors
|
||||
.newSingleThreadScheduledExecutor();
|
||||
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("SamplingService"));
|
||||
scheduledFuture = service.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
package org.skywalking.apm.agent.core.boot;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author zhangkewei
|
||||
*/
|
||||
public class DefaultNamedThreadFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testNamedThread() throws Exception {
|
||||
Thread newThread = new DefaultNamedThreadFactory("DefaultNamedThreadFactoryTest").newThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
});
|
||||
newThread.start();
|
||||
assertNotNull(newThread.getName());
|
||||
assert(newThread.getName().contains("DefaultNamedThreadFactoryTest"));
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ package org.skywalking.apm.plugin.jetty.v9.server;
|
|||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -36,8 +37,8 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) throws Throwable {
|
||||
String requestURI = (String)allArguments[0];
|
||||
HttpServletRequest servletRequest = (HttpServletRequest)allArguments[2];
|
||||
HttpChannel httpChannel = (HttpChannel)allArguments[0];
|
||||
HttpServletRequest servletRequest = httpChannel.getRequest();
|
||||
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
next.setHeadValue(servletRequest.getHeader(next.getHeadKey()));
|
||||
}
|
||||
|
||||
AbstractSpan span = ContextManager.createEntrySpan(requestURI, contextCarrier);
|
||||
AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier);
|
||||
Tags.URL.set(span, servletRequest.getRequestURL().toString());
|
||||
Tags.HTTP.METHOD.set(span, servletRequest.getMethod());
|
||||
span.setComponent(ComponentsDefine.JETTY_SERVER);
|
||||
|
|
@ -57,7 +58,8 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable {
|
||||
HttpServletResponse servletResponse = (HttpServletResponse)allArguments[3];
|
||||
HttpChannel httpChannel = (HttpChannel)allArguments[0];
|
||||
HttpServletResponse servletResponse = httpChannel.getResponse();
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
if (servletResponse.getStatus() >= 400) {
|
||||
span.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -26,17 +26,18 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMet
|
|||
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* {@link HandlerListInstrumentation} enhance the <code>handle</code> method in <code>org.eclipse.jetty.server.handler.HandlerList</code>
|
||||
* {@link JettyInstrumentation} enhance the <code>handle</code> method in <code>org.eclipse.jetty.server.handler.HandlerList</code>
|
||||
* by <code>org.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor</code>
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class HandlerListInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
public class JettyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.eclipse.jetty.server.handler.HandlerList";
|
||||
private static final String ENHANCE_CLASS = "org.eclipse.jetty.server.Server";
|
||||
private static final String ENHANCE_METHOD = "handle";
|
||||
private static final String INTERCEPTOR_CLASS = "org.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor";
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ public class HandlerListInstrumentation extends ClassInstanceMethodsEnhancePlugi
|
|||
return new InstanceMethodsInterceptPoint[] {
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named(ENHANCE_METHOD);
|
||||
return named(ENHANCE_METHOD).and(takesArgumentWithType(0, "org.eclipse.jetty.server.HttpChannel"));
|
||||
}
|
||||
|
||||
@Override public String getMethodsInterceptor() {
|
||||
|
|
@ -1 +1 @@
|
|||
jetty-server-9.x=org.skywalking.apm.plugin.jetty.v9.server.define.HandlerListInstrumentation
|
||||
jetty-server-9.x=org.skywalking.apm.plugin.jetty.v9.server.define.JettyInstrumentation
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
package org.skywalking.apm.plugin.jetty.v9.server;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -58,7 +58,7 @@ import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag;
|
|||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
public class HandleInterceptorTest {
|
||||
|
||||
private HandleInterceptor tomcatInvokeInterceptor;
|
||||
private HandleInterceptor jettyInvokeInterceptor;
|
||||
@SegmentStoragePoint
|
||||
private SegmentStorage segmentStorage;
|
||||
|
||||
|
|
@ -66,36 +66,39 @@ public class HandleInterceptorTest {
|
|||
public AgentServiceRule serviceRule = new AgentServiceRule();
|
||||
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
private Request request;
|
||||
|
||||
@Mock
|
||||
private Request baseRequest;
|
||||
@Mock
|
||||
private HttpServletResponse response;
|
||||
private Response response;
|
||||
@Mock
|
||||
private MethodInterceptResult methodInterceptResult;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance enhancedInstance;
|
||||
|
||||
@Mock
|
||||
private HttpChannel httpChannel;
|
||||
|
||||
private Object[] arguments;
|
||||
private Class[] argumentType;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tomcatInvokeInterceptor = new HandleInterceptor();
|
||||
jettyInvokeInterceptor = new HandleInterceptor();
|
||||
when(request.getRequestURI()).thenReturn("/test/testRequestURL");
|
||||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL"));
|
||||
when(response.getStatus()).thenReturn(200);
|
||||
arguments = new Object[] {"/test/testRequestURL", baseRequest, request, response};
|
||||
argumentType = new Class[] {String.class, baseRequest.getClass(), request.getClass(), response.getClass()};
|
||||
when(httpChannel.getResponse()).thenReturn(response);
|
||||
when(httpChannel.getRequest()).thenReturn(request);
|
||||
arguments = new Object[] {httpChannel};
|
||||
argumentType = new Class[] {httpChannel.getClass()};
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutSerializedContextData() throws Throwable {
|
||||
tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -107,8 +110,8 @@ public class HandleInterceptorTest {
|
|||
public void testWithSerializedContextData() throws Throwable {
|
||||
when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -120,9 +123,9 @@ public class HandleInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithOccurException() throws Throwable {
|
||||
tomcatInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
tomcatInvokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
|
||||
tomcatInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
jettyInvokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
jettyInvokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
|
||||
jettyInvokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue