首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有gRPC Java客户端和BeanShell采样器的JMeter

带有gRPC Java客户端和BeanShell采样器的JMeter
EN

Stack Overflow用户
提问于 2020-12-27 15:23:43
回答 1查看 117关注 0票数 0

为什么不能在JMeter的BeanShell采样器之外运行这个原生Java gRPC客户端:

代码语言:javascript
复制
package at.fhj.swd.grpc.client;

import at.fhj.swd.grpc.CalcRequest;
import at.fhj.swd.grpc.CalcResponse;
import at.fhj.swd.grpc.CalcServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class GrpcClient {

public static void calc() {
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9090)
            .usePlaintext()
            .build();

    CalcServiceGrpc.CalcServiceBlockingStub stub
            = CalcServiceGrpc.newBlockingStub(channel);
    CalcResponse calcResponse = stub.calc(CalcRequest.newBuilder()
            .setNumber(7)
            .build());

    channel.shutdown();

    System.out.println(calcResponse.getResultList());
    }
}

BeanShell采样器脚本无法创建GrpcCient的实例。(引用的方法调用)

代码语言:javascript
复制
import at.fhj.swd.grpc.client.GrpcClient;

GrpcClient grpcClient = new GrpcClient();

//grpcClient.calc();

错误:

代码语言:javascript
复制
Response code:500
Response message:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval   io/grpc/Channel

似乎导入出了问题,但是为什么呢?如果在没有JMeter的情况下执行客户端,则客户端将运行。

EN

回答 1

Stack Overflow用户

发布于 2020-12-27 17:51:11

  1. Beanshell
    1. Beanshell不是100%兼容的,所以如果有重载的函数/构造函数,你需要通过reflection
    2. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy显式地指定你想要的函数/构造函数,所以从语言下拉列表中选择groovy就足够了,你的代码就会按预期开始工作。此外,与Beanshell相比,

    具有更好的性能,有关

Groovy的更多详细信息,请参阅Apache Groovy - Why and How You Should Use It文章

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65463657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档