Skip to content

Commit

Permalink
工程代码可测性
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmanpushcart committed Oct 13, 2018
1 parent 802e1d9 commit d39ad95
Show file tree
Hide file tree
Showing 19 changed files with 479 additions and 170 deletions.
2 changes: 1 addition & 1 deletion doc/JVM-SANDBOX-USER-GUIDE-Chinese.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ EVENT_POOL_KEY_MAX : 2000
> JAR_FILE : /Users/luanjia/opt/sandbox/lib/../module/sandbox-mgr-module.jar
> STATE : FROZEN
> MODE : {AGENT,ATTACH}
> CLASS : class com.albaba.jvm.sandbox.module.mgr.ModuleMgrModule
> CLASS : class com.alibaba.jvm.sandbox.module.mgr.ModuleMgrModule
> LOADER : ModuleClassLoader[crc32=1721245995;file=/Users/luanjia/opt/sandbox/lib/../module/sandbox-mgr-module.jar;]
> cCnt : 0
> mCnt : 0
Expand Down
2 changes: 1 addition & 1 deletion doc/JVM-SANDBOX-USER-GUIDE-English.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Then the success of the start, the sandbox has been successfully implanted in th
> JAR_FILE : /Users/vlinux/opt/sandbox/lib/../module/sandbox-mgr-module.jar
> STATE : FROZEN
> MODE : {AGENT,ATTACH}
> CLASS : class com.albaba.jvm.sandbox.module.mgr.ModuleMgrModule
> CLASS : class com.alibaba.jvm.sandbox.module.mgr.ModuleMgrModule
> LOADER : ModuleClassLoader[crc32=1721245995;file=/Users/vlinux/opt/sandbox/lib/../module/sandbox-mgr-module.jar;]
> cCnt : 0
> mCnt : 0
Expand Down
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.alibaba.jvm.sandbox</groupId>
Expand Down Expand Up @@ -109,7 +108,8 @@
<module>sandbox-mgr-provider</module>
<module>sandbox-module-starter</module>
<module>sandbox-debug-module</module>
</modules>
<module>sandbox-qatest</module>
</modules>

<dependencyManagement>
<dependencies>
Expand All @@ -133,6 +133,12 @@
<artifactId>sandbox-spy</artifactId>
<version>${sandbox.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox-core</artifactId>
<version>${sandbox.version}</version>
<scope>test</scope>
</dependency>

<!-- servlet api -->
<dependency>
Expand Down Expand Up @@ -204,4 +210,4 @@
</scm>


</project>
</project>
6 changes: 0 additions & 6 deletions sandbox-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,33 @@ protected EventProcess initialValue() {

private EventListenerWrap(final EventListener listener,
final Event.Type[] eventTypeArray) {
this.listener = new SeparateImmediatelyEventListener(eventTypeArray, listener, eventPool);

if(isInterruptEventHandler(listener.getClass())) {
this.listener = new InterruptedEventListenerImpl(
new SeparateImmediatelyEventListener(eventTypeArray, listener, eventPool)
);
} else {
this.listener = new SeparateImmediatelyEventListener(eventTypeArray, listener, eventPool);
}
}
}

@Interrupted
private class InterruptedEventListenerImpl implements EventListener {

private final EventListener listener;

private InterruptedEventListenerImpl(EventListener listener) {
this.listener = listener;
}

@Override
public void onEvent(Event event) throws Throwable {
listener.onEvent(event);
}

}


// ----------------------------------- 从这里开始就是提供给Spy的static方法 -----------------------------------

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albaba.jvm.sandbox.module.mgr;
package com.alibaba.jvm.sandbox.module.mgr;

import com.alibaba.jvm.sandbox.api.Information;
import com.alibaba.jvm.sandbox.api.Module;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albaba.jvm.sandbox.module.mgr;
package com.alibaba.jvm.sandbox.module.mgr;

import com.alibaba.jvm.sandbox.api.Information;
import com.alibaba.jvm.sandbox.api.Module;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albaba.jvm.sandbox.module.mgr;
package com.alibaba.jvm.sandbox.module.mgr;

import com.alibaba.jvm.sandbox.api.Information;
import com.alibaba.jvm.sandbox.api.Module;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
com.albaba.jvm.sandbox.module.mgr.ModuleMgrModule
com.albaba.jvm.sandbox.module.mgr.InfoModule
com.albaba.jvm.sandbox.module.mgr.ControlModule
com.alibaba.jvm.sandbox.module.mgr.ModuleMgrModule
com.alibaba.jvm.sandbox.module.mgr.InfoModule
com.alibaba.jvm.sandbox.module.mgr.ControlModule
Binary file not shown.
41 changes: 41 additions & 0 deletions sandbox-qatest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.0.16</version>
</parent>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox-qatest</artifactId>
<name>sandbox-qatest</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>pertest</forkMode>
<argLine>-Xbootclasspath/p:./lib/sandbox-spy-1.0.16-for-qatest.jar</argLine>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.alibaba.jvm.sandbox.qatest.core.enhance;

import com.alibaba.jvm.sandbox.api.event.BeforeEvent;
import com.alibaba.jvm.sandbox.api.event.Event;
import com.alibaba.jvm.sandbox.api.event.ThrowsEvent;
import com.alibaba.jvm.sandbox.api.filter.Filter;
import com.alibaba.jvm.sandbox.api.filter.NameRegexFilter;
import com.alibaba.jvm.sandbox.api.listener.EventListener;
import com.alibaba.jvm.sandbox.core.util.SandboxReflectUtils;
import com.alibaba.jvm.sandbox.core.util.UnCaughtException;
import com.alibaba.jvm.sandbox.qatest.core.enhance.target.Calculator;
import junit.framework.Assert;
import org.junit.Test;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static com.alibaba.jvm.sandbox.core.util.SandboxReflectUtils.unCaughtGetClassDeclaredJavaMethod;
import static com.alibaba.jvm.sandbox.core.util.SandboxReflectUtils.unCaughtInvokeMethod;

public class CalculatorTestCase extends CoreEnhanceBaseTestCase {

protected int calculatorSum(final Object calculatorObject, int... numArray) {
return unCaughtInvokeMethod(
unCaughtGetClassDeclaredJavaMethod(calculatorObject.getClass(), "sum", int[].class),
calculatorObject,
numArray
);
}

protected int calculatorErrorSum(final Object calculatorObject, int... numArray) throws Throwable {
try {
return unCaughtInvokeMethod(
unCaughtGetClassDeclaredJavaMethod(calculatorObject.getClass(), "errorSum", int[].class),
calculatorObject,
numArray
);
} catch (Throwable cause) {
if(cause instanceof UnCaughtException
&& (cause.getCause() instanceof InvocationTargetException)) {
throw ((InvocationTargetException)cause.getCause()).getTargetException();
}
throw cause;
}
}

@Test
public void test_sum() throws IllegalAccessException, IOException, InvocationTargetException, InstantiationException {
final Class<?> computerClass = watching(
Calculator.class,
new NameRegexFilter(".*", "sum"),
new InterruptedEventListener() {
@Override
public void onEvent(Event event) throws Throwable {
final BeforeEvent beforeEvent = (BeforeEvent) event;
final int[] numberArray = (int[]) beforeEvent.argumentArray[0];
numberArray[0] = 40;
numberArray[1] = 60;
}
},
Event.Type.BEFORE
);

Assert.assertEquals(
100,
calculatorSum(
computerClass.newInstance(),
1, 1
)
);

}

}
Loading

0 comments on commit d39ad95

Please sign in to comment.