You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2021/07/30 17:40:28 UTC

[datasketches-server] 01/02: document test base class a bit more, test status calls

This is an automated email from the ASF dual-hosted git repository.

jmalkin pushed a commit to branch test_coverage
in repository https://gitbox.apache.org/repos/asf/datasketches-server.git

commit d3b1d3312710028528405e9f48b06899f36fd33d
Author: Jon Malkin <jm...@users.noreply.github.com>
AuthorDate: Thu Jul 29 11:45:17 2021 -0700

    document test base class a bit more, test status calls
---
 .../apache/datasketches/server/ServerTestBase.java | 20 +++++++
 .../datasketches/server/StatusHandlerTest.java     | 61 ++++++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/src/test/java/org/apache/datasketches/server/ServerTestBase.java b/src/test/java/org/apache/datasketches/server/ServerTestBase.java
index a6df4f2..30865c3 100644
--- a/src/test/java/org/apache/datasketches/server/ServerTestBase.java
+++ b/src/test/java/org/apache/datasketches/server/ServerTestBase.java
@@ -77,6 +77,14 @@ public class ServerTestBase {
     }
   }
 
+  /**
+   * Sends a POST to the server at the target path, using the provided data. Returns the HTTP status code
+   * as well as any response in the response object (after clearing out anything that already existed).
+   * @param path Request path appended to the server URI
+   * @param data Request data as a JsonObject
+   * @param response Response data as a JsonObject -- existing data will be removed
+   * @return The HTTP status code from the server
+   */
   int postData(@NonNull final String path,
                @NonNull final JsonObject data,
                @NonNull final JsonObject response) {
@@ -132,6 +140,18 @@ public class ServerTestBase {
     return status;
   }
 
+  /**
+   * <p>Sends a GET to the server at the target path, using the provided data. Returns the HTTP status code
+   * as well as any response in the response object (after clearing out anything that already existed).</p>
+   *
+   * <p>Unlike POST, this call may be subject to HTTP header length limits since the data is encoded as
+   * the request querystrong.</p>
+   * @param path Request path appended to the server URI
+   * @param data Request data as a JsonObject
+   * @param response Response data as a JsonObject -- existing data will be removed
+   * @return The HTTP status code from the server
+   */
+
   int getData(@NonNull final String path,
               @NonNull final JsonObject data,
               @NonNull final JsonObject response) {
diff --git a/src/test/java/org/apache/datasketches/server/StatusHandlerTest.java b/src/test/java/org/apache/datasketches/server/StatusHandlerTest.java
new file mode 100644
index 0000000..c91119d
--- /dev/null
+++ b/src/test/java/org/apache/datasketches/server/StatusHandlerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+package org.apache.datasketches.server;
+
+import static org.apache.datasketches.server.SketchConstants.RESPONSE_SKETCH_COUNT_FIELD;
+import static org.apache.datasketches.server.SketchConstants.STATUS_PATH;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.testng.annotations.Test;
+
+
+import com.google.gson.JsonObject;
+
+public class StatusHandlerTest extends ServerTestBase {
+  @Test
+  public void callStatus() {
+    // really simple call -- the parameters are ignored
+    final JsonObject response = new JsonObject();
+    JsonObject request = new JsonObject();
+
+    // GET will easily work since the header size isn't an issue with no data
+    assertEquals(getData(STATUS_PATH, request, response), HttpStatus.OK_200);
+    JsonObject data = response.get(RESPONSE_FIELD).getAsJsonObject();
+    assertTrue(data.has(RESPONSE_SKETCH_COUNT_FIELD));
+    assertEquals(data.get(RESPONSE_SKETCH_COUNT_FIELD).getAsInt(), 20);
+
+    // POST the same query
+    request.addProperty("notAName", "theta0");
+    assertEquals(postData(STATUS_PATH, request, response), HttpStatus.OK_200);
+    data = response.get(RESPONSE_FIELD).getAsJsonObject();
+    assertTrue(data.has(RESPONSE_SKETCH_COUNT_FIELD));
+    assertEquals(data.get(RESPONSE_SKETCH_COUNT_FIELD).getAsInt(), 20);
+
+    // send in a tiny bit of data that should be ignored
+    request = new JsonObject();
+    request.add("name", new JsonObject());
+    assertEquals(postData(STATUS_PATH, request, response), HttpStatus.OK_200);
+    data = response.get(RESPONSE_FIELD).getAsJsonObject();
+    assertTrue(data.has(RESPONSE_SKETCH_COUNT_FIELD));
+    assertEquals(data.get(RESPONSE_SKETCH_COUNT_FIELD).getAsInt(), 20);
+  }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org