JMeter of JavaRequest inquiry

1. Background

Recently I consulted an old friend of a problem: how to write multiple requests in the request in a custom Java? They can only send a request old reaction based on such a request in the form of Java (code modulation required jar package encapsulated constituents). This problem happened recently in the author's flight test QQ group , someone consulted, there were only answered with SubResult.

2. The purpose

The goal is to dig deep under: JMeter of JavaRequest request over how to write a SamplerResult.

3. combat

Before I have repeatedly written request Java script, this time on how to build and Java scripting environment which agreed to the request in good structural article does not say, everyone under their own Baidu. In fact, mainly talking about the idea, including the most after I wrote the article is mainly about ideas to solve problems.

  • Encountered this problem, I first thought is SubResult (because long-term study author JMeter underlying source code)

And then began to roll up the code:

image_thumb4

image_thumb13[4]

Well, I feel very perfect! However, after the execution:

image_thumb15

Seen from the figure, it threw out : sampleEnd Called Twice abnormal, I will do the fine-tuning the code:

image_thumb21

Well, the feeling should be no problem, the next again:

image_thumb24

I rub, loud noise and the error. . . The reported setEndTime the MUST BE Called the After setStartTime , so I looked JMeter underlying code to see where this exception thrown. As shown below:

image_thumb28

Well? StartTime value of zero will throw this exception, I feel more and more interesting. With this question I went to see the JMeter API documentation, this discovery led to the murderers of this phenomenon.

image_thumb30

When the return translator:

addRawSubResult(SampleResult subResult) The results add a child to the collection without updating any parent field.
addSubResult(SampleResult subResult) Was added to adjust the parent and child result byte count and end time.
addSubResult(SampleResult subResult, boolean renameSubResults) Was added to adjust the parent and child result byte count and end time.

We used the code is addSubResult ( SampleResult subResult, boolean renameSubResults), it also adjusted the Code:

image_thumb33

Results of the:

image_thumb35

ok, successful execution (Log4j2 appear abnormal because the author is not configured log4j2.xml, do not care about the details), but the overall feeling or what I have more real drawback to micro-changed under the code?:

image_thumb47

image_thumb50

OKay, packed into JMeter runs as follows:

image_thumb53

image_thumb55

When I look at polymerization report, they encountered a problem. . .

image_thumb62

Yep? Show only parent request aggregated data, Why do not display the sub-request data it? I now found the solution is: When executed first save the file to see the results of JTL, the end of the scene to open this file with JTL results polymerization report again.

image_thumb65

okay, eventually solve the problem. . . If you find a better solution, please let us know!

Guess you like

Origin www.cnblogs.com/leebaul/p/11369776.html