【发布时间】:2019-07-27 10:35:15
【问题描述】:
我有一个设置线程组,它点击一个 url 并获得很多产品 id。
/product/4564
/product/4534
/product/1234
....
我将它保存在这样的属性中:
// Using jsr223
import org.apache.http.HttpHeaders;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.StringEntity;
import com.google.gson.Gson;
List<String> sendRequest(String url, String method, Map<String,Object> body) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(2000)
.setSocketTimeout(3000)
.build();
StringEntity entity = new StringEntity(new Gson().toJson(body), "UTF-8");
HttpUriRequest request = RequestBuilder.create(method)
.setConfig(requestConfig)
.setUri(url)
.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8")
.setEntity(entity)
.build();
HttpClientBuilder.create().build().withCloseable {httpClient ->
httpClient.execute(request).withCloseable {response ->
String res = response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "";
return Arrays.asList("result", res);
}
}
}
Map<String,Object> map = new LinkedHashMap<>();
SampleResult.setIgnore();
def test1 = sendRequest("localhost:8080/product/list","GET", map);
ArrayList pathProduct = Arrays.toString(test1.get(1))
props.put("myProperty", pathProduct)
然后我在另一个线程组中有一个吞吐量控制器,这就是使用属性而不是变量的原因。我读到,如果我使用一个变量,将不会在另一个线程上可用。
然后我有一个Http请求,我这样设置:
protocol: http
server: localhost
path: ${__groovy(props.get("myProperty"))}
它部分有效,因为我只得到 1 个 url 而不是 N,我得到的 url 是:
http://localhost/product/4564/product/4534/product/1234
我想得到:
http://localhost/product/4564
http://localhost/product/4534
http://localhost/product/1234
.....
有什么想法吗?提前致谢
【问题讨论】: