From 4ce8ea6067a82206994fb43fbe45b6893ec60e2c Mon Sep 17 00:00:00 2001 From: Mrproliu Date: Wed, 9 Oct 2019 18:45:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ehcache/v2/EhcacheInterceptorTest.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) rename apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/{aom => apm}/plugin/ehcache/v2/EhcacheInterceptorTest.java (80%) diff --git a/apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/aom/plugin/ehcache/v2/EhcacheInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java similarity index 80% rename from apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/aom/plugin/ehcache/v2/EhcacheInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java index fd8a1ba58463..41e91931f978 100644 --- a/apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/aom/plugin/ehcache/v2/EhcacheInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/ehcache-2.x-plugin/src/test/java/com/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java @@ -17,7 +17,7 @@ */ -package com.apache.skywalking.aom.plugin.ehcache.v2; +package com.apache.skywalking.apm.plugin.ehcache.v2; import com.apache.skywalking.apm.plugin.ehcache.v2.EhcacheEnhanceInfo; import com.apache.skywalking.apm.plugin.ehcache.v2.EhcacheLockInterceptor; @@ -25,6 +25,7 @@ import com.apache.skywalking.apm.plugin.ehcache.v2.EhcacheOperateObjectInterceptor; import net.sf.ehcache.Cache; import net.sf.ehcache.Element; +import net.sf.ehcache.config.CacheConfiguration; 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; @@ -63,14 +64,19 @@ public class EhcacheInterceptorTest { private EhcacheOperateObjectInterceptor operateObjectInterceptor; private EhcacheOperateElementInterceptor operateElementInterceptor; + private EhcacheOperateAllInterceptor operateAllInterceptor; private EhcacheLockInterceptor lockInterceptor; + private EhcacheConstructorInterceptor constructorInterceptor; private Object[] operateObjectArguments; private Object[] operateElementArguments; private Object[] tryLockArguments; private Object[] releaseLockArguments; + private Exception exception; + private Method putCacheMethod; private Method getCacheMethod; + private Method getAllMethod; private Method tryReadLockMethod; private Method tryWriteLockMethod; @@ -92,8 +98,12 @@ public void setSkyWalkingDynamicField(Object value) { public void setUp() throws NoSuchMethodException { operateObjectInterceptor = new EhcacheOperateObjectInterceptor(); operateElementInterceptor = new EhcacheOperateElementInterceptor(); + operateAllInterceptor = new EhcacheOperateAllInterceptor(); + constructorInterceptor = new EhcacheConstructorInterceptor(); lockInterceptor = new EhcacheLockInterceptor(); + exception = new Exception(); + operateObjectArguments = new Object[] { "dataKey" }; @@ -109,6 +119,7 @@ public void setUp() throws NoSuchMethodException { putCacheMethod = Whitebox.getMethods(Cache.class, PUT_CACHE_ENHANCE_METHOD)[0]; getCacheMethod = Whitebox.getMethods(Cache.class, GET_CACHE_ENHANCE_METHOD)[0]; + getAllMethod = Whitebox.getMethods(Cache.class, GET_ALL_CACHE_ENHANCE_METHOD)[0]; tryReadLockMethod = Whitebox.getMethods(Cache.class, READ_LOCK_TRY_ENHANCE_METHOD)[0]; tryWriteLockMethod = Whitebox.getMethods(Cache.class, WRITE_LOCK_TRY_ENHANCE_METHOD)[0]; @@ -116,10 +127,18 @@ public void setUp() throws NoSuchMethodException { releaseWriteLockMethod = Whitebox.getMethods(Cache.class, WRITE_LOCK_RELEASE_ENHANCE_METHOD)[0]; } + @Test + public void assertConstruct() throws Throwable { + constructorInterceptor.onConstruct(enhancedInstance, new Object[] { + new CacheConfiguration(CACHE_NAME, 20) + }); + } + @Test public void assertPutSuccess() throws Throwable { // put arguments operateElementInterceptor.beforeMethod(enhancedInstance, putCacheMethod, operateElementArguments, null, null); + operateElementInterceptor.handleMethodException(enhancedInstance, putCacheMethod, null, null, exception); operateElementInterceptor.afterMethod(enhancedInstance, putCacheMethod, operateElementArguments, null, null); List traceSegments = segmentStorage.getTraceSegments(); @@ -129,15 +148,28 @@ public void assertPutSuccess() throws Throwable { @Test public void assertGetSuccess() throws Throwable { operateObjectInterceptor.beforeMethod(enhancedInstance, getCacheMethod, operateObjectArguments, null, null); + operateObjectInterceptor.handleMethodException(enhancedInstance, getCacheMethod, null, null, exception); operateObjectInterceptor.afterMethod(enhancedInstance, getCacheMethod, operateObjectArguments, null, null); List traceSegments = segmentStorage.getTraceSegments(); Assert.assertThat(traceSegments.size(), is(1)); } + @Test + public void assertGetAllSuccess() throws Throwable { + operateAllInterceptor.beforeMethod(enhancedInstance, getAllMethod, null, null, null); + operateAllInterceptor.handleMethodException(enhancedInstance, getAllMethod, null, null, exception); + operateAllInterceptor.afterMethod(enhancedInstance, getAllMethod, null, null, null); + + List traceSegments = segmentStorage.getTraceSegments(); + Assert.assertThat(traceSegments.size(), is(1)); + } + + @Test public void assertLockSuccess() throws Throwable { lockInterceptor.beforeMethod(enhancedInstance, tryReadLockMethod, tryLockArguments, null, null); + lockInterceptor.handleMethodException(enhancedInstance, tryReadLockMethod, null, null, exception); lockInterceptor.afterMethod(enhancedInstance, tryReadLockMethod, tryLockArguments, null, null); lockInterceptor.beforeMethod(enhancedInstance, tryWriteLockMethod, tryLockArguments, null, null);