Search in sources :

Example 6 with StorageContainer

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

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

Example 8 with StorageContainer

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();
}
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 9 with StorageContainer

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());
}
Also used : CreateStreamRequest(org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest) ProtoUtils.createCreateStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateStreamRequest) CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) ByteString(com.google.protobuf.ByteString) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Example 10 with StorageContainer

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());
}
Also used : ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) ByteString(com.google.protobuf.ByteString) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Aggregations

StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)16 Test (org.junit.Test)12 ByteString (com.google.protobuf.ByteString)6 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)4 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)4 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)3 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)2 StorageException (org.apache.bookkeeper.stream.storage.exceptions.StorageException)2 ListenableScheduledFuture (com.google.common.util.concurrent.ListenableScheduledFuture)1 ListeningScheduledExecutorService (com.google.common.util.concurrent.ListeningScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)1 StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)1 CreateNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest)1 CreateNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse)1 CreateStreamRequest (org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest)1 CreateStreamResponse (org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse)1 DeleteNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest)1 DeleteNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse)1 DeleteStreamRequest (org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest)1