use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.
the class TestStorageContainerRegistryImpl method testStartStopStorageContainers.
@Test
public void testStartStopStorageContainers() throws Exception {
StorageContainer sc1 = createStorageContainer();
StorageContainer sc2 = createStorageContainer();
StorageContainerFactory factory = scId -> {
if (scId == 1L) {
return sc1;
} else {
return sc2;
}
};
long scId = 1L;
StorageContainerRegistryImpl registry = new StorageContainerRegistryImpl(factory, scheduler);
FutureUtils.result(registry.startStorageContainer(scId));
assertEquals(1, registry.getNumStorageContainers());
assertEquals(sc1, registry.getStorageContainer(scId));
scId = 2L;
FutureUtils.result(registry.startStorageContainer(scId));
assertEquals(2, registry.getNumStorageContainers());
assertEquals(sc1, registry.getStorageContainer(1L));
assertEquals(sc2, registry.getStorageContainer(2L));
FutureUtils.result(registry.stopStorageContainer(scId));
assertEquals(1, registry.getNumStorageContainers());
assertEquals(sc1, registry.getStorageContainer(1L));
registry.close();
verify(sc1, times(1)).close();
assertEquals(0, registry.getNumStorageContainers());
// double close
registry.close();
verify(sc1, times(1)).close();
}
use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.
the class TestStorageContainerRegistryImpl method createStorageContainer.
private StorageContainer createStorageContainer() {
StorageContainer sc = mock(StorageContainer.class);
when(sc.start()).thenReturn(FutureUtils.value(null));
when(sc.stop()).thenReturn(FutureUtils.value(null));
return sc;
}
use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer 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.api.sc.StorageContainer in project bookkeeper by apache.
the class TestRangeStoreImpl method testCreateStreamMockRootStorageContainerStore.
@Test
public void testCreateStreamMockRootStorageContainerStore() throws Exception {
String colName = "test-create-namespace-mock-root-storage-container-store";
String streamName = colName;
StorageContainer scStore = mock(StorageContainer.class);
when(scStore.stop()).thenReturn(FutureUtils.value(null));
rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.STREAM_EXISTS).build();
CreateStreamRequest createReq = createCreateStreamRequest(colName, streamName, DEFAULT_STREAM_CONF);
when(scStore.createStream(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
CompletableFuture<CreateStreamResponse> createRespFuture = rangeStore.createStream(createReq);
verify(scStore, times(1)).createStream(createReq);
assertTrue(createResp == createRespFuture.get());
}
use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.
the class TestRangeStoreImpl method testDeleteStreamMockRootStorageContainerStore.
@Test
public void testDeleteStreamMockRootStorageContainerStore() throws Exception {
String colName = "test-delete-namespace-no-root-storage-container-store";
String streamName = colName;
StorageContainer scStore = mock(StorageContainer.class);
when(scStore.stop()).thenReturn(FutureUtils.value(null));
rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.STREAM_NOT_FOUND).build();
DeleteStreamRequest deleteReq = createDeleteStreamRequest(colName, streamName);
when(scStore.deleteStream(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
CompletableFuture<DeleteStreamResponse> deleteRespFuture = rangeStore.deleteStream(deleteReq);
verify(scStore, times(1)).deleteStream(deleteReq);
assertTrue(deleteResp == deleteRespFuture.get());
}
Aggregations