[NO ISSUE][TEST] Fix HttpServerTest
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Throw exception in case of request too large response
is received.
- Disable auto-retry on test http client.
Change-Id: Ica2a2cb0d79472174e7ac349a618bbd7d27b0086
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2829
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpRequestTask.java b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpRequestTask.java
index 2ab0229..78226ae 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpRequestTask.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpRequestTask.java
@@ -32,8 +32,8 @@
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import io.netty.handler.codec.http.HttpResponseStatus;
@@ -41,8 +41,8 @@
protected final HttpUriRequest request;
- protected HttpRequestTask(int size) throws URISyntaxException {
- request = post(null, size);
+ protected HttpRequestTask(int entitySize) throws URISyntaxException {
+ request = post(null, entitySize);
}
@Override
@@ -53,6 +53,8 @@
HttpServerTest.SUCCESS_COUNT.incrementAndGet();
} else if (response.getStatusLine().getStatusCode() == HttpResponseStatus.SERVICE_UNAVAILABLE.code()) {
HttpServerTest.UNAVAILABLE_COUNT.incrementAndGet();
+ } else if (response.getStatusLine().getStatusCode() == HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE.code()) {
+ throw new Exception(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE.reasonPhrase());
} else {
HttpServerTest.OTHER_COUNT.incrementAndGet();
}
@@ -73,7 +75,7 @@
}
protected HttpResponse executeHttpRequest(HttpUriRequest method) throws Exception {
- HttpClient client = HttpClients.custom().setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE).build();
+ HttpClient client = HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)).build();
try {
return client.execute(method);
} catch (Exception e) {
@@ -90,7 +92,7 @@
return builder.build();
}
- protected HttpUriRequest post(String query, int size) throws URISyntaxException {
+ protected HttpUriRequest post(String query, int entitySize) throws URISyntaxException {
URI uri = new URI(HttpServerTest.PROTOCOL, null, HttpServerTest.HOST, HttpServerTest.PORT, HttpServerTest.PATH,
query, null);
RequestBuilder builder = RequestBuilder.post(uri);
@@ -102,11 +104,13 @@
String statement = str.toString();
builder.setHeader("Content-type", "application/x-www-form-urlencoded");
builder.addParameter("statement", statement);
- for (int i = 0; i < size; i++) {
- str.append("This is a string statement that will be ignored");
- str.append('\n');
+ if (entitySize > 0) {
+ str.setLength(0);
+ for (int i = 0; i < entitySize; i++) {
+ str.append("x");
+ }
+ builder.setEntity(new StringEntity(str.toString(), StandardCharsets.UTF_8));
}
- builder.setEntity(new StringEntity(str.toString(), StandardCharsets.UTF_8));
builder.setCharset(StandardCharsets.UTF_8);
return builder.build();
}
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java
index 8867bb5..b5683ae 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/test/HttpServerTest.java
@@ -40,6 +40,7 @@
import org.apache.hyracks.http.server.WebManager;
import org.apache.hyracks.http.servlet.ChattyServlet;
import org.apache.hyracks.http.servlet.SleepyServlet;
+import org.apache.hyracks.util.StorageUtil;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -348,7 +349,8 @@
public void testLargeRequest() throws Exception {
WebManager webMgr = new WebManager();
// Server with max allowed request size = 512K
- final HttpServerConfig config = HttpServerConfigBuilder.custom().setMaxRequestSize(512 * 1024).build();
+ final int maxRequestSize = StorageUtil.getIntSizeInBytes(512, StorageUtil.StorageUnit.KILOBYTE);
+ final HttpServerConfig config = HttpServerConfigBuilder.custom().setMaxRequestSize(maxRequestSize).build();
HttpServer server = new HttpServer(webMgr.getBosses(), webMgr.getWorkers(), PORT, config);
ChattyServlet servlet = new ChattyServlet(server.ctx(), new String[] { PATH });
server.addServlet(servlet);
@@ -356,7 +358,7 @@
webMgr.start();
Exception failure = null;
try {
- request(1, 32000);
+ request(1, maxRequestSize + 1);
for (Future<Void> thread : FUTURES) {
thread.get();
}
@@ -375,12 +377,12 @@
}
private void request(int count) throws URISyntaxException {
- request(count, 32);
+ request(count, 0);
}
- private void request(int count, int size) throws URISyntaxException {
+ private void request(int count, int entitySize) throws URISyntaxException {
for (int i = 0; i < count; i++) {
- HttpRequestTask requestTask = new HttpRequestTask(size);
+ HttpRequestTask requestTask = new HttpRequestTask(entitySize);
Future<Void> next = executor.submit(requestTask);
FUTURES.add(next);
TASKS.add(requestTask);