Search in sources :

Example 11 with StorageContainer

use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.

the class TestRangeStoreImpl method testCreateNamespaceMockRootStorageContainerStore.

@Test
public void testCreateNamespaceMockRootStorageContainerStore() throws Exception {
    String colName = "test-create-namespace-mock-root-storage-container-store";
    StorageContainer scStore = mock(StorageContainer.class);
    when(scStore.stop()).thenReturn(FutureUtils.value(null));
    rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
    CreateNamespaceResponse createResp = CreateNamespaceResponse.newBuilder().setCode(StatusCode.NAMESPACE_EXISTS).build();
    CreateNamespaceRequest request = createCreateNamespaceRequest(colName, namespaceConf);
    when(scStore.createNamespace(request)).thenReturn(CompletableFuture.completedFuture(createResp));
    CompletableFuture<CreateNamespaceResponse> createRespFuture = rangeStore.createNamespace(request);
    verify(scStore, times(1)).createNamespace(request);
    assertTrue(createResp == createRespFuture.get());
}
Also used : ByteString(com.google.protobuf.ByteString) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) ProtoUtils.createCreateNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateNamespaceRequest) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) Test(org.junit.Test)

Example 12 with StorageContainer

use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.

the class TestRangeStoreImpl method testDeleteNamespaceMockRootStorageContainerStore.

@Test
public void testDeleteNamespaceMockRootStorageContainerStore() throws Exception {
    String colName = "test-delete-namespace-no-root-storage-container-store";
    StorageContainer scStore = mock(StorageContainer.class);
    when(scStore.stop()).thenReturn(FutureUtils.value(null));
    rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
    DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.NAMESPACE_NOT_FOUND).build();
    DeleteNamespaceRequest request = createDeleteNamespaceRequest(colName);
    when(scStore.deleteNamespace(request)).thenReturn(CompletableFuture.completedFuture(deleteResp));
    CompletableFuture<DeleteNamespaceResponse> deleteRespFuture = rangeStore.deleteNamespace(request);
    verify(scStore, times(1)).deleteNamespace(request);
    assertTrue(deleteResp == deleteRespFuture.get());
}
Also used : DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) ByteString(com.google.protobuf.ByteString) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Example 13 with StorageContainer

use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.

the class TestRangeStoreImpl method testRangeMockStorageContainer.

@Test
public void testRangeMockStorageContainer() throws Exception {
    StorageContainer scStore = mock(StorageContainer.class);
    when(scStore.stop()).thenReturn(FutureUtils.value(null));
    rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
    StorageContainerResponse response = createRangeResponse(StatusCode.SUCCESS);
    StorageContainerRequest request = createRangeRequest(ROOT_STORAGE_CONTAINER_ID);
    when(scStore.range(request)).thenReturn(CompletableFuture.completedFuture(response));
    CompletableFuture<StorageContainerResponse> future = rangeStore.range(request);
    verify(scStore, times(1)).range(eq(request));
    assertTrue(response == future.get());
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 14 with StorageContainer

use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.

the class TestDefaultStorageContainerFactory method testCreate.

@Test
public void testCreate() throws Exception {
    OrderedScheduler scheduler = mock(OrderedScheduler.class);
    OrderedScheduler snapshotScheduler = mock(OrderedScheduler.class);
    MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
    ListeningScheduledExecutorService snapshotExecutor = mock(ListeningScheduledExecutorService.class);
    when(snapshotScheduler.chooseThread(anyLong())).thenReturn(snapshotExecutor);
    Mockito.doReturn(mock(ListenableScheduledFuture.class)).when(snapshotExecutor).scheduleWithFixedDelay(any(Runnable.class), anyInt(), anyInt(), any(TimeUnit.class));
    DefaultStorageContainerFactory factory = new DefaultStorageContainerFactory(new StorageConfiguration(new CompositeConfiguration()), (streamId, rangeId) -> streamId, scheduler, storeFactory, URI.create("distributedlog://127.0.0.1/stream/storage"));
    StorageContainer sc = factory.createStorageContainer(1234L);
    assertTrue(sc instanceof StorageContainerImpl);
    assertEquals(1234L, sc.getId());
}
Also used : MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) ListenableScheduledFuture(com.google.common.util.concurrent.ListenableScheduledFuture) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) TimeUnit(java.util.concurrent.TimeUnit) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Test(org.junit.Test)

Example 15 with StorageContainer

use of org.apache.bookkeeper.stream.storage.api.sc.StorageContainer in project bookkeeper by apache.

the class TestHelixStorageContainerManager method createRegistry.

private StorageContainerRegistryImpl createRegistry() {
    return new StorageContainerRegistryImpl((scId) -> {
        StorageContainer sc = mock(StorageContainer.class);
        when(sc.getId()).thenReturn(scId);
        when(sc.start()).thenReturn(FutureUtils.value(null));
        when(sc.stop()).thenReturn(FutureUtils.value(null));
        return sc;
    }, scheduler);
}
Also used : StorageContainerRegistryImpl(org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)

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