Search in sources :

Example 16 with HttpEndpointService

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());
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookKeeper(org.apache.bookkeeper.client.BookKeeper) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Test(org.junit.Test)

Example 17 with HttpEndpointService

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();
    }
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Test(org.junit.Test)

Example 18 with HttpEndpointService

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();
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Test(org.junit.Test)

Aggregations

HttpEndpointService (org.apache.bookkeeper.http.service.HttpEndpointService)18 HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)17 HttpServiceRequest (org.apache.bookkeeper.http.service.HttpServiceRequest)16 Test (org.junit.Test)16 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)7 BookKeeper (org.apache.bookkeeper.client.BookKeeper)6 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 Cleanup (lombok.Cleanup)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)1 LedgerUnderreplicationManager (org.apache.bookkeeper.meta.LedgerUnderreplicationManager)1 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)1 TestCallbacks (org.apache.bookkeeper.test.TestCallbacks)1