Search in sources :

Example 1 with AsyncInvoker

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;
}
Also used : AsyncInvoker(cn.moyada.dubbo.faker.core.invoke.AsyncInvoker) LoggingListener(cn.moyada.dubbo.faker.core.listener.LoggingListener) AbstractInvoker(cn.moyada.dubbo.faker.core.invoke.AbstractInvoker) MethodInvokeDO(cn.moyada.dubbo.faker.core.model.MethodInvokeDO) CompletedListener(cn.moyada.dubbo.faker.core.listener.CompletedListener) ParamProvider(cn.moyada.dubbo.faker.core.provider.ParamProvider) MethodProxy(cn.moyada.dubbo.faker.core.model.MethodProxy)

Aggregations

AbstractInvoker (cn.moyada.dubbo.faker.core.invoke.AbstractInvoker)1 AsyncInvoker (cn.moyada.dubbo.faker.core.invoke.AsyncInvoker)1 CompletedListener (cn.moyada.dubbo.faker.core.listener.CompletedListener)1 LoggingListener (cn.moyada.dubbo.faker.core.listener.LoggingListener)1 MethodInvokeDO (cn.moyada.dubbo.faker.core.model.MethodInvokeDO)1 MethodProxy (cn.moyada.dubbo.faker.core.model.MethodProxy)1 ParamProvider (cn.moyada.dubbo.faker.core.provider.ParamProvider)1