Search in sources :

Example 26 with StorageContainerRequest

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest in project bookkeeper by apache.

the class TestMetaRangeClientImpl method testGetActiveStreamRanges.

@Test
public void testGetActiveStreamRanges() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    metaRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    // create response
    GetActiveRangesResponse getActiveRangesResponse = GetActiveRangesResponse.newBuilder().addRanges(buildRelatedRange(Long.MIN_VALUE, 0L, 123L, 1L, Lists.newArrayList(113L))).addRanges(buildRelatedRange(0L, Long.MAX_VALUE, 124L, 2L, Lists.newArrayList(114L))).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setGetActiveRangesResp(getActiveRangesResponse).build();
    MetaRangeServiceImplBase metaRangeService = new MetaRangeServiceImplBase() {

        @Override
        public void getActiveRanges(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            responseObserver.onNext(response);
            responseObserver.onCompleted();
        }
    };
    serviceRegistry.addService(metaRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    HashStreamRanges expectedStream = createActiveRanges(response.getGetActiveRangesResp());
    CompletableFuture<HashStreamRanges> getFuture = metaRangeClient.getActiveDataRanges();
    assertEquals(expectedStream, getFuture.get());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) HashStreamRanges(org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) GetActiveRangesResponse(org.apache.bookkeeper.stream.proto.storage.GetActiveRangesResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) MetaRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 27 with StorageContainerRequest

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest 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 28 with StorageContainerRequest

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest in project bookkeeper by apache.

the class StorageContainerImplTest method testPutWhenTableStoreCached.

@Test
public void testPutWhenTableStoreCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.put(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    container.getTableStoreCache().getTableStores().put(RID, trStore);
    StorageContainerRequest request = newStorageContainerRequest(KV_PUT_REQ);
    StorageContainerResponse response = FutureUtils.result(container.put(request));
    assertSame(expectedResp, response);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 29 with StorageContainerRequest

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest in project bookkeeper by apache.

the class StorageContainerImplTest method testRangeWhenTableStoreCached.

@Test
public void testRangeWhenTableStoreCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.range(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    container.getTableStoreCache().getTableStores().put(RID, trStore);
    StorageContainerRequest request = newStorageContainerRequest(KV_RANGE_REQ);
    StorageContainerResponse response = FutureUtils.result(container.range(request));
    assertSame(expectedResp, response);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 30 with StorageContainerRequest

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest in project bookkeeper by apache.

the class StorageContainerImplTest method testTxnWhenTableStoreCached.

@Test
public void testTxnWhenTableStoreCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.txn(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    container.getTableStoreCache().getTableStores().put(RID, trStore);
    StorageContainerRequest request = newStorageContainerRequest(KV_TXN_REQ);
    StorageContainerResponse response = FutureUtils.result(container.txn(request));
    assertSame(expectedResp, response);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Aggregations

StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)33 Test (org.junit.Test)31 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)27 TestResponseObserver (org.apache.bookkeeper.stream.server.TestResponseObserver)12 RangeStore (org.apache.bookkeeper.stream.storage.api.RangeStore)9 StatusRuntimeException (io.grpc.StatusRuntimeException)5 ByteBuf (io.netty.buffer.ByteBuf)4 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)4 StreamObserver (io.grpc.stub.StreamObserver)3 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)3 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)3 HashStreamRanges (org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges)2 DeleteRangeRequest (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest)2 MetaRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase)2 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Cleanup (lombok.Cleanup)1 StorageContainerChannel (org.apache.bookkeeper.clients.impl.container.StorageContainerChannel)1 KvUtils.newIncrementRequest (org.apache.bookkeeper.clients.impl.kv.KvUtils.newIncrementRequest)1