1
0
mirror of synced 2025-12-21 08:30:11 +08:00

🎨 优化代码

This commit is contained in:
Binary Wang
2020-09-26 16:15:56 +08:00
parent 5ecfaf7cd0
commit 1d7344309a
67 changed files with 277 additions and 234 deletions

View File

@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import org.testng.annotations.*;
@@ -25,7 +26,7 @@ public class WxMpBusyRetryTest {
RequestExecutor<T, E> executor, String uri, E data)
throws WxErrorException {
log.info("Executed");
throw new WxErrorException(WxError.builder().errorCode(-1).build());
throw new WxErrorException("something");
}
};
@@ -43,18 +44,15 @@ public class WxMpBusyRetryTest {
public void testRetryInThreadPool(final WxMpService service) throws InterruptedException, ExecutionException {
// 当线程池中的线程复用的时候,还是能保证相同的重试次数
ExecutorService executorService = Executors.newFixedThreadPool(1);
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println("=====================");
System.out.println(Thread.currentThread().getName() + ": testRetry");
service.execute(null, (String)null, null);
} catch (WxErrorException e) {
throw new RuntimeException(e);
} catch (RuntimeException e) {
// OK
}
Runnable runnable = () -> {
try {
System.out.println("=====================");
System.out.println(Thread.currentThread().getName() + ": testRetry");
service.execute(null, (String)null, null);
} catch (WxErrorException e) {
throw new WxRuntimeException(e);
} catch (RuntimeException e) {
// OK
}
};
Future<?> submit1 = executorService.submit(runnable);

View File

@@ -97,14 +97,11 @@ public class WxMpMessageRouterTest {
}).end();
final WxMpXmlMessage m = new WxMpXmlMessage();
Runnable r = new Runnable() {
@Override
public void run() {
router.route(m);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
Runnable r = () -> {
router.route(m);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
};
for (int i = 0; i < 10; i++) {

View File

@@ -82,15 +82,12 @@ public class BaseWxMpServiceImplTest {
// 测试多线程刷新accessToken时是否重复刷新
wxService.getWxMpConfigStorage().expireAccessToken();
final Set<String> set = Sets.newConcurrentHashSet();
Runnable r = new Runnable() {
@Override
public void run() {
try {
String accessToken = wxService.getAccessToken();
set.add(accessToken);
} catch (WxErrorException e) {
e.printStackTrace();
}
Runnable r = () -> {
try {
String accessToken = wxService.getAccessToken();
set.add(accessToken);
} catch (WxErrorException e) {
e.printStackTrace();
}
};

View File

@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,7 +24,7 @@ public class ApiTestModule implements Module {
public void configure(Binder binder) {
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
if (inputStream == null) {
throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到请参照test-config-sample.xml文件生成");
throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到请参照test-config-sample.xml文件生成");
}
TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);