zhaijack commented on a change in pull request #521: Issue 520: Add more http 
endpoint
URL: https://github.com/apache/bookkeeper/pull/521#discussion_r141566049
 
 

 ##########
 File path: 
bookkeeper-server/src/test/java/org/apache/bookkeeper/http/TestHttpService.java
 ##########
 @@ -112,13 +115,57 @@ public void testConfigServicePost() throws Exception {
 
     @Test
     public void testListBookiesService() throws Exception {
-        // test config service
+        baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
         HttpService listBookiesService = 
bkHttpServiceProvider.provideListBookiesService();
 
-        // null parameters, should print rw bookies, without hostname
-        HttpServiceRequest postRequest1 = new HttpServiceRequest(null, 
HttpServer.Method.GET, null);
-        // TODO: add test zkutil zkserver into config
-        HttpServiceResponse postResponse1 = 
listBookiesService.handle(postRequest1);
-        assertEquals(HttpServer.StatusCode.OK.getValue(), 
postResponse1.getStatusCode());
+        //1,  null parameters, should print rw bookies, without hostname
+        HttpServiceRequest request1 = new HttpServiceRequest(null, 
HttpServer.Method.GET, null);
+        HttpServiceResponse response1 = listBookiesService.handle(request1);
+        assertEquals(HttpServer.StatusCode.OK.getValue(), 
response1.getStatusCode());
+        // get response , expected get 3 bookies, and without hostname
+        @SuppressWarnings("unchecked")
+        HashMap<String, String> respBody = 
JsonUtil.fromJson(response1.getBody(), HashMap.class);
+        assertEquals(3, respBody.size());
+        for (int i = 0; i < 3; i++) {
+            assertEquals(true, respBody.containsKey(getBookie(i).toString()));
+            assertEquals(null, respBody.get(getBookie(i).toString()));
+        }
+
+        //2, parameter: type=rw&print_hostnames=true, should print rw bookies 
with hostname
+        HashMap<String, String> params = Maps.newHashMap();
+        params.put("type", "rw");
+        params.put("print_hostnames", "true");
+        HttpServiceRequest request2 = new HttpServiceRequest(null, 
HttpServer.Method.GET, params);
+        HttpServiceResponse response2 = listBookiesService.handle(request2);
+        assertEquals(HttpServer.StatusCode.OK.getValue(), 
response2.getStatusCode());
+        // get response , expected get 3 bookies, and with hostname
+        @SuppressWarnings("unchecked")
+        HashMap<String, String> respBody2 = 
JsonUtil.fromJson(response2.getBody(), HashMap.class);
+        assertEquals(3, respBody2.size());
+        for (int i = 0; i < 3; i++) {
+            assertEquals(true, respBody2.containsKey(getBookie(i).toString()));
+            assertNotNull(respBody2.get(getBookie(i).toString()));
+        }
+
+        //3, parameter: type=ro&print_hostnames=true, should print ro bookies 
with hostname
+        // turn bookie to ro, get
+        for (int i = 0; i < 3; i++) {
 
 Review comment:
   Thanks. will change it.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to