ASTERIXDB-1719 - Align HTTP Test Requests to $METHOD.http
Change-Id: I60958f77226f1afb2585baf9248682c4867758d8
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1341
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_1/cluster_state_1.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_1/cluster_state_1.1.get.http
similarity index 98%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_1/cluster_state_1.1.cstate.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_1/cluster_state_1.1.get.http
index 517b5b0..08577ae 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_1/cluster_state_1.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_1/cluster_state_1.1.get.http
@@ -22,3 +22,4 @@
* Expected Result : Success
* Date : 7th September 2016
*/
+/admin/cluster
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_2/cluster_state_2.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_2/cluster_state_2.1.get.http
similarity index 97%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_2/cluster_state_2.1.cstate.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_2/cluster_state_2.1.get.http
index b88aed8..a6414db 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_2/cluster_state_2.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_2/cluster_state_2.1.get.http
@@ -22,4 +22,4 @@
* Expected Result : Negative
* Date : 7th September 2016
*/
-/node/foo
+/admin/cluster/node/foo
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_3/cluster_state_3.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_3/cluster_state_3.1.cstate.aql
deleted file mode 100644
index 22b4a19..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_3/cluster_state_3.1.cstate.aql
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
- * Test case Name : cluster_state_3
- * Description : cluster state api all nodes
- * Expected Result : Positive
- * Date : 8th September 2016
- */
-/node
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_3/cluster_state_3.1.get.http
similarity index 97%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.cstate.aql
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_3/cluster_state_3.1.get.http
index 726f7e7..8291cb7 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_3/cluster_state_3.1.get.http
@@ -22,4 +22,4 @@
* Expected Result : Positive
* Date : 8th September 2016
*/
-/cc
+/admin/cluster/node
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_4/cluster_state_4.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_4/cluster_state_4.1.get.http
similarity index 96%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_4/cluster_state_4.1.cstate.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_4/cluster_state_4.1.get.http
index 0faba10..401f9a5 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_4/cluster_state_4.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_4/cluster_state_4.1.get.http
@@ -22,4 +22,4 @@
* Expected Result : Positive
* Date : 8th September 2016
*/
-/node/asterix_nc1
+/admin/cluster/node/asterix_nc1
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.get.http
similarity index 97%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.cstate.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.get.http
index 726f7e7..5f248e8 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_1/cluster_state_cc_1.1.get.http
@@ -22,4 +22,4 @@
* Expected Result : Positive
* Date : 8th September 2016
*/
-/cc
+/admin/cluster/cc
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.get.http
similarity index 97%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.cstate.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.get.http
index 1c6bab0..edc6363 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_cc_stats_1/cluster_state_cc_stats_1.1.get.http
@@ -22,4 +22,4 @@
* Expected Result : Positive
* Date : 8th September 2016
*/
-/cc/stats
+/admin/cluster/cc/stats
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_nc_threaddump_1/cluster_state_nc_threaddump_1.1.cstate.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_nc_threaddump_1/cluster_state_nc_threaddump_1.1.get.http
similarity index 95%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_nc_threaddump_1/cluster_state_nc_threaddump_1.1.cstate.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_nc_threaddump_1/cluster_state_nc_threaddump_1.1.get.http
index b1aa5d3..62cdfeb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_nc_threaddump_1/cluster_state_nc_threaddump_1.1.cstate.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/cluster_state_nc_threaddump_1/cluster_state_nc_threaddump_1.1.get.http
@@ -22,4 +22,4 @@
* Expected Result : Positive
* Date : 8th September 2016
*/
-/node/asterix_nc2/threaddump
+/admin/cluster/node/asterix_nc2/threaddump
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/diagnostics_1/diagnostics_1.1.httpapi.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/diagnostics_1/diagnostics_1.1.get.http
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/diagnostics_1/diagnostics_1.1.httpapi.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/diagnostics_1/diagnostics_1.1.get.http
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/replication/replication.1.httpapi.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/replication/replication.1.get.http
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/replication/replication.1.httpapi.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/replication/replication.1.get.http
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/version_1/version_1.1.version.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/version_1/version_1.1.get.http
similarity index 98%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/version_1/version_1.1.version.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/version_1/version_1.1.get.http
index 6a75528..0e6b893 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/version_1/version_1.1.version.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/version_1/version_1.1.get.http
@@ -22,3 +22,4 @@
* Expected Result : Success
* Date : 8th September 2016
*/
+/admin/version
\ No newline at end of file
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
index 0a1ad14..c6da1c0 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
@@ -371,6 +371,9 @@
// For tests where you simply want the byte-for-byte output.
private static void writeOutputToFile(File actualFile, InputStream resultStream) throws Exception {
+ if (!actualFile.getParentFile().mkdirs()) {
+ LOGGER.warning("Unable to create actual file parent dir: " + actualFile.getParentFile());
+ }
try (FileOutputStream out = new FileOutputStream(actualFile)) {
IOUtils.copy(resultStream, out);
}
@@ -454,11 +457,21 @@
params.add(formatParam);
}
+ private List<CompilationUnit.Parameter> injectStatement(String statement, String stmtParamName,
+ List<CompilationUnit.Parameter> otherParams) {
+ CompilationUnit.Parameter stmtParam = new CompilationUnit.Parameter();
+ stmtParam.setName(stmtParamName);
+ stmtParam.setValue(statement);
+ List<CompilationUnit.Parameter> params = new ArrayList<>(otherParams);
+ params.add(stmtParam);
+ return params;
+ }
+
private HttpUriRequest constructHttpMethod(String statement, String endpoint, String stmtParam,
boolean postStmtAsParam, List<CompilationUnit.Parameter> otherParams) {
if (statement.length() + endpoint.length() < MAX_URL_LENGTH) {
// Use GET for small-ish queries
- return constructGetMethod(statement, endpoint, stmtParam, otherParams);
+ return constructGetMethod(endpoint, injectStatement(statement, stmtParam, otherParams));
} else {
// Use POST for bigger ones to avoid 413 FULL_HEAD
String stmtParamName = (postStmtAsParam ? stmtParam : null);
@@ -466,21 +479,47 @@
}
}
- private HttpUriRequest constructGetMethod(String statement, String endpoint, String stmtParam,
- List<CompilationUnit.Parameter> otherParams) {
- RequestBuilder builder = RequestBuilder.get(endpoint).addParameter(stmtParam, statement);
- for (CompilationUnit.Parameter param : otherParams) {
+ private HttpUriRequest constructGetMethod(String endpoint, List<CompilationUnit.Parameter> params) {
+ RequestBuilder builder = RequestBuilder.get(endpoint);
+ for (CompilationUnit.Parameter param : params) {
builder.addParameter(param.getName(), param.getValue());
}
builder.setCharset(StandardCharsets.UTF_8);
return builder.build();
}
+ private HttpUriRequest constructGetMethod(String endpoint, OutputFormat fmt,
+ List<CompilationUnit.Parameter> params) {
+
+ HttpUriRequest method = constructGetMethod(endpoint, params);
+ // Set accepted output response type
+ method.setHeader("Accept", fmt.mimeType());
+ return method;
+ }
+
+ private HttpUriRequest constructPostMethod(String endpoint, List<CompilationUnit.Parameter> params) {
+ RequestBuilder builder = RequestBuilder.post(endpoint);
+ for (CompilationUnit.Parameter param : params) {
+ builder.addParameter(param.getName(), param.getValue());
+ }
+ builder.setCharset(StandardCharsets.UTF_8);
+ return builder.build();
+ }
+
+ private HttpUriRequest constructPostMethod(String endpoint, OutputFormat fmt,
+ List<CompilationUnit.Parameter> params) {
+
+ HttpUriRequest method = constructPostMethod(endpoint, params);
+ // Set accepted output response type
+ method.setHeader("Accept", fmt.mimeType());
+ return method;
+ }
+
protected HttpUriRequest constructPostMethodUrl(String statement, String endpoint, String stmtParam,
List<CompilationUnit.Parameter> otherParams) {
RequestBuilder builder = RequestBuilder.post(endpoint);
if (stmtParam != null) {
- for (CompilationUnit.Parameter param : otherParams) {
+ for (CompilationUnit.Parameter param : injectStatement(statement, stmtParam, otherParams)) {
builder.addParameter(param.getName(), param.getValue());
}
builder.addParameter(stmtParam, statement);
@@ -500,8 +539,7 @@
RequestBuilder builder = RequestBuilder.post(endpoint);
JSONObject content = new JSONObject();
try {
- content.put(stmtParam, statement);
- for (CompilationUnit.Parameter param : otherParams) {
+ for (CompilationUnit.Parameter param : injectStatement(statement, stmtParam, otherParams)) {
content.put(param.getName(), param.getValue());
}
} catch (JSONException e) {
@@ -513,8 +551,13 @@
}
public InputStream executeJSONGet(OutputFormat fmt, String url) throws Exception {
- HttpUriRequest request = RequestBuilder.get(url).setHeader("Accept", fmt.mimeType()).build();
+ HttpUriRequest request = constructGetMethod(url, fmt, new ArrayList<>());
+ HttpResponse response = executeAndCheckHttpRequest(request);
+ return response.getEntity().getContent();
+ }
+ public InputStream executeJSONPost(OutputFormat fmt, String url) throws Exception {
+ HttpUriRequest request = constructPostMethod(url, fmt, new ArrayList<>());
HttpResponse response = executeAndCheckHttpRequest(request);
return response.getEntity().getContent();
}
@@ -765,7 +808,6 @@
File actualResultFile = testCaseCtx.getActualResultFile(cUnit, expectedResultFile,
new File(actualPath));
- actualResultFile.getParentFile().mkdirs();
writeOutputToFile(actualResultFile, resultStream);
runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), expectedResultFile,
@@ -782,7 +824,6 @@
resultStream = executeQuery(statement, OutputFormat.forCompilationUnit(cUnit),
getEndpoint(Servlets.AQL_QUERY), cUnit.getParameter());
qbcFile = getTestCaseQueryBeforeCrashFile(actualPath, testCaseCtx, cUnit);
- qbcFile.getParentFile().mkdirs();
writeOutputToFile(qbcFile, resultStream);
break;
case "txnqar": // qar represents query after recovery
@@ -791,7 +832,6 @@
File qarFile = new File(actualPath + File.separator
+ testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_" + cUnit.getName()
+ "_qar.adm");
- qarFile.getParentFile().mkdirs();
writeOutputToFile(qarFile, resultStream);
qbcFile = getTestCaseQueryBeforeCrashFile(actualPath, testCaseCtx, cUnit);
runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), qbcFile, qarFile);
@@ -859,36 +899,26 @@
throw new Exception(output);
}
break;
- case "cstate": // cluster state query
+ case "get":
+ case "post":
+ if (!"http".equals(ctx.extension())) {
+ throw new IllegalArgumentException("Unexpected format for method " + ctx.getType() + ": "
+ + ctx.extension());
+ }
fmt = OutputFormat.forCompilationUnit(cUnit);
- String extra = stripJavaComments(statement).trim();
- resultStream = executeJSONGet(fmt, getEndpoint(Servlets.CLUSTER_STATE) + extra);
+ String endpoint = stripJavaComments(statement).trim();
+ switch (ctx.getType()) {
+ case "get":
+ resultStream = executeJSONGet(fmt, "http://" + host + ":" + port + endpoint);
+ break;
+ case "post":
+ resultStream = executeJSONPost(fmt, "http://" + host + ":" + port + endpoint);
+ break;
+ default:
+ throw new IllegalStateException("NYI: " + ctx.getType());
+ }
expectedResultFile = expectedResultFileCtxs.get(queryCount.intValue()).getFile();
actualResultFile = testCaseCtx.getActualResultFile(cUnit, expectedResultFile, new File(actualPath));
- actualResultFile.getParentFile().mkdirs();
- writeOutputToFile(actualResultFile, resultStream);
- runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), expectedResultFile,
- actualResultFile);
- queryCount.increment();
- break;
- case "version": // version servlet
- fmt = OutputFormat.forCompilationUnit(cUnit);
- resultStream = executeJSONGet(fmt, getEndpoint(Servlets.VERSION));
- expectedResultFile = expectedResultFileCtxs.get(queryCount.intValue()).getFile();
- actualResultFile = testCaseCtx.getActualResultFile(cUnit, expectedResultFile, new File(actualPath));
- actualResultFile.getParentFile().mkdirs();
- writeOutputToFile(actualResultFile, resultStream);
- runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), expectedResultFile,
- actualResultFile);
- queryCount.increment();
- break;
- case "httpapi": // http api
- fmt = OutputFormat.forCompilationUnit(cUnit);
- extra = stripJavaComments(statement).trim();
- resultStream = executeJSONGet(fmt, "http://" + host + ":" + port + extra);
- expectedResultFile = expectedResultFileCtxs.get(queryCount.intValue()).getFile();
- actualResultFile = testCaseCtx.getActualResultFile(cUnit, expectedResultFile, new File(actualPath));
- actualResultFile.getParentFile().mkdirs();
writeOutputToFile(actualResultFile, resultStream);
runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), expectedResultFile,
actualResultFile);
diff --git a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestFileContext.java b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestFileContext.java
index 74a607d..e41a624 100644
--- a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestFileContext.java
+++ b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestFileContext.java
@@ -39,6 +39,12 @@
return type;
}
+ public String extension() {
+ final String name = file.getName();
+ int lastDot = name.lastIndexOf('.');
+ return lastDot == -1 ? name : name.substring(lastDot + 1);
+ }
+
public void setType(String type) {
this.type = type;
}