Jmeter protobuf testing. Could not read Protobuf message

青春壹個敷衍的年華 提交于 2019-12-06 10:25:00

I'm fairly convinced your issue is that you're losing some non-printable characters while converting from binary stream to String and then back. I'm thinking of two possible workarounds:

  1. Write the binary data to a file instead of saving to string, and then use the filename as variable in the HTTP sampler, in the body from file section

  2. Use a beanshell sampler, and construct your own HTTPClient object and POST request, with the binary data in body and fire it yourself instead of using the HTTP sampler

I don't like the first option because of all the additional file I/O. I do not like the second option because measuring response time will now include all the request assembly you're doing in beanshell - so you'll have to pick the one that bothers you less I guess.

Let me know if you want me to write up some code examples for either case.

Edit: For beanshell HTTP call using HttpClient 4:

import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;

byte[] data = null;
//...assign protobuf binary buffer to data...

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://127.0.0.1");
HttpEntity entity = new ByteArrayEntity(data);
post.setEntity(entity);
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
HttpResponse response=null;
try {
    response = client.execute(post);
} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

ResponseCode = response.getStatusLine().getStatusCode().toString();
//if some assert is true then
Issuccess = true;
ResponseMessage="Some Response Message";

This is untested against a protobuf end point, let me know how it works out for you.

On high loads Beanshell interpreter can be the cause of unexpected behaviour as it has some performance problems. Try switching to JSR223 PreProcessor and use groovy as a language. Groovy scripting engine implements Compilable interface hence given you follow some simple rules you can achieve best performance and your problem can go away.

See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for groovy engine installation instructions, scripting best practices and Beanshell versus Groovy benchmark.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!