You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2019/02/27 07:37:51 UTC
[bookkeeper] branch master updated: Add http method test for
vertx-http server
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 4e32ef6 Add http method test for vertx-http server
4e32ef6 is described below
commit 4e32ef618fd3b6a60d9ff7f78ea40c8d11464d96
Author: Rajan Dhabalia <rd...@apache.org>
AuthorDate: Tue Feb 26 23:37:46 2019 -0800
Add http method test for vertx-http server
### Motivation
As discussed at #1953, adding test to verify all http-method works for vertx-http-server.
Reviewers: Enrico Olivelli <eo...@gmail.com>, Sijie Guo <si...@apache.org>
This closes #1963 from rdhabalia/gc_test
---
.../bookkeeper/http/vertx/TestVertxHttpServer.java | 26 +++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/bookkeeper-http/vertx-http-server/src/test/java/org/apache/bookkeeper/http/vertx/TestVertxHttpServer.java b/bookkeeper-http/vertx-http-server/src/test/java/org/apache/bookkeeper/http/vertx/TestVertxHttpServer.java
index 1c547d3..c6cc133 100644
--- a/bookkeeper-http/vertx-http-server/src/test/java/org/apache/bookkeeper/http/vertx/TestVertxHttpServer.java
+++ b/bookkeeper-http/vertx-http-server/src/test/java/org/apache/bookkeeper/http/vertx/TestVertxHttpServer.java
@@ -47,7 +47,7 @@ public class TestVertxHttpServer {
httpServer.initialize(httpServiceProvider);
assertTrue(httpServer.startServer(0));
int port = httpServer.getListeningPort();
- HttpResponse httpResponse = sendGet(getUrl(port, HttpRouter.HEARTBEAT));
+ HttpResponse httpResponse = send(getUrl(port, HttpRouter.HEARTBEAT), HttpServer.Method.GET);
assertEquals(HttpServer.StatusCode.OK.getValue(), httpResponse.responseCode);
assertEquals(HeartbeatService.HEARTBEAT.trim(), httpResponse.responseBody.trim());
httpServer.stopServer();
@@ -60,17 +60,33 @@ public class TestVertxHttpServer {
httpServer.initialize(httpServiceProvider);
assertTrue(httpServer.startServer(0));
int port = httpServer.getListeningPort();
- HttpResponse httpResponse = sendGet(getUrl(port, HttpRouter.METRICS));
+ HttpResponse httpResponse = send(getUrl(port, HttpRouter.METRICS), HttpServer.Method.GET);
assertEquals(HttpServer.StatusCode.OK.getValue(), httpResponse.responseCode);
httpServer.stopServer();
}
- // HTTP GET request
- private HttpResponse sendGet(String url) throws IOException {
+ @Test
+ public void testHttpMethods() throws Exception {
+ VertxHttpServer httpServer = new VertxHttpServer();
+ HttpServiceProvider httpServiceProvider = NullHttpServiceProvider.getInstance();
+ httpServer.initialize(httpServiceProvider);
+ assertTrue(httpServer.startServer(0));
+ int port = httpServer.getListeningPort();
+ HttpResponse httpResponse = send(getUrl(port, HttpRouter.GC), HttpServer.Method.GET);
+ assertEquals(HttpServer.StatusCode.OK.getValue(), httpResponse.responseCode);
+ httpResponse = send(getUrl(port, HttpRouter.GC), HttpServer.Method.POST);
+ assertEquals(HttpServer.StatusCode.OK.getValue(), httpResponse.responseCode);
+ httpResponse = send(getUrl(port, HttpRouter.GC), HttpServer.Method.PUT);
+ assertEquals(HttpServer.StatusCode.OK.getValue(), httpResponse.responseCode);
+ httpServer.stopServer();
+ }
+
+ // HTTP request
+ private HttpResponse send(String url, HttpServer.Method method) throws IOException {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional, default is GET
- con.setRequestMethod("GET");
+ con.setRequestMethod(method.toString());
int responseCode = con.getResponseCode();
StringBuilder response = new StringBuilder();
BufferedReader in = null;