您可能知道在HTTP标头中发送分块文件,没有内容长度,因此程序必须等待0才能理解该文件已结束.
--sample http header
POST /some/path HTTP/1.1
Host: www.example.com
Content-Type: text/plain
Transfer-Encoding: chunked
25
This is the data in the first chunk
8
sequence
0
Run Code Online (Sandbox Code Playgroud)
为了接收该文件,可以使用以下代码.
ResponseHandler<String> reshandler = new ResponseHandler<String>() {
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
byte[] b = new byte[500];
StringBuffer out = new StringBuffer();
int len = in.read(b);
out.append(new String(b, 0 , len));
return out.toString();
}
};
Run Code Online (Sandbox Code Playgroud)
但在我的情况下,我使用流媒体通道,换句话说没有0表明文件已经结束.无论如何,如果我使用这个代码,它似乎永远等待0永远不会发生.我的问题是有没有更好的方法从流通道接收分块文件?
我计划重用VS Load Test的现有Specflow场景(目前用于验收和自动测试),以避免重复和额外的工作.Specflow适用于那些测试,因为它运行它们一次,但是在Load测试的上下文中,当它执行每个Specflow场景多次并且并行它会遇到问题和错误并且用户数量更多时会得到更多
这些错误可能会导致部分测试失败,最终会产生不正确的测试结果,例如使用一个Specflow场景作为测试场景,负载测试为20个用户,时间段为2分钟,可能导致50个类似于下面的错误.因此测试结果显示特定场景执行200次,其中150次通过,50次失败测试,失败是由Specflow错误引起的.在负载测试的上下文中,由于测试本身存在问题,因此该结果完全错误且不正确.
错误信息:
ScenarioTearDown threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.HandleBlockSwitch(ScenarioBlock block)
TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance) TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.Step(StepDefinitionKeyword stepDefinitionKeyword, String keyword, String text, String multilineTextArg, Table tableArg)
TechTalk.SpecFlow.TestRunner.Then(String text, String multilineTextArg, Table tableArg, String keyword)
Run Code Online (Sandbox Code Playgroud)
经过一些调查后,似乎Specflow无法生成和运行相同的方案并行导致此冲突并且未通过一些测试但我也对此有一些疑问,并试图查看是否有任何解决方法或如果我遗漏任何东西并想知道是否Specflow场景可以用于负载测试吗?