use of org.apache.bookkeeper.http.service.HttpServiceRequest in project bookkeeper by apache.
the class TestHttpService method testListUnderReplicatedLedgerService.
private void testListUnderReplicatedLedgerService(LedgerManagerFactory mFactory) throws Exception {
startAuditorElector();
HttpEndpointService listUnderReplicatedLedgerService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_UNDER_REPLICATED_LEDGER);
// 1, PUT, should return error, because only support GET.
HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
HttpServiceResponse response1 = listUnderReplicatedLedgerService.handle(request1);
assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
// 2, GET, should return success.
// first put ledger into rereplicate. then use api to list ur ledger.
@Cleanup LedgerManager ledgerManager = mFactory.newLedgerManager();
@Cleanup final LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
LedgerMetadata md = LedgerHandleAdapter.getLedgerMetadata(lh);
List<BookieSocketAddress> ensemble = md.getEnsembles().get(0L);
ensemble.set(0, new BookieSocketAddress("1.1.1.1", 1000));
TestCallbacks.GenericCallbackFuture<Void> cb = new TestCallbacks.GenericCallbackFuture<Void>();
ledgerManager.writeLedgerMetadata(lh.getId(), md, cb);
cb.get();
long underReplicatedLedger = -1;
for (int i = 0; i < 10; i++) {
underReplicatedLedger = underReplicationManager.pollLedgerToRereplicate();
if (underReplicatedLedger != -1) {
break;
}
Thread.sleep(1000);
}
HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
HttpServiceResponse response2 = listUnderReplicatedLedgerService.handle(request2);
assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
stopAuditorElector();
}
use of org.apache.bookkeeper.http.service.HttpServiceRequest 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.HttpServiceRequest 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.HttpServiceRequest 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