Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
luanjia committed Dec 30, 2018
2 parents 35520fd + bbc9ce4 commit e064515
Show file tree
Hide file tree
Showing 26 changed files with 942 additions and 1,029 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@

## for maven
pom.xml.versionsBackup
sandbox-api/target/
sandbox-common-api/target/
sandbox-core/target/
sandbox-provider-api/target/
sandbox-spy/target/
3 changes: 1 addition & 2 deletions sandbox-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox-common-api</artifactId>
</dependency>

<!-- 废弃对Servlet的依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>


</dependencies>

</project>
2 changes: 1 addition & 1 deletion sandbox-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>-Xbootclasspath/p:./src/test/resources/lib/sandbox-spy-1.1.0-for-qatest.jar</argLine>
<argLine>-Xbootclasspath/p:./src/test/resources/lib/sandbox-spy-1.2.0-for-qatest.jar</argLine>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private Spy.Ret handleEvent(final int listenerId,

// 普通事件处理器则可以打个日志后,直接放行
else {
logger.debug("on-event: event|{}|{}|{};listener|{} occur an error.",
logger.warn("on-event: event|{}|{}|{};listener|{} occur an error.",
event.type,
processId,
invokeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,15 @@ class SingleEventFactory {
}
}

private final BeforeEvent beforeEvent
= new BeforeEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null, null, null, null, null, null);

private final ReturnEvent returnEvent
= new ReturnEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);

private final ThrowsEvent throwsEvent
= new ThrowsEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);

private final LineEvent lineEvent
= new LineEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, -1);

private final ImmediatelyThrowsEvent immediatelyThrowsEvent
= new ImmediatelyThrowsEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);

private final ImmediatelyReturnEvent immediatelyReturnEvent
= new ImmediatelyReturnEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);

private final CallBeforeEvent callBeforeEvent
= new CallBeforeEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, -1, null, null, null);

private final CallReturnEvent callReturnEvent
= new CallReturnEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID);

private final CallThrowsEvent callThrowsEvent
= new CallThrowsEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);
private LineEvent lineEvent = null;
private BeforeEvent beforeEvent = null;
private ReturnEvent returnEvent = null;
private ThrowsEvent throwsEvent = null;
private CallBeforeEvent callBeforeEvent = null;
private CallReturnEvent callReturnEvent = null;
private CallThrowsEvent callThrowsEvent = null;
private ImmediatelyThrowsEvent immediatelyThrowsEvent = null;
private ImmediatelyReturnEvent immediatelyReturnEvent = null;


public BeforeEvent makeBeforeEvent(final int processId,
Expand All @@ -92,6 +75,9 @@ public BeforeEvent makeBeforeEvent(final int processId,
final String javaMethodDesc,
final Object target,
final Object[] argumentArray) {
if (null == beforeEvent) {
beforeEvent = new BeforeEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null, null, null, null, null, null);
}
unsafe.putInt(beforeEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(beforeEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putObject(beforeEvent, javaClassLoaderFieldInBeforeEventOffset, javaClassLoader);
Expand All @@ -106,15 +92,21 @@ public BeforeEvent makeBeforeEvent(final int processId,
public ReturnEvent makeReturnEvent(final int processId,
final int invokeId,
final Object returnObj) {
if (null == returnEvent) {
returnEvent = new ReturnEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);
}
unsafe.putInt(returnEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(returnEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putObject(returnEvent, objectFieldInReturnEventOffset, returnObj);
return returnEvent;
}

public ImmediatelyReturnEvent makeImmediatelyReturnEvent(final int processId,
final int invokeId,
final Object returnObj) {
final int invokeId,
final Object returnObj) {
if (null == immediatelyReturnEvent) {
immediatelyReturnEvent = new ImmediatelyReturnEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);
}
unsafe.putInt(immediatelyReturnEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(immediatelyReturnEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putObject(immediatelyReturnEvent, objectFieldInReturnEventOffset, returnObj);
Expand All @@ -124,26 +116,34 @@ public ImmediatelyReturnEvent makeImmediatelyReturnEvent(final int processId,
public ThrowsEvent makeThrowsEvent(final int processId,
final int invokeId,
final Throwable throwable) {
if (null == throwsEvent) {
throwsEvent = new ThrowsEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);
}
unsafe.putInt(throwsEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(throwsEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putObject(throwsEvent, throwableFieldInThrowsEventOffset, throwable);
return throwsEvent;
}

public ImmediatelyThrowsEvent makeImmediatelyThrowsEvent(final int processId,
final int invokeId,
final Throwable throwable) {
final int invokeId,
final Throwable throwable) {
if (null == immediatelyThrowsEvent) {
immediatelyThrowsEvent = new ImmediatelyThrowsEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);
}
unsafe.putInt(immediatelyThrowsEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(immediatelyThrowsEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putObject(immediatelyThrowsEvent, throwableFieldInThrowsEventOffset, throwable);
return immediatelyThrowsEvent;
}



public LineEvent makeLineEvent(final int processId,
final int invokeId,
final int lineNumber) {
if (null == lineEvent) {
lineEvent = new LineEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, -1);
}
unsafe.putInt(lineEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(lineEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putInt(lineEvent, lineNumberFieldInLineEventOffset, lineNumber);
Expand All @@ -156,6 +156,9 @@ public CallBeforeEvent makeCallBeforeEvent(final int processId,
final String owner,
final String name,
final String desc) {
if (null == callBeforeEvent) {
callBeforeEvent = new CallBeforeEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, -1, null, null, null);
}
unsafe.putInt(callBeforeEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(callBeforeEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putInt(callBeforeEvent, lineNumberFieldInCallBeforeEventOffset, lineNumber);
Expand All @@ -167,6 +170,9 @@ public CallBeforeEvent makeCallBeforeEvent(final int processId,

public CallReturnEvent makeCallReturnEvent(final int processId,
final int invokeId) {
if (null == callReturnEvent) {
callReturnEvent = new CallReturnEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID);
}
unsafe.putInt(callReturnEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(callReturnEvent, invokeIdFieldInInvokeEventOffset, invokeId);
return callReturnEvent;
Expand All @@ -175,6 +181,9 @@ public CallReturnEvent makeCallReturnEvent(final int processId,
public CallThrowsEvent makeCallThrowsEvent(final int processId,
final int invokeId,
final String throwException) {
if (null == callThrowsEvent) {
callThrowsEvent = new CallThrowsEvent(ILLEGAL_PROCESS_ID, ILLEGAL_INVOKE_ID, null);
}
unsafe.putInt(callThrowsEvent, processIdFieldInInvokeEventOffset, processId);
unsafe.putInt(callThrowsEvent, invokeIdFieldInInvokeEventOffset, invokeId);
unsafe.putObject(callThrowsEvent, throwExceptionFieldInCallThrowsEventOffset, throwException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ private void loadClassLoader() {

@Override
protected void onMethodEnter() {

codeLockForTracing.lock(new CodeLock.Block() {
@Override
public void code() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.alibaba.jvm.sandbox.qatest.core.enhance.listener.TracingEventListener;
import com.alibaba.jvm.sandbox.qatest.core.enhance.target.Calculator;
import com.alibaba.jvm.sandbox.qatest.core.util.JvmHelper;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.com.alibaba.jvm.sandbox.spy.Spy;

import static com.alibaba.jvm.sandbox.api.ProcessController.returnImmediately;
import static com.alibaba.jvm.sandbox.api.ProcessController.throwsImmediately;
import static com.alibaba.jvm.sandbox.api.event.Event.Type.*;
Expand All @@ -19,6 +22,11 @@

public class CalculatorTestCaseImplByEventListener implements ICalculatorTestCase {

@BeforeClass
public static void initSpy() {
Spy.isSpyThrowException = true;
}

@Test
@Override
public void cal$sum$around() throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.alibaba.jvm.sandbox.qatest.core.enhance;

import java.com.alibaba.jvm.sandbox.spy.Spy;

/**
* Calculator类测试用例接口
* <p>
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit e064515

Please sign in to comment.