[NO ISSUE][TEST] Allow Requests To NC Endpoints By Port
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Currently, the test framework allows sending requests to
NC endpoints that are referenced by name if that name was
added to the list of available NC endpoints. This change
allows a request to be sent to any endpoint by specifying
the endpoint port in the test file.
- Modify a test case to utilize port-based NC endpoints.
Change-Id: If0ad80bed625c45da01aa018e4267409c329be9e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2991
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: 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/java/org/apache/asterix/test/common/TestExecutor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
index b143ea9..98cd668 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
@@ -31,6 +31,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Inet4Address;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
@@ -135,6 +136,7 @@
private static final Pattern MAX_RESULT_READS_PATTERN =
Pattern.compile("maxresultreads=(\\d+)(\\D|$)", Pattern.MULTILINE);
private static final Pattern HTTP_REQUEST_TYPE = Pattern.compile("requesttype=(.*)", Pattern.MULTILINE);
+ private static final String NC_ENDPOINT_PREFIX = "nc:";
public static final int TRUNCATE_THRESHOLD = 16384;
public static final Set<String> NON_CANCELLABLE =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("store", "validate")));
@@ -1723,16 +1725,25 @@
protected URI createEndpointURI(String path, String query) throws URISyntaxException {
InetSocketAddress endpoint;
- if (!path.startsWith("nc:")) {
+ if (isCcEndPointPath(path)) {
int endpointIdx = Math.abs(endpointSelector++ % endpoints.size());
endpoint = endpoints.get(endpointIdx);
} else {
+ // allowed patterns: [nc:endpointName URL] or [nc:nodeId:port URL]
final String[] tokens = path.split(" ");
if (tokens.length != 2) {
throw new IllegalArgumentException("Unrecognized http pattern");
}
- String nodeId = tokens[0].substring(3);
- endpoint = getNcEndPoint(nodeId);
+ final String endpointName = tokens[0].substring(NC_ENDPOINT_PREFIX.length());
+ if (containsPort(endpointName)) {
+ // currently only loopback address is supported in the test framework
+ final String nodeIP = InetAddress.getLoopbackAddress().getHostAddress();
+ final String endpointParts[] = StringUtils.split(endpointName, ':');
+ int port = Integer.valueOf(endpointParts[1]);
+ endpoint = new InetSocketAddress(nodeIP, port);
+ } else {
+ endpoint = getNcEndPoint(endpointName);
+ }
path = tokens[1];
}
URI uri = new URI("http", null, endpoint.getHostString(), endpoint.getPort(), path, query, null);
@@ -1873,11 +1884,11 @@
Assert.assertEquals(HttpStatus.SC_OK, httpResponse.getStatusLine().getStatusCode());
}
- private InetSocketAddress getNcEndPoint(String nodeId) {
- if (ncEndPoints == null || !ncEndPoints.containsKey(nodeId)) {
- throw new IllegalStateException("No end point specified for node: " + nodeId);
+ private InetSocketAddress getNcEndPoint(String name) {
+ if (ncEndPoints == null || !ncEndPoints.containsKey(name)) {
+ throw new IllegalStateException("No end point specified for node: " + name);
}
- return ncEndPoints.get(nodeId);
+ return ncEndPoints.get(name);
}
private InetSocketAddress getNcReplicationAddress(String nodeId) {
@@ -1978,4 +1989,12 @@
private static String toQueryServiceHandle(String handle) {
return handle.replace("/aql/", "/service/");
}
+
+ private static boolean isCcEndPointPath(String endPoint) {
+ return !endPoint.startsWith(NC_ENDPOINT_PREFIX);
+ }
+
+ private static boolean containsPort(String endPoint) {
+ return StringUtils.contains(endPoint, ':');
+ }
}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/replication/release_partition/release_partition.4.get.http b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/replication/release_partition/release_partition.4.get.http
index d5cf952..74ebe94 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/replication/release_partition/release_partition.4.get.http
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/replication/release_partition/release_partition.4.get.http
@@ -16,4 +16,4 @@
* specific language governing permissions and limitations
* under the License.
*/
-nc:asterix_nc1 /admin/storage/partition/0
\ No newline at end of file
+nc:asterix_nc1:19004 /admin/storage/partition/0
\ No newline at end of file