Skip to content

Commit 3ff8fb7

Browse files
committed
Avoid all caching in DevModeClient
Hoping it could stabilize DevMojoIT.
1 parent c302b63 commit 3ff8fb7

File tree

1 file changed

+29
-4
lines changed
  • test-framework/devmode-test-utils/src/main/java/io/quarkus/test/devmode/util

1 file changed

+29
-4
lines changed

test-framework/devmode-test-utils/src/main/java/io/quarkus/test/devmode/util/DevModeClient.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.io.IOException;
88
import java.net.HttpURLConnection;
9+
import java.net.MalformedURLException;
910
import java.net.URL;
1011
import java.nio.charset.StandardCharsets;
1112
import java.time.Instant;
@@ -157,6 +158,7 @@ public String getHttpResponse(String path, boolean allowError, Supplier<String>
157158
public String getHttpResponse(String path, boolean allowError, Supplier<String> brokenReason, long timeout,
158159
TimeUnit tu) {
159160
AtomicReference<String> resp = new AtomicReference<>();
161+
160162
await()
161163
.pollDelay(1, TimeUnit.SECONDS)
162164
.atMost(timeout, tu).until(() -> {
@@ -166,20 +168,25 @@ public String getHttpResponse(String path, boolean allowError, Supplier<String>
166168
return true;
167169
}
168170
try {
169-
URL url = new URL("http://localhost:" + port + ((path.startsWith("/") ? path : "/" + path)));
171+
URL url = prepareUrl(path);
172+
170173
String content;
171174
if (!allowError) {
172175
content = IOUtils.toString(url, StandardCharsets.UTF_8);
173176
} else {
174177
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
178+
conn.setDefaultUseCaches(false);
179+
conn.setUseCaches(false);
175180
// the default Accept header used by HttpURLConnection is not compatible with RESTEasy negotiation as it uses q=.8
176181
conn.setRequestProperty("Accept", "text/html, *; q=0.2, */*; q=0.2");
177182
if (conn.getResponseCode() >= 400) {
178183
content = IOUtils.toString(conn.getErrorStream(), StandardCharsets.UTF_8);
179184
} else {
180185
content = IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8);
181186
}
187+
conn.disconnect();
182188
}
189+
183190
resp.set(content);
184191
return true;
185192
} catch (Exception e) {
@@ -203,8 +210,10 @@ public boolean getHttpResponse(String path, int expectedStatus, long timeout, Ti
203210
.pollDelay(1, TimeUnit.SECONDS)
204211
.atMost(timeout, tu).until(() -> {
205212
try {
206-
URL url = new URL("http://localhost:" + port + ((path.startsWith("/") ? path : "/" + path)));
213+
URL url = prepareUrl(path);
207214
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
215+
connection.setDefaultUseCaches(false);
216+
connection.setUseCaches(false);
208217
// the default Accept header used by HttpURLConnection is not compatible with RESTEasy negotiation as it uses q=.2
209218
connection.setRequestProperty("Accept", "text/html, *; q=0.2, */*; q=0.2");
210219
if (connection.getResponseCode() == expectedStatus) {
@@ -230,8 +239,10 @@ public boolean getStrictHttpResponse(String path, int expectedStatus) {
230239
.pollDelay(1, TimeUnit.SECONDS)
231240
.atMost(5, TimeUnit.MINUTES).until(() -> {
232241
try {
233-
URL url = new URL("http://localhost:" + port + ((path.startsWith("/") ? path : "/" + path)));
242+
URL url = prepareUrl(path);
234243
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
244+
connection.setDefaultUseCaches(false);
245+
connection.setUseCaches(false);
235246
// the default Accept header used by HttpURLConnection is not compatible with RESTEasy negotiation as it uses q=.2
236247
connection.setRequestProperty("Accept", "text/html, *; q=0.2, */*; q=0.2");
237248
code.set(connection.getResponseCode() == expectedStatus);
@@ -258,8 +269,10 @@ public String get(String urlStr) throws IOException {
258269

259270
public boolean isCode(String path, int code) {
260271
try {
261-
URL url = new URL("http://localhost:" + port + ((path.startsWith("/") ? path : "/" + path)));
272+
URL url = prepareUrl(path);
262273
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
274+
connection.setDefaultUseCaches(false);
275+
connection.setUseCaches(false);
263276
// the default Accept header used by HttpURLConnection is not compatible with
264277
// RESTEasy negotiation as it uses q=.2
265278
connection.setRequestProperty("Accept", "text/html, *; q=0.2, */*; q=0.2");
@@ -268,4 +281,16 @@ public boolean isCode(String path, int code) {
268281
return false;
269282
}
270283
}
284+
285+
private URL prepareUrl(String path) throws MalformedURLException {
286+
String urlString = "http://localhost:" + port + (path.startsWith("/") ? path : "/" + path);
287+
if (urlString.contains("?")) {
288+
urlString += "&";
289+
} else {
290+
urlString += "?";
291+
}
292+
urlString += "_test_timestamp=" + System.currentTimeMillis();
293+
294+
return new URL(urlString);
295+
}
271296
}

0 commit comments

Comments
 (0)