Search in sources :

Example 1 with ClientException

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

the class TestStorageContainerChannel method testGetRootRangeServiceExceptionally.

@Test
public void testGetRootRangeServiceExceptionally() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses1 = FutureUtils.createFuture();
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses2 = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses1).thenReturn(locateResponses2);
    // the future is not set before #getRootRangeService
    assertNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    // call #getRootRangeService
    CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
    // the future is set and the locationClient#locateStorageContainers is called
    assertNotNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // if the request is outstanding, a second call will not call locationClient#locateStorageContainers
    CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
    assertTrue(rsChannelFuture == rsChannelFuture1);
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // prepare the result and complete the request
    OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
    // complete exceptionally
    locateResponses1.completeExceptionally(new ClientException("test-exception"));
    ensureCallbackExecuted();
    // verify channel
    assertNull(channelManager.getChannel(endpoint));
    // verify storage container info
    assertNull(scClient.getStorageContainerInfo());
    // complete with right responses
    locateResponses2.complete(Lists.newArrayList(oneResp));
    // get the service
    StorageServerChannel rsChannel = rsChannelFuture.get();
    assertTrue(rsChannel == mockChannel);
    // verify storage container info
    StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // verify channel
    assertEquals(mockChannel, channelManager.getChannel(endpoint));
    verify(locationClient, times(2)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) Test(org.junit.Test)

Example 2 with ClientException

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

the class StorageAdminClientTest method testStreamAPI.

@Test
public void testStreamAPI() throws Exception {
    // Create a namespace
    String nsName = testName.getMethodName() + "_ns";
    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 stream
    String streamName = testName.getMethodName() + "_stream";
    StreamConfiguration streamConf = StreamConfiguration.newBuilder(DEFAULT_STREAM_CONF).build();
    StreamProperties streamProps = FutureUtils.result(adminClient.createStream(nsName, streamName, streamConf));
    assertEquals(streamName, streamProps.getStreamName());
    assertEquals(StreamConfiguration.newBuilder(streamConf).setBackendServiceUrl(defaultBackendUri.toString()).build(), streamProps.getStreamConf());
    // create a duplicated stream
    try {
        FutureUtils.result(adminClient.createStream(nsName, streamName, streamConf));
        fail("Should fail on creation if stream " + streamName + " already exists");
    } catch (StreamExistsException cee) {
    // expected
    } catch (ClientException ce) {
        // TODO: currently it throws InternalServerError for stream exists case
        assertTrue(ce.getMessage().endsWith("code = " + StatusCode.INTERNAL_SERVER_ERROR));
    }
    String notFoundStreamName = testName.getMethodName() + "_notfound";
    // get a not-found stream
    try {
        FutureUtils.result(adminClient.getStream(nsName, notFoundStreamName));
        fail("Should fail on get if stream " + notFoundStreamName + " doesn't exist");
    } catch (StreamNotFoundException cnfe) {
    // expected
    }
    // delete a not-found stream
    try {
        FutureUtils.result(adminClient.deleteStream(nsName, notFoundStreamName));
        fail("Should fail on delete if stream " + notFoundStreamName + " doesn't exist");
    } catch (StreamNotFoundException cnfe) {
    // expected
    }
    // get an existing stream
    StreamProperties getStreamProps = FutureUtils.result(adminClient.getStream(nsName, streamName));
    assertEquals(streamProps, getStreamProps);
    // delete an existing stream
    Boolean deleted = FutureUtils.result(adminClient.deleteStream(nsName, streamName));
    assertTrue(deleted);
    // the stream should not exist after deleted.
    try {
        FutureUtils.result(adminClient.getStream(nsName, streamName));
        fail("Should fail on get if stream " + nsName + " doesn't exist");
    } catch (StreamNotFoundException cnfe) {
    // expected
    }
}
Also used : NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) StreamConfiguration(org.apache.bookkeeper.stream.proto.StreamConfiguration) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) StreamNotFoundException(org.apache.bookkeeper.clients.exceptions.StreamNotFoundException) NamespaceConfiguration(org.apache.bookkeeper.stream.proto.NamespaceConfiguration) StreamExistsException(org.apache.bookkeeper.clients.exceptions.StreamExistsException) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) Test(org.junit.Test)

Example 3 with ClientException

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

the class TestPByteBufTableImpl method testInitializeFailureOnGetActiveRanges.

@Test
public void testInitializeFailureOnGetActiveRanges() {
    ClientException cause = new ClientException("test-cause");
    when(mockMetaRangeClient.getActiveDataRanges()).thenReturn(FutureUtils.exception(cause));
    PByteBufTableImpl table = new PByteBufTableImpl(runtime.getMethodName(), streamProps, mockClientManager, scheduler.chooseThread(1));
    try {
        FutureUtils.result(table.initialize());
        fail("Should fail initializing the table with exception " + cause);
    } catch (Exception e) {
        assertEquals(cause, e);
    }
}
Also used : ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) Test(org.junit.Test)

Example 4 with ClientException

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

the class TestProtocolInternalUtils method testCreateRootRangeException.

// 
// Test Exceptions related utils
// 
@Test
public void testCreateRootRangeException() {
    String name = "test-create-root-range-exception";
    // stream exists exception
    Throwable cause1 = createRootRangeException(name, StatusCode.STREAM_EXISTS);
    assertTrue(cause1 instanceof StreamExistsException);
    StreamExistsException see = (StreamExistsException) cause1;
    // stream not found
    Throwable cause2 = createRootRangeException(name, StatusCode.STREAM_NOT_FOUND);
    assertTrue(cause2 instanceof StreamNotFoundException);
    StreamNotFoundException snfe = (StreamNotFoundException) cause2;
    // invalid stream name
    Throwable invalidStreamNameCause = createRootRangeException(name, StatusCode.INVALID_STREAM_NAME);
    assertTrue(invalidStreamNameCause instanceof InvalidStreamNameException);
    InvalidStreamNameException isne = (InvalidStreamNameException) invalidStreamNameCause;
    // failure
    Throwable cause3 = createRootRangeException(name, StatusCode.FAILURE);
    ClientException se = (ClientException) cause3;
    assertEquals("fail to access its root range : code = " + StatusCode.FAILURE, se.getMessage());
    // namespace exists exception
    Throwable cause5 = createRootRangeException(name, StatusCode.NAMESPACE_EXISTS);
    assertTrue(cause5 instanceof NamespaceExistsException);
    // namespace not-found exception
    Throwable cause6 = createRootRangeException(name, StatusCode.NAMESPACE_NOT_FOUND);
    assertTrue(cause6 instanceof NamespaceNotFoundException);
    // invalid namespace name
    Throwable cause7 = createRootRangeException(name, StatusCode.INVALID_NAMESPACE_NAME);
    assertTrue(cause7 instanceof InvalidNamespaceNameException);
}
Also used : InvalidStreamNameException(org.apache.bookkeeper.clients.exceptions.InvalidStreamNameException) InvalidNamespaceNameException(org.apache.bookkeeper.clients.exceptions.InvalidNamespaceNameException) StreamNotFoundException(org.apache.bookkeeper.clients.exceptions.StreamNotFoundException) StreamExistsException(org.apache.bookkeeper.clients.exceptions.StreamExistsException) 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)

Example 5 with ClientException

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

the class RootRangeClientImplTestBase method testCreateRootRangeException.

@Test
public void testCreateRootRangeException() {
    String name = "test-create-root-range-exception";
    // stream exists exception
    Throwable cause1 = createRootRangeException(name, StatusCode.STREAM_EXISTS);
    assertTrue(cause1 instanceof StreamExistsException);
    StreamExistsException see = (StreamExistsException) cause1;
    // stream not found
    Throwable cause2 = createRootRangeException(name, StatusCode.STREAM_NOT_FOUND);
    assertTrue(cause2 instanceof StreamNotFoundException);
    StreamNotFoundException snfe = (StreamNotFoundException) cause2;
    // failure
    Throwable cause3 = createRootRangeException(name, StatusCode.FAILURE);
    assertTrue(cause3 instanceof ClientException);
    ClientException se = (ClientException) cause3;
    assertEquals("fail to access its root range : code = " + StatusCode.FAILURE, se.getMessage());
    // unexpected
    Throwable cause4 = createRootRangeException(name, StatusCode.BAD_VERSION);
    assertTrue(cause4 instanceof ClientException);
    // namespace exists exception
    Throwable cause5 = createRootRangeException(name, StatusCode.NAMESPACE_EXISTS);
    assertTrue(cause5 instanceof NamespaceExistsException);
    // namespace not-found exception
    Throwable cause6 = createRootRangeException(name, StatusCode.NAMESPACE_NOT_FOUND);
    assertTrue(cause6 instanceof NamespaceNotFoundException);
    // invalid namespace name
    Throwable cause7 = createRootRangeException(name, StatusCode.INVALID_NAMESPACE_NAME);
    assertTrue(cause7 instanceof InvalidNamespaceNameException);
}
Also used : InvalidNamespaceNameException(org.apache.bookkeeper.clients.exceptions.InvalidNamespaceNameException) StreamNotFoundException(org.apache.bookkeeper.clients.exceptions.StreamNotFoundException) StreamExistsException(org.apache.bookkeeper.clients.exceptions.StreamExistsException) 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