mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
fix(test): JsParserTest Vertx 资源泄漏修复
将各 @Test 方法中局部创建的 Vertx.vertx() 统一为成员变量, 通过 @Before 创建并初始化,@After 关闭,避免资源泄漏。
This commit is contained in:
@@ -7,6 +7,8 @@ import cn.qaiu.parser.custom.CustomParserRegistry;
|
|||||||
import cn.qaiu.parser.customjs.JsParserExecutor;
|
import cn.qaiu.parser.customjs.JsParserExecutor;
|
||||||
import cn.qaiu.WebClientVertxInit;
|
import cn.qaiu.WebClientVertxInit;
|
||||||
import io.vertx.core.Vertx;
|
import io.vertx.core.Vertx;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -21,15 +23,26 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class JsParserTest {
|
public class JsParserTest {
|
||||||
|
|
||||||
|
private Vertx vertx;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
vertx = Vertx.vertx();
|
||||||
|
WebClientVertxInit.init(vertx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
if (vertx != null) {
|
||||||
|
vertx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsParserRegistration() {
|
public void testJsParserRegistration() {
|
||||||
// 清理注册表
|
// 清理注册表
|
||||||
CustomParserRegistry.clear();
|
CustomParserRegistry.clear();
|
||||||
|
|
||||||
// 初始化Vertx
|
|
||||||
Vertx vertx = Vertx.vertx();
|
|
||||||
WebClientVertxInit.init(vertx);
|
|
||||||
|
|
||||||
// 检查是否加载了JavaScript解析器
|
// 检查是否加载了JavaScript解析器
|
||||||
CustomParserConfig config = CustomParserRegistry.get("demo_js");
|
CustomParserConfig config = CustomParserRegistry.get("demo_js");
|
||||||
assert config != null : "JavaScript解析器未加载";
|
assert config != null : "JavaScript解析器未加载";
|
||||||
@@ -43,11 +56,7 @@ public class JsParserTest {
|
|||||||
public void testJsParserExecution() {
|
public void testJsParserExecution() {
|
||||||
// 清理注册表
|
// 清理注册表
|
||||||
CustomParserRegistry.clear();
|
CustomParserRegistry.clear();
|
||||||
|
|
||||||
// 初始化Vertx
|
|
||||||
Vertx vertx = Vertx.vertx();
|
|
||||||
WebClientVertxInit.init(vertx);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建解析器
|
// 创建解析器
|
||||||
IPanTool tool = ParserCreate.fromType("demo_js")
|
IPanTool tool = ParserCreate.fromType("demo_js")
|
||||||
@@ -74,11 +83,7 @@ public class JsParserTest {
|
|||||||
public void testJsParserFileList() {
|
public void testJsParserFileList() {
|
||||||
// 清理注册表
|
// 清理注册表
|
||||||
CustomParserRegistry.clear();
|
CustomParserRegistry.clear();
|
||||||
|
|
||||||
// 初始化Vertx
|
|
||||||
Vertx vertx = Vertx.vertx();
|
|
||||||
WebClientVertxInit.init(vertx);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建解析器
|
// 创建解析器
|
||||||
IPanTool tool = ParserCreate.fromType("demo_js")
|
IPanTool tool = ParserCreate.fromType("demo_js")
|
||||||
@@ -114,11 +119,7 @@ public class JsParserTest {
|
|||||||
public void testJsParserById() {
|
public void testJsParserById() {
|
||||||
// 清理注册表
|
// 清理注册表
|
||||||
CustomParserRegistry.clear();
|
CustomParserRegistry.clear();
|
||||||
|
|
||||||
// 初始化Vertx
|
|
||||||
Vertx vertx = Vertx.vertx();
|
|
||||||
WebClientVertxInit.init(vertx);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建ShareLinkInfo
|
// 创建ShareLinkInfo
|
||||||
Map<String, Object> otherParam = new HashMap<>();
|
Map<String, Object> otherParam = new HashMap<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user