Search in sources :

Example 1 with StorageException

use of org.apache.bookkeeper.stream.storage.exceptions.StorageException in project bookkeeper by apache.

the class TestStorageContainerRegistryImpl method testStartStorageContainerTwice.

@Test
public void testStartStorageContainerTwice() throws Exception {
    StorageContainerFactory scFactory = createStorageContainerFactory();
    StorageContainerRegistryImpl registry = new StorageContainerRegistryImpl(scFactory, scheduler);
    FutureUtils.result(registry.startStorageContainer(1234L));
    assertEquals(1, registry.getNumStorageContainers());
    // second time
    try {
        FutureUtils.result(registry.startStorageContainer(1234L));
        fail("Should fail on starting same storage container twice");
    } catch (StorageException ue) {
        assertEquals(1, registry.getNumStorageContainers());
    }
}
Also used : StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) Test(org.junit.Test)

Example 2 with StorageException

use of org.apache.bookkeeper.stream.storage.exceptions.StorageException in project bookkeeper by apache.

the class StorageContainerRegistryImpl method unsafeStartStorageContainer.

private CompletableFuture<Void> unsafeStartStorageContainer(long scId) {
    if (closed) {
        return FutureUtils.exception(new ObjectClosedException(COMPONENT_NAME));
    }
    if (groups.containsKey(scId)) {
        return FutureUtils.exception(new StorageException("StorageContainer " + scId + " already registered"));
    }
    StorageContainer newStorageContainer = scFactory.createStorageContainer(scId);
    StorageContainer oldStorageContainer = groups.putIfAbsent(scId, newStorageContainer);
    if (null != oldStorageContainer) {
        newStorageContainer.close();
        return FutureUtils.exception(new StorageException("StorageContainer " + scId + " already registered"));
    }
    log.info("Registered StorageContainer ('{}').", scId);
    return newStorageContainer.start();
}
Also used : ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)

Example 3 with StorageException

use of org.apache.bookkeeper.stream.storage.exceptions.StorageException in project bookkeeper by apache.

the class TestStorageContainerResponseHandler method testInternalError.

@SuppressWarnings("unchecked")
@Test
public void testInternalError() throws Exception {
    StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
    AtomicReference<StorageContainerResponse> responseHolder = new AtomicReference<>(null);
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer((Answer<Void>) invocation -> {
        StorageContainerResponse resp = invocation.getArgument(0);
        responseHolder.set(resp);
        latch.countDown();
        return null;
    }).when(observer).onNext(any(StorageContainerResponse.class));
    StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
    StorageException exception = new StorageException("test-exception");
    handler.accept(null, exception);
    verify(observer, times(1)).onNext(any());
    verify(observer, times(1)).onCompleted();
    verify(observer, times(0)).onError(any());
    latch.await();
    assertNotNull(responseHolder.get());
    assertEquals(StatusCode.INTERNAL_SERVER_ERROR, responseHolder.get().getCode());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assert.assertNotNull(org.junit.Assert.assertNotNull) StatusException(io.grpc.StatusException) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) CountDownLatch(java.util.concurrent.CountDownLatch) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Answer(org.mockito.stubbing.Answer) StreamObserver(io.grpc.stub.StreamObserver) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Status(io.grpc.Status) Assert.assertEquals(org.junit.Assert.assertEquals) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) Mockito.mock(org.mockito.Mockito.mock) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Aggregations

StorageException (org.apache.bookkeeper.stream.storage.exceptions.StorageException)3 Test (org.junit.Test)2 Status (io.grpc.Status)1 StatusException (io.grpc.StatusException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 StreamObserver (io.grpc.stub.StreamObserver)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)1 StatusCode (org.apache.bookkeeper.stream.proto.storage.StatusCode)1 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)1 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)1 StorageContainerFactory (org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1