use of org.apache.bookkeeper.http.service.HttpEndpointService in project bookkeeper by apache.
the class TestHttpService method testGetLastLogMarkService.
@Test
public void testGetLastLogMarkService() throws Exception {
baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
BookKeeper.DigestType digestType = BookKeeper.DigestType.CRC32;
int numLedgers = 4;
int numMsgs = 100;
LedgerHandle[] lh = new LedgerHandle[numLedgers];
// create ledgers
for (int i = 0; i < numLedgers; i++) {
lh[i] = bkc.createLedger(digestType, "".getBytes());
}
String content = "Apache BookKeeper is cool!";
// add entries
for (int i = 0; i < numMsgs; i++) {
for (int j = 0; j < numLedgers; j++) {
lh[j].addEntry(content.getBytes());
}
}
// close ledgers
for (int i = 0; i < numLedgers; i++) {
lh[i].close();
}
HttpEndpointService getLastLogMarkService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LAST_LOG_MARK);
// 1, null parameters of PUT, should fail
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
HttpServiceResponse response1 = getLastLogMarkService.handle(request1);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
// 2, null parameters of GET, should return 1 file
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response2 = getLastLogMarkService.handle(request2);
assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
@SuppressWarnings("unchecked") HashMap<String, String> respBody = JsonUtil.fromJson(response2.getBody(), HashMap.class);
assertEquals(1, respBody.size());
}
use of org.apache.bookkeeper.http.service.HttpEndpointService in project bookkeeper by apache.
the class TestHttpService method testConfigServiceGet.
@Test
public void testConfigServiceGet() throws Exception {
try {
// test config service
String testProperty = "TEST_PROPERTY";
String testValue = "TEST_VALUE";
baseConf.setProperty(testProperty, testValue);
HttpEndpointService configService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.SERVER_CONFIG);
HttpServiceRequest getRequest = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response = configService.handle(getRequest);
Map configMap = JsonUtil.fromJson(response.getBody(), Map.class);
assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode());
assertEquals(testValue, configMap.get(testProperty));
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.bookkeeper.http.service.HttpEndpointService in project bookkeeper by apache.
the class TestHttpService method testDecommissionService.
@Test
public void testDecommissionService() throws Exception {
baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
startAuditorElector();
HttpEndpointService decommissionService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.DECOMMISSION);
// 1, PUT with null, should return error, because should contains {"bookie_src": <bookie_address>}.
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
HttpServiceResponse response1 = decommissionService.handle(request1);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
// 2, GET, should fail for not support get
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response2 = decommissionService.handle(request2);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response2.getStatusCode());
// 3, PUT, with body, should success.
String putBody3 = "{\"bookie_src\": \"" + getBookie(1).toString() + "\"}";
HttpServiceRequest request3 = new HttpServiceRequest(putBody3, HttpServer.Method.PUT, null);
// after bookie kill, request should success
killBookie(1);
HttpServiceResponse response3 = decommissionService.handle(request3);
assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
stopAuditorElector();
}
Aggregations