thubbo / jmeter-plugins-for-apache-dubbo

Dubbo Plugin for Apache JMeter, It is a plug-in developed for testing Dubbo in Jmeter.
Apache License 2.0
565 stars 290 forks source link

Class<T>这种参数的类型要填什么呢?填java.lang.Class报错 #114

Closed githubnichen closed 4 years ago

githubnichen commented 4 years ago
T getUser(long userId, Class entityClass); 这是dubbo接口,jmeter中paramType填java.lang.Class,然后paramValue中填对应的实体类json数据,报错。报错信息: java.lang.IllegalArgumentException: Invalid parameter => [ParamType=java.lang.Class,ParamValue={"userId":null,"kkkk":null,"depodddsit":null,"cuisine":null,"housework":null,"liveWithParentsInLaw":null,"liveWithParents":null,"parents":null,"fondDate":null,"marryDate":null,"pets":null,"personality":null,"workAttitude":null,"familySituation":null,"interests":null,"finishSchool":null,"lastModTime":null,"createTime":null}] at io.github.ningyu.jmeter.plugin.util.ClassUtils.parseParameter(ClassUtils.java:227) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample.callDubbo(DubboSample.java:291) [jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample.sample(DubboSample.java:67) [jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_171] Caused by: java.lang.UnsupportedOperationException: Attempted to deserialize a java.lang.Class. Forgot to register a type adapter? at com.google.gson.internal.bind.TypeAdapters$1.read(TypeAdapters.java:77) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at com.google.gson.internal.bind.TypeAdapters$1.read(TypeAdapters.java:69) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at com.google.gson.Gson.fromJson(Gson.java:927) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at com.google.gson.Gson.fromJson(Gson.java:892) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at com.google.gson.Gson.fromJson(Gson.java:841) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at com.google.gson.Gson.fromJson(Gson.java:813) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at io.github.ningyu.jmeter.plugin.util.JsonUtils.formJson(JsonUtils.java:52) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] at io.github.ningyu.jmeter.plugin.util.ClassUtils.parseParameter(ClassUtils.java:209) ~[jmeter-plugins-dubbo-2.7.7-jar-with-dependencies.jar:?] ... 7 more
ningyu1 commented 4 years ago

@githubnichen 看这个https://github.com/thubbo/jmeter-plugins-for-apache-dubbo/wiki/FAQ#%E5%A4%8D%E6%9D%82%E5%8F%82%E6%95%B0%E4%BD%BF%E7%94%A8%E6%A1%88%E4%BE%8B

githubnichen commented 4 years ago

这个我看过了,但是我的接口是这种 T getUser(long userId, Class entityClass); 跟文档中的不一样。 Class entityClass这个参数的类型不知道要传什么?

ningyu1 commented 4 years ago

@githubnichen 第一个参数 type:long 值: long类型的值 第二个参数 type : entityClass的完全类名(包含包名) 值:{"属性":"值"}

githubnichen commented 4 years ago

试过了,不行呢。报找不到方法

githubnichen commented 4 years ago

这样传的话,会去找完全类名的方法,而找不到Class类型的方法

ningyu1 commented 4 years ago

找不到方法就两个问题,要么这个服务就没有注册到注册中心,要么就是通过参数类型和方法名称反射找不到方法(大多还是参数类型弄错了),去看api中的类方法描述

ningyu1 commented 4 years ago

直接写java.lang.Class 肯定不行,这个就是服务写的不规范,怎么会传入一个Class呢?

githubnichen commented 4 years ago

是第二种情况,但是接口是要求传Class类型的参数,如果传具体的类,会找不到方法

githubnichen commented 4 years ago
T getUser(long userId, Class entityClass); 接口就是这样
ningyu1 commented 4 years ago

Class 这个对象确实现在处理不了

githubnichen commented 4 years ago

这个Class后面有一个泛型T,打不上去

githubnichen commented 4 years ago

其实我就想知道是dubbo的泛型调用处理不了,还是这个插件没有处理这种情况呢

ningyu1 commented 4 years ago

插件没处理,目前插件支持的泛型是 xxx.XXXClass 这种方式

githubnichen commented 4 years ago

如果要处理这种情况的话,有什么思路吗?我看您是直接调用的$invoke,然后有具体的对象,再将其转为map处理

ningyu1 commented 4 years ago

这个用泛化不太能处理,Class太抽象,首先要知道那个具体的类型(xxxClass)然后再获取它的Class(大class描述类) 插件里面value的json要反序列化成目标对象(这里是具体的类对象不是描述类对象)所以作为通用的插件没发实现这个,除非你直接写javaclient sample定制写死。

githubnichen commented 4 years ago

正在直接写死。。。。。