use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TableRequestProcessorTest method testProcess.
private void testProcess(RequestCase type) throws Exception {
@Cleanup("shutdown") ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
StorageContainerChannel scChannel = mock(StorageContainerChannel.class);
CompletableFuture<StorageServerChannel> serverChannelFuture = FutureUtils.createFuture();
when(scChannel.getStorageContainerChannelFuture()).thenReturn(serverChannelFuture);
StorageContainerResponse.Builder respBuilder = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS);
switch(type) {
case KV_PUT_REQ:
respBuilder.setKvPutResp(PutResponse.newBuilder().build());
break;
case KV_DELETE_REQ:
respBuilder.setKvDeleteResp(DeleteRangeResponse.newBuilder().build());
break;
case KV_RANGE_REQ:
respBuilder.setKvRangeResp(RangeResponse.newBuilder().build());
break;
case KV_INCR_REQ:
respBuilder.setKvIncrResp(IncrementResponse.newBuilder().build());
break;
case KV_TXN_REQ:
respBuilder.setKvTxnResp(TxnResponse.newBuilder().build());
break;
default:
break;
}
StorageContainerResponse response = respBuilder.build();
AtomicReference<StorageContainerRequest> receivedRequest = new AtomicReference<>(null);
AtomicReference<RequestCase> receivedRequestType = new AtomicReference<>(null);
TableServiceImplBase tableService = new TableServiceImplBase() {
@Override
public void range(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
receivedRequest.set(request);
receivedRequestType.set(KV_RANGE_REQ);
complete(responseObserver);
}
@Override
public void put(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
receivedRequest.set(request);
receivedRequestType.set(KV_PUT_REQ);
complete(responseObserver);
}
@Override
public void delete(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
receivedRequest.set(request);
receivedRequestType.set(KV_DELETE_REQ);
complete(responseObserver);
}
@Override
public void txn(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
receivedRequest.set(request);
receivedRequestType.set(KV_TXN_REQ);
complete(responseObserver);
}
@Override
public void increment(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
receivedRequest.set(request);
receivedRequestType.set(KV_INCR_REQ);
complete(responseObserver);
}
private void complete(StreamObserver<StorageContainerResponse> responseStreamObserver) {
responseStreamObserver.onNext(response);
responseStreamObserver.onCompleted();
}
};
serviceRegistry.addService(tableService.bindService());
StorageServerChannel ssChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
serverChannelFuture.complete(ssChannel);
StorageContainerRequest.Builder requestBuilder = StorageContainerRequest.newBuilder();
switch(type) {
case KV_PUT_REQ:
requestBuilder.setKvPutReq(PutRequest.newBuilder().build());
break;
case KV_DELETE_REQ:
requestBuilder.setKvDeleteReq(DeleteRangeRequest.newBuilder().build());
break;
case KV_RANGE_REQ:
requestBuilder.setKvRangeReq(RangeRequest.newBuilder().build());
break;
case KV_INCR_REQ:
requestBuilder.setKvIncrReq(IncrementRequest.newBuilder().build());
break;
case KV_TXN_REQ:
requestBuilder.setKvTxnReq(TxnRequest.newBuilder().build());
break;
default:
break;
}
StorageContainerRequest request = requestBuilder.build();
TableRequestProcessor<String> processor = TableRequestProcessor.of(request, resp -> "test", scChannel, scheduler);
assertEquals("test", FutureUtils.result(processor.process()));
assertSame(request, receivedRequest.get());
assertEquals(type, receivedRequestType.get());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestMetaRangeClientImpl method testGetActiveStreamRangesFailure.
@Test
public void testGetActiveStreamRangesFailure() throws Exception {
CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
metaRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
MetaRangeServiceImplBase metaRangeService = new MetaRangeServiceImplBase() {
@Override
public void getActiveRanges(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
responseObserver.onError(new StatusRuntimeException(Status.INTERNAL));
}
};
serviceRegistry.addService(metaRangeService.bindService());
StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
serviceFuture.complete(rsChannel);
CompletableFuture<HashStreamRanges> getFuture = metaRangeClient.getActiveDataRanges();
try {
getFuture.get();
fail("should fail on rpc failure");
} catch (ExecutionException ee) {
assertNotNull(ee.getCause());
assertTrue(ee.getCause() instanceof StatusRuntimeException);
StatusRuntimeException se = (StatusRuntimeException) ee.getCause();
assertEquals(Status.INTERNAL, se.getStatus());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateStreamFailure.
@Test
public void testCreateStreamFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
CreateStreamRequest createReq = createCreateStreamRequest(nsName, streamName, DEFAULT_STREAM_CONF);
when(rangeService.createStream(createReq)).thenReturn(FutureUtils.exception(CAUSE));
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());
assertEquals(createResp, resultHolder.get());
verify(rangeService, times(1)).createStream(createReq);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestGrpcRootRangeService method testDeleteNamespaceSuccess.
@Test
public void testDeleteNamespaceSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).build();
DeleteNamespaceRequest deleteReq = createDeleteNamespaceRequest(nsName);
when(rangeService.deleteNamespace(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
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());
assertTrue(deleteResp == resultHolder.get());
verify(rangeService, times(1)).deleteNamespace(deleteReq);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetNamespaceSuccess.
@Test
public void testGetNamespaceSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetNamespaceResponse getResp = GetNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).setColProps(namespaceProps).build();
GetNamespaceRequest getReq = createGetNamespaceRequest(nsName);
when(rangeService.getNamespace(getReq)).thenReturn(CompletableFuture.completedFuture(getResp));
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());
assertTrue(getResp == resultHolder.get());
verify(rangeService, times(1)).getNamespace(getReq);
}
Aggregations