use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.
the class TestHttpService method testListBookiesService.
@Test
public void testListBookiesService() throws Exception {
baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
HttpEndpointService listBookiesService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_BOOKIES);
// 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(numberOfBookies, respBody.size());
for (int i = 0; i < numberOfBookies; 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 numberOfBookies bookies, and with hostname
@SuppressWarnings("unchecked") HashMap<String, String> respBody2 = JsonUtil.fromJson(response2.getBody(), HashMap.class);
assertEquals(numberOfBookies, respBody2.size());
for (int i = 0; i < numberOfBookies; 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 1 into ro, get it
setBookieToReadOnly(getBookie(1));
Thread.sleep(200);
HashMap<String, String> params3 = Maps.newHashMap();
params3.put("type", "ro");
params3.put("print_hostnames", "true");
HttpServiceRequest request3 = new HttpServiceRequest(null, HttpServer.Method.GET, params3);
HttpServiceResponse response3 = listBookiesService.handle(request3);
// LOG.info("Turn 1 bookies into RO, should get it in this request");
assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
// get response , expected get 1 ro bookies, and with hostname
@SuppressWarnings("unchecked") HashMap<String, String> respBody3 = JsonUtil.fromJson(response3.getBody(), HashMap.class);
assertEquals(1, respBody3.size());
assertEquals(true, respBody3.containsKey(getBookie(1).toString()));
// get other 5 rw bookies.
HashMap<String, String> params4 = Maps.newHashMap();
params4.put("type", "rw");
params4.put("print_hostnames", "true");
HttpServiceRequest request4 = new HttpServiceRequest(null, HttpServer.Method.GET, params4);
HttpServiceResponse response4 = listBookiesService.handle(request4);
assertEquals(HttpServer.StatusCode.OK.getValue(), response4.getStatusCode());
@SuppressWarnings("unchecked") HashMap<String, String> respBody4 = JsonUtil.fromJson(response4.getBody(), HashMap.class);
assertEquals(5, respBody4.size());
assertEquals(true, respBody4.containsKey(getBookie(2).toString()));
}
use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.
the class TestHttpService method testTriggerAuditService.
@Test
public void testTriggerAuditService() throws Exception {
baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
startAuditorElector();
HttpEndpointService triggerAuditService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.TRIGGER_AUDIT);
// 1, GET, should return error
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response1 = triggerAuditService.handle(request1);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
// 2, PUT, should success.
killBookie(1);
Thread.sleep(500);
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
HttpServiceResponse response2 = triggerAuditService.handle(request2);
assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
stopAuditorElector();
}
use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.
the class TestHttpService method testReadLedgerEntryService.
@Test
public void testReadLedgerEntryService() throws Exception {
baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
BookKeeper.DigestType digestType = BookKeeper.DigestType.CRC32;
int numLedgers = 1;
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 readLedgerEntryService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.READ_LEDGER_ENTRY);
// 1, null parameters of GET, should return NOT_FOUND
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response1 = readLedgerEntryService.handle(request1);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
// 2, parameters for GET first ledger, should return OK
// no start/end entry id, so return all the 100 entries.
HashMap<String, String> params = Maps.newHashMap();
Long ledgerId = Long.valueOf(lh[0].getId());
params.put("ledger_id", ledgerId.toString());
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, params);
HttpServiceResponse response2 = readLedgerEntryService.handle(request2);
assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
@SuppressWarnings("unchecked") HashMap<String, String> respBody = JsonUtil.fromJson(response2.getBody(), HashMap.class);
// default return all the entries. so should have 100 entries return
assertEquals(100, respBody.size());
// 2, parameters for GET first ledger, should return OK
// start_entry_id=1, end_entry_id=77, so return 77 entries.
HashMap<String, String> params3 = Maps.newHashMap();
params3.put("ledger_id", ledgerId.toString());
params3.put("start_entry_id", "1");
params3.put("end_entry_id", "77");
HttpServiceRequest request3 = new HttpServiceRequest(null, HttpServer.Method.GET, params3);
HttpServiceResponse response3 = readLedgerEntryService.handle(request3);
assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
@SuppressWarnings("unchecked") HashMap<String, String> respBody3 = JsonUtil.fromJson(response3.getBody(), HashMap.class);
assertEquals(77, respBody3.size());
// Verify the entry content that we got.
assertTrue(respBody3.get("17").equals(content));
}
use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.
the class TestHttpService method testDeleteLedgerService.
/**
* Create ledgers, then test Delete Ledger service.
*/
@Test
public void testDeleteLedgerService() 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 deleteLedgerService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.DELETE_LEDGER);
// 1, null parameters of GET, should return NOT_FOUND
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response1 = deleteLedgerService.handle(request1);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
// 2, null parameters of DELETE, should return NOT_FOUND
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.DELETE, null);
HttpServiceResponse response2 = deleteLedgerService.handle(request2);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response2.getStatusCode());
// 3, delete first ledger, should return OK, and should only get 3 ledgers after delete.
HashMap<String, String> params = Maps.newHashMap();
Long ledgerId = Long.valueOf(lh[0].getId());
params.put("ledger_id", ledgerId.toString());
HttpServiceRequest request3 = new HttpServiceRequest(null, HttpServer.Method.DELETE, params);
HttpServiceResponse response3 = deleteLedgerService.handle(request3);
assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
// use list Ledger to verify left 3 ledger
HttpEndpointService listLedgerService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_LEDGER);
HttpServiceRequest request4 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response4 = listLedgerService.handle(request4);
assertEquals(HttpServer.StatusCode.OK.getValue(), response4.getStatusCode());
// get response , expected get 3 ledgers
@SuppressWarnings("unchecked") LinkedHashMap<String, String> respBody = JsonUtil.fromJson(response4.getBody(), LinkedHashMap.class);
assertEquals(3, respBody.size());
}
use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.
the class TestHttpService method testListDiskFilesService.
@Test
public void testListDiskFilesService() 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 listDiskFileService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_DISK_FILE);
// 1, null parameters of GET, should return 3 kind of files: journal, entrylog and index files
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response1 = listDiskFileService.handle(request1);
assertEquals(HttpServer.StatusCode.OK.getValue(), response1.getStatusCode());
@SuppressWarnings("unchecked") HashMap<String, String> respBody = JsonUtil.fromJson(response1.getBody(), HashMap.class);
assertEquals(3, respBody.size());
// 2, parameters of GET journal file, should return journal files
HashMap<String, String> params = Maps.newHashMap();
params.put("file_type", "journal");
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, params);
HttpServiceResponse response2 = listDiskFileService.handle(request2);
assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
@SuppressWarnings("unchecked") HashMap<String, String> respBody2 = JsonUtil.fromJson(response2.getBody(), HashMap.class);
assertEquals(1, respBody2.size());
}
Aggregations