Search in sources :

Example 1 with StorageContainerFactory

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();
}
Also used : OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) Mockito.verify(org.mockito.Mockito.verify) StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) After(org.junit.After) Assert.fail(org.junit.Assert.fail) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Example 2 with StorageContainerFactory

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());
}
Also used : StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) Test(org.junit.Test)

Example 3 with StorageContainerFactory

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());
    }
}
Also used : StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) Test(org.junit.Test)

Example 4 with StorageContainerFactory

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());
    }
}
Also used : StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) Test(org.junit.Test)

Aggregations

StorageContainerFactory (org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory)4 Test (org.junit.Test)4 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)2 StorageException (org.apache.bookkeeper.stream.storage.exceptions.StorageException)2 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1