use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class BeamFnDataGrpcMultiplexerTest method testInboundObserverBlocksTillConsumerConnects.
@Test
public void testInboundObserverBlocksTillConsumerConnects() throws Exception {
Collection<BeamFnApi.Elements> outboundValues = new ArrayList<>();
Collection<BeamFnApi.Elements.Data> inboundValues = new ArrayList<>();
BeamFnDataGrpcMultiplexer multiplexer = new BeamFnDataGrpcMultiplexer(DESCRIPTOR, (StreamObserver<BeamFnApi.Elements> inboundObserver) -> TestStreams.withOnNext(outboundValues::add).build());
ExecutorService executorService = Executors.newCachedThreadPool();
executorService.submit(new Runnable() {
@Override
public void run() {
// Purposefully sleep to simulate a delay in a consumer connecting.
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
multiplexer.futureForKey(OUTPUT_LOCATION).complete(inboundValues::add);
}
});
multiplexer.getInboundObserver().onNext(ELEMENTS);
assertTrue(multiplexer.consumers.containsKey(OUTPUT_LOCATION));
// Ensure that when we see a terminal Elements object, we remove the consumer
multiplexer.getInboundObserver().onNext(TERMINAL_ELEMENTS);
assertFalse(multiplexer.consumers.containsKey(OUTPUT_LOCATION));
// Assert that normal and terminal Elements are passed to the consumer
assertThat(inboundValues, contains(ELEMENTS.getData(0), TERMINAL_ELEMENTS.getData(0)));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver 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);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver 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.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver 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.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver 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);
}
Aggregations