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());
}
}
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();
}
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());
}
Aggregations