Skip to content

Commit 72ea24a

Browse files
author
Tom Akehurst
committed
Set the async timeout to 5 minutes to avoid breaking stubs with longer delays (default was 30s)
1 parent 1fea787 commit 72ea24a

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

Diff for: src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public class JettyHttpServer implements HttpServer {
5858
private static final String FILES_URL_MATCH = String.format("/%s/*", WireMockApp.FILES_ROOT);
5959
private static final String[] GZIPPABLE_METHODS = new String[] { "POST", "PUT", "PATCH", "DELETE" };
6060

61+
static {
62+
System.setProperty("org.eclipse.jetty.server.HttpChannelState.DEFAULT_TIMEOUT", "300000");
63+
}
64+
6165
private final Server jettyServer;
6266
private final ServerConnector httpConnector;
6367
private final ServerConnector httpsConnector;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (C) 2011 Thomas Akehurst
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ignored;
17+
18+
import com.github.tomakehurst.wiremock.common.Json;
19+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
20+
import com.github.tomakehurst.wiremock.http.HttpClientFactory;
21+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
22+
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
23+
import org.apache.http.client.methods.CloseableHttpResponse;
24+
import org.apache.http.client.methods.RequestBuilder;
25+
import org.apache.http.entity.StringEntity;
26+
import org.apache.http.util.EntityUtils;
27+
import org.junit.Rule;
28+
import org.junit.Test;
29+
30+
import java.io.IOException;
31+
import java.util.concurrent.ExecutorService;
32+
import java.util.concurrent.Executors;
33+
34+
import static org.hamcrest.CoreMatchers.is;
35+
import static org.junit.Assert.assertThat;
36+
37+
public class VeryLongAsynchronousDelayAcceptanceTest {
38+
39+
@Rule
40+
public WireMockRule wireMockRule = new WireMockRule(getOptions());
41+
42+
private WireMockConfiguration getOptions() {
43+
WireMockConfiguration wireMockConfiguration = new WireMockConfiguration();
44+
wireMockConfiguration.jettyAcceptors(1).containerThreads(4);
45+
wireMockConfiguration.asynchronousResponseEnabled(true);
46+
wireMockConfiguration.asynchronousResponseThreads(10);
47+
wireMockConfiguration.dynamicPort();
48+
return wireMockConfiguration;
49+
}
50+
51+
52+
@Test
53+
public void longDelayWithBodyMatch() throws IOException {
54+
String json = "{ \"id\": \"cb7872bd-89cd-4015-97d1-718779df7dfe\", \"priority\": 1, \"request\": { \"urlPattern\": \"/faulty.*/.*/path/path\", \"method\": \"POST\", \"bodyPatterns\": [ { \"matches\": \".*<xml>permissions</xml>.*\" } ] }, \"response\": { \"status\": 200, \"bodyFileName\": \"plain-example.txt\", \"fixedDelayMilliseconds\": 35000 } }\n";
55+
56+
wireMockRule.addStubMapping(Json.read(json, StubMapping.class));
57+
58+
CloseableHttpResponse response = HttpClientFactory.createClient(50, 120000)
59+
.execute(RequestBuilder
60+
.post("http://localhost:" + wireMockRule.port() + "/faulty/1/path/path")
61+
.setEntity(new StringEntity("<xml>permissions</xml>"))
62+
.build()
63+
);
64+
65+
assertThat(response.getStatusLine().getStatusCode(), is(200));
66+
assertThat(EntityUtils.toString(response.getEntity()), is("Some example test from a file"));
67+
}
68+
69+
}

0 commit comments

Comments
 (0)