Search in sources :

Example 6 with ClientException

use of org.apache.bookkeeper.clients.exceptions.ClientException in project bookkeeper by apache.

the class StorageAdminClientTest method testNamespaceAPI.

@Test
public void testNamespaceAPI() throws Exception {
    // Create a namespace
    String nsName = testName.getMethodName();
    NamespaceConfiguration colConf = NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build();
    NamespaceProperties colProps = FutureUtils.result(adminClient.createNamespace(nsName, colConf));
    assertEquals(nsName, colProps.getNamespaceName());
    assertEquals(colConf.getDefaultStreamConf(), colProps.getDefaultStreamConf());
    // create a duplicated namespace
    try {
        FutureUtils.result(adminClient.createNamespace(nsName, colConf));
        fail("Should fail on creation if namespace " + nsName + " already exists");
    } catch (NamespaceExistsException cee) {
    // expected
    } catch (ClientException ce) {
        // TODO: currently range server throws InternalServerError
        assertTrue(ce.getMessage().endsWith("code = " + StatusCode.INTERNAL_SERVER_ERROR));
    }
    String notFoundColName = testName.getMethodName() + "_notfound";
    // get a not-found namespace
    try {
        FutureUtils.result(adminClient.getNamespace(notFoundColName));
        fail("Should fail on get if namespace " + notFoundColName + " doesn't exist");
    } catch (NamespaceNotFoundException cnfe) {
    // expected
    }
    // delete a not-found namespace
    try {
        FutureUtils.result(adminClient.deleteNamespace(notFoundColName));
        fail("Should fail on delete if namespace " + notFoundColName + " doesn't exist");
    } catch (NamespaceNotFoundException cnfe) {
    // expected
    }
    // get an existing namespace
    NamespaceProperties getColProps = FutureUtils.result(adminClient.getNamespace(nsName));
    assertEquals(colProps, getColProps);
    // delete an existing namespace
    Boolean deleted = FutureUtils.result(adminClient.deleteNamespace(nsName));
    assertTrue(deleted);
    // the namespace should not exist after deleted.
    try {
        FutureUtils.result(adminClient.getNamespace(nsName));
        fail("Should fail on get if namespace " + nsName + " doesn't exist");
    } catch (NamespaceNotFoundException cnfe) {
    // expected
    }
}
Also used : NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) NamespaceConfiguration(org.apache.bookkeeper.stream.proto.NamespaceConfiguration) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException) Test(org.junit.Test)

Aggregations

ClientException (org.apache.bookkeeper.clients.exceptions.ClientException)6 Test (org.junit.Test)6 NamespaceExistsException (org.apache.bookkeeper.clients.exceptions.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)3 StreamExistsException (org.apache.bookkeeper.clients.exceptions.StreamExistsException)3 StreamNotFoundException (org.apache.bookkeeper.clients.exceptions.StreamNotFoundException)3 InvalidNamespaceNameException (org.apache.bookkeeper.clients.exceptions.InvalidNamespaceNameException)2 NamespaceConfiguration (org.apache.bookkeeper.stream.proto.NamespaceConfiguration)2 NamespaceProperties (org.apache.bookkeeper.stream.proto.NamespaceProperties)2 List (java.util.List)1 InvalidStreamNameException (org.apache.bookkeeper.clients.exceptions.InvalidStreamNameException)1 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)1 StreamConfiguration (org.apache.bookkeeper.stream.proto.StreamConfiguration)1 StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)1 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)1 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)1