我正在使用 RestAssured 2.8.0
我正在尝试设置自己的超时(用于网关超时),
因此,如果我在 X 毫秒后没有得到响应,我想中止。
I tried:
public static ValidatableResponse postWithConnectionConfig(String url, String body, RequestSpecification requestSpecification, ResponseSpecification responseSpecification) {
ConnectionConfig.CloseIdleConnectionConfig closeIdleConnectionConfig = new ConnectionConfig.CloseIdleConnectionConfig(1L, TimeUnit.MILLISECONDS);
ConnectionConfig connectionConfig = new ConnectionConfig(closeIdleConnectionConfig);
RestAssuredConfig restAssuredConfig = new RestAssuredConfig().connectionConfig(connectionConfig);
return given().specification(requestSpecification)
.body(body)
.config(restAssuredConfig)
.post(url)
.then()
.specification(responseSpecification);
}
or
ConnectionConfig connectionConfig = new ConnectionConfig()
.closeIdleConnectionsAfterEachResponseAfter(10L, TimeUnit.MILLISECONDS);
RestAssuredConfig restAssuredConfig = new RestAssuredConfig().connectionConfig(connectionConfig);
我也尝试添加
.queryParam("SO_TIMEOUT", 10)
or
.queryParam("CONNECTION_MANAGER_TIMEOUT", 10)
似乎没有什么作用。
它不会中止我的查询
您可以通过设置 HTTP 客户端参数来配置超时:
RestAssuredConfig config = RestAssured.config()
.httpClient(HttpClientConfig.httpClientConfig()
.setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000)
.setParam(CoreConnectionPNames.SO_TIMEOUT, 1000));
given().config(config).post("http://localhost:8884");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)