Plugin test must compile with jdk 1.6, so not allow to use lambda.
This commit is contained in:
parent
0e23b0248a
commit
12c3c4ef69
|
|
@ -26,7 +26,7 @@ import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap;
|
|||
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 @@ import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag;
|
|||
@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 class InterceptorTest {
|
|||
executeInterceptor.afterMethod(null, null, allArguments, null, null);
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment segment = segmentStorage.getTraceSegments().get(0);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
|
||||
assertNotNull(spans);
|
||||
assertThat(spans.size(), is(2));
|
||||
assertSpan(spans.get(0), 0);
|
||||
|
|
@ -118,9 +118,11 @@ public class InterceptorTest {
|
|||
executeInterceptor.beforeMethod(null, null, allArguments, null, null);
|
||||
asyncExecuteInterceptor.beforeMethod(null, null, null, null, null);
|
||||
final Map<String, Object> 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 class InterceptorTest {
|
|||
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<String, Object> 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 @@ public class InterceptorTest {
|
|||
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<Object> parameters = new ArrayList<Object>();
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue