From 12c3c4ef692488acc03b585c0daff23f2afcf57f Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Tue, 24 Oct 2017 23:54:08 +0800 Subject: [PATCH] Plugin test must compile with jdk 1.6, so not allow to use lambda. --- .../apm/plugin/sjdbc/InterceptorTest.java | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java index 925174676c31..f7219d088b3b 100644 --- a/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java @@ -26,7 +26,7 @@ import com.dangdang.ddframe.rdb.sharding.util.EventBusInstance; import com.google.common.base.Optional; import java.sql.SQLException; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -65,40 +65,40 @@ @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(TracingSegmentRunner.class) public class InterceptorTest { - + private static ExecutorService ES; - + @SegmentStoragePoint private SegmentStorage segmentStorage; @Rule public AgentServiceRule serviceRule = new AgentServiceRule(); - + private ExecuteInterceptor executeInterceptor; - + private AsyncExecuteInterceptor asyncExecuteInterceptor; private Object[] allArguments; - + @BeforeClass public static void init() { ExecuteEventListener.init(); new ExecutorEngineConstructorInterceptor().onConstruct(null, null); ES = Executors.newSingleThreadExecutor(); } - + @AfterClass public static void finish() { ES.shutdown(); } - + @Before public void setUp() throws SQLException { executeInterceptor = new ExecuteInterceptor(); asyncExecuteInterceptor = new AsyncExecuteInterceptor(); - allArguments = new Object[]{SQLType.DQL, null}; + allArguments = new Object[] {SQLType.DQL, null}; } - + @Test public void assertSyncExecute() throws Throwable { executeInterceptor.beforeMethod(null, null, allArguments, null, null); @@ -106,7 +106,7 @@ public void assertSyncExecute() throws Throwable { executeInterceptor.afterMethod(null, null, allArguments, null, null); assertThat(segmentStorage.getTraceSegments().size(), is(1)); TraceSegment segment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(segment); + List spans = SegmentHelper.getSpans(segment); assertNotNull(spans); assertThat(spans.size(), is(2)); assertSpan(spans.get(0), 0); @@ -118,9 +118,11 @@ public void assertAsyncExecute() throws Throwable { executeInterceptor.beforeMethod(null, null, allArguments, null, null); asyncExecuteInterceptor.beforeMethod(null, null, null, null, null); final Map dataMap = ExecutorDataMap.getDataMap(); - ES.submit(() -> { - ExecutorDataMap.setDataMap(dataMap); - sendEvent("ds_1", "select * from t_order_1"); + ES.submit(new Runnable() { + @Override public void run() { + ExecutorDataMap.setDataMap(dataMap); + sendEvent("ds_1", "select * from t_order_1"); + } }).get(); asyncExecuteInterceptor.afterMethod(null, null, null, null, null); sendEvent("ds_0", "select * from t_order_0"); @@ -140,15 +142,17 @@ public void assertAsyncExecute() throws Throwable { assertSpan(spans1.get(0), 0); assertThat(spans1.get(1).getOperationName(), is("/SJDBC/TRUNK/DQL")); } - + @Test public void assertExecuteError() throws Throwable { executeInterceptor.beforeMethod(null, null, allArguments, null, null); asyncExecuteInterceptor.beforeMethod(null, null, null, null, null); final Map dataMap = ExecutorDataMap.getDataMap(); - ES.submit(() -> { - ExecutorDataMap.setDataMap(dataMap); - sendError(); + ES.submit(new Runnable() { + @Override public void run() { + ExecutorDataMap.setDataMap(dataMap); + sendError(); + } }).get(); asyncExecuteInterceptor.handleMethodException(null, null, null, null, new SQLException("test")); asyncExecuteInterceptor.afterMethod(null, null, null, null, null); @@ -178,18 +182,22 @@ private void assertSpan(AbstractTracingSpan span, int index) { assertThat(span.isExit(), is(true)); assertThat(span.getOperationName(), is("/SJDBC/BRANCH/QUERY")); } - + private void assertErrorSpan(AbstractTracingSpan span) { assertOccurException(span, true); } - + private void sendEvent(String datasource, String sql) { - DQLExecutionEvent event = new DQLExecutionEvent(datasource, sql, Arrays.asList("1", 100)); + List parameters = new ArrayList(); + parameters.add("1"); + parameters.add(100); + + DQLExecutionEvent event = new DQLExecutionEvent(datasource, sql, parameters); EventBusInstance.getInstance().post(event); event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); EventBusInstance.getInstance().post(event); } - + private void sendError() { DMLExecutionEvent event = new DMLExecutionEvent("", "", Collections.emptyList()); EventBusInstance.getInstance().post(event);