use of cn.moyada.dubbo.faker.core.invoke.AsyncInvoker in project dubbo-faker by moyada.
the class FakerRequest method request.
public String request(int invokeId, String invokeExpression, int poolSize, int qps, int questNum, boolean random, boolean saveResult, String resultParam) {
MethodInvokeDO invokeInfo = fakerManager.getInvokeInfo(invokeId);
// , poolSize);
MethodProxy proxy = methodHandleProxy.getProxy(invokeInfo);
Object[] values = JsonUtil.toArray(invokeExpression, Object[].class);
Class<?>[] paramTypes = proxy.getParamTypes();
if (null == values || paramTypes.length != values.length) {
throw InitializeInvokerException.paramError;
}
// 生成调用报告序号
String fakerId = UUIDUtil.getUUID();
// 参数提供器
ParamProvider paramProvider = new ParamProvider(fakerManager, values, paramTypes, random);
// 创建调用结果监听器
CompletedListener listener = new LoggingListener(fakerId, invokeId, fakerManager, saveResult, resultParam);
// 创建方法调用器
AbstractInvoker invoke = new AsyncInvoker(proxy.getMethodHandle(), proxy.getService(), listener, poolSize);
int timeout = (3600 / qps) - (10 >= qps ? 0 : 20);
// 发起调用
if (timeout > 50) {
log.info("start timeout faker invoke: " + fakerId);
for (int index = 0; index < questNum; index++) {
invoke.invoke(paramProvider.fetchNextParam());
LockSupport.parkNanos(timeout * 1000);
}
} else {
log.info("start faker invoke: " + fakerId);
for (int index = 0; index < questNum; index++) {
invoke.invoke(paramProvider.fetchNextParam());
}
}
invoke.destroy();
log.info("faker invoke done: " + fakerId);
listener.shutdownDelay();
log.info("logging shutdown: " + fakerId);
return "请求结果序号:" + fakerId;
}
Aggregations