use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateNamespaceSuccess.
//
// Test Namespace API
//
@Test
public void testCreateNamespaceSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateNamespaceResponse createResp = CreateNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).setColProps(namespaceProps).build();
CreateNamespaceRequest createReq = createCreateNamespaceRequest(nsName, namespaceConf);
when(rangeService.createNamespace(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
AtomicReference<CreateNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<CreateNamespaceResponse> streamObserver = new StreamObserver<CreateNamespaceResponse>() {
@Override
public void onNext(CreateNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.createNamespace(CreateNamespaceRequest.newBuilder().setName(nsName).setColConf(namespaceConf).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(createResp == resultHolder.get());
verify(rangeService, times(1)).createNamespace(createReq);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcMetaRangeService method testGetActiveRangesException.
@Test
public void testGetActiveRangesException() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
when(rangeService.getActiveRanges(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
grpcService.getActiveRanges(request, responseObserver);
responseObserver.verifyException(Status.NOT_FOUND);
verify(rangeService, times(1)).getActiveRanges(request);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcMetaRangeService method testGetActiveRangesFailure.
@Test
public void testGetActiveRangesFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
when(rangeService.getActiveRanges(request)).thenReturn(FutureUtils.exception(CAUSE));
TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
grpcService.getActiveRanges(request, responseObserver);
responseObserver.verifySuccess(response);
verify(rangeService, times(1)).getActiveRanges(request);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcMetaRangeService method testGetActiveRangesSuccess.
//
// Meta KeyRange Server Requests tests
//
@Test
public void testGetActiveRangesSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setGetActiveRangesResp(GetActiveRangesResponse.newBuilder()).build();
when(rangeService.getActiveRanges(request)).thenReturn(CompletableFuture.completedFuture(response));
TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
grpcService.getActiveRanges(request, responseObserver);
responseObserver.verifySuccess(response);
verify(rangeService, times(1)).getActiveRanges(request);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateNamespaceFailure.
@Test
public void testCreateNamespaceFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateNamespaceResponse createResp = CreateNamespaceResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
CreateNamespaceRequest createReq = createCreateNamespaceRequest(nsName, namespaceConf);
when(rangeService.createNamespace(createReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<CreateNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<CreateNamespaceResponse> streamObserver = new StreamObserver<CreateNamespaceResponse>() {
@Override
public void onNext(CreateNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.createNamespace(CreateNamespaceRequest.newBuilder().setName(nsName).setColConf(namespaceConf).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(createResp, resultHolder.get());
verify(rangeService, times(1)).createNamespace(createReq);
}
Aggregations