use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory 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.StorageContainerFactory in project bookkeeper by apache.
the class TestStorageContainerRegistryImpl method testStopNotFoundStorageContainer.
@Test
public void testStopNotFoundStorageContainer() throws Exception {
StorageContainerFactory scFactory = createStorageContainerFactory();
StorageContainerRegistryImpl registry = new StorageContainerRegistryImpl(scFactory, scheduler);
FutureUtils.result(registry.stopStorageContainer(1234L));
assertEquals(0, registry.getNumStorageContainers());
}
use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory 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.api.sc.StorageContainerFactory in project bookkeeper by apache.
the class TestStorageContainerRegistryImpl method testOperationsAfterClosed.
@Test
public void testOperationsAfterClosed() throws Exception {
StorageContainerFactory scFactory = createStorageContainerFactory();
StorageContainerRegistryImpl registry = new StorageContainerRegistryImpl(scFactory, scheduler);
registry.close();
long scId = 1234L;
try {
FutureUtils.result(registry.startStorageContainer(scId));
fail("Should fail to start storage container after registry is closed");
} catch (ObjectClosedException oce) {
// expected
assertEquals(0, registry.getNumStorageContainers());
}
try {
FutureUtils.result(registry.stopStorageContainer(scId));
fail("Should fail to start storage container after registry is closed");
} catch (ObjectClosedException oce) {
// expected
assertEquals(0, registry.getNumStorageContainers());
}
}
Aggregations