use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testDeleteNamespaceFailure.
@Test
public void testDeleteNamespaceFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
DeleteNamespaceRequest deleteReq = createDeleteNamespaceRequest(nsName);
when(rangeService.deleteNamespace(deleteReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<DeleteNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<DeleteNamespaceResponse> streamObserver = new StreamObserver<DeleteNamespaceResponse>() {
@Override
public void onNext(DeleteNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.deleteNamespace(DeleteNamespaceRequest.newBuilder().setName(nsName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(deleteResp, resultHolder.get());
verify(rangeService, times(1)).deleteNamespace(deleteReq);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetStreamFailure.
@Test
public void testGetStreamFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
GetStreamRequest getReq = createGetStreamRequest(nsName, streamName);
when(rangeService.getStream(getReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<GetStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<GetStreamResponse> streamObserver = new StreamObserver<GetStreamResponse>() {
@Override
public void onNext(GetStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.getStream(GetStreamRequest.newBuilder().setStreamName(StreamName.newBuilder().setColName(nsName).setStreamName(streamName)).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(getResp, resultHolder.get());
verify(rangeService, times(1)).getStream(getReq);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testDeleteStreamSuccess.
@Test
public void testDeleteStreamSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).build();
DeleteStreamRequest deleteReq = createDeleteStreamRequest(nsName, streamName);
when(rangeService.deleteStream(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
AtomicReference<DeleteStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<DeleteStreamResponse> streamObserver = new StreamObserver<DeleteStreamResponse>() {
@Override
public void onNext(DeleteStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.deleteStream(DeleteStreamRequest.newBuilder().setColName(nsName).setName(streamName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(deleteResp == resultHolder.get());
verify(rangeService, times(1)).deleteStream(deleteReq);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetNamespaceFailure.
@Test
public void testGetNamespaceFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetNamespaceResponse getResp = GetNamespaceResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
GetNamespaceRequest getReq = createGetNamespaceRequest(nsName);
when(rangeService.getNamespace(getReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<GetNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<GetNamespaceResponse> streamObserver = new StreamObserver<GetNamespaceResponse>() {
@Override
public void onNext(GetNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.getNamespace(GetNamespaceRequest.newBuilder().setName(nsName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(getResp, resultHolder.get());
verify(rangeService, times(1)).getNamespace(getReq);
}
use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateStreamSuccess.
//
// Test Stream API
//
@Test
public void testCreateStreamSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build();
CreateStreamRequest createReq = createCreateStreamRequest(nsName, streamName, DEFAULT_STREAM_CONF);
when(rangeService.createStream(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
AtomicReference<CreateStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<CreateStreamResponse> streamObserver = new StreamObserver<CreateStreamResponse>() {
@Override
public void onNext(CreateStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.createStream(CreateStreamRequest.newBuilder().setColName(nsName).setName(streamName).setStreamConf(DEFAULT_STREAM_CONF).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(createResp == resultHolder.get());
verify(rangeService, times(1)).createStream(createReq);
}
Aggregations