use of io.grpc.testing.integration.TestServiceGrpc.TestServiceImplBase in project grpc-java by grpc.
the class MoreInProcessTest method asyncClientStreaming_serverErrorPriorToRequest.
@Test
public void asyncClientStreaming_serverErrorPriorToRequest() throws Exception {
// implement a service
final Status fakeError = Status.INVALID_ARGUMENT;
TestServiceImplBase clientStreamingImpl = new TestServiceImplBase() {
@Override
public StreamObserver<StreamingInputCallRequest> streamingInputCall(StreamObserver<StreamingInputCallResponse> responseObserver) {
// send error directly
responseObserver.onError(new StatusRuntimeException(fakeError));
responseObserver.onCompleted();
return new StreamObserver<StreamingInputCallRequest>() {
@Override
public void onNext(StreamingInputCallRequest value) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
}
};
serviceRegistry.addService(clientStreamingImpl);
// implement a client
final CountDownLatch finishLatch = new CountDownLatch(1);
final AtomicReference<StreamingInputCallResponse> responseRef = new AtomicReference<>();
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
StreamObserver<StreamingInputCallResponse> responseObserver = new StreamObserver<StreamingInputCallResponse>() {
@Override
public void onNext(StreamingInputCallResponse response) {
responseRef.set(response);
}
@Override
public void onError(Throwable t) {
throwableRef.set(t);
finishLatch.countDown();
}
@Override
public void onCompleted() {
finishLatch.countDown();
}
};
// make a gRPC call
TestServiceGrpc.newStub(inProcessChannel).streamingInputCall(responseObserver);
assertTrue(finishLatch.await(900, TimeUnit.MILLISECONDS));
assertEquals(fakeError.getCode(), Status.fromThrowable(throwableRef.get()).getCode());
assertNull(responseRef.get());
}
use of io.grpc.testing.integration.TestServiceGrpc.TestServiceImplBase in project grpc-java by grpc.
the class MoreInProcessTest method asyncClientStreaming_serverResponsePriorToRequest.
@Test
public void asyncClientStreaming_serverResponsePriorToRequest() throws Exception {
// implement a service
final StreamingInputCallResponse fakeResponse = StreamingInputCallResponse.newBuilder().setAggregatedPayloadSize(100).build();
TestServiceImplBase clientStreamingImpl = new TestServiceImplBase() {
@Override
public StreamObserver<StreamingInputCallRequest> streamingInputCall(StreamObserver<StreamingInputCallResponse> responseObserver) {
// send response directly
responseObserver.onNext(fakeResponse);
responseObserver.onCompleted();
return new StreamObserver<StreamingInputCallRequest>() {
@Override
public void onNext(StreamingInputCallRequest value) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
}
};
serviceRegistry.addService(clientStreamingImpl);
// implement a client
final CountDownLatch finishLatch = new CountDownLatch(1);
final AtomicReference<StreamingInputCallResponse> responseRef = new AtomicReference<>();
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
StreamObserver<StreamingInputCallResponse> responseObserver = new StreamObserver<StreamingInputCallResponse>() {
@Override
public void onNext(StreamingInputCallResponse response) {
responseRef.set(response);
}
@Override
public void onError(Throwable t) {
throwableRef.set(t);
finishLatch.countDown();
}
@Override
public void onCompleted() {
finishLatch.countDown();
}
};
// make a gRPC call
TestServiceGrpc.newStub(inProcessChannel).streamingInputCall(responseObserver);
assertTrue(finishLatch.await(900, TimeUnit.MILLISECONDS));
assertEquals(fakeResponse, responseRef.get());
assertNull(throwableRef.get());
}
use of io.grpc.testing.integration.TestServiceGrpc.TestServiceImplBase in project grpc-java by grpc.
the class MoreInProcessTest method asyncClientStreaming_erroneousServiceImpl.
@Test
public void asyncClientStreaming_erroneousServiceImpl() throws Exception {
// implement a service
TestServiceImplBase clientStreamingImpl = new TestServiceImplBase() {
@Override
public StreamObserver<StreamingInputCallRequest> streamingInputCall(StreamObserver<StreamingInputCallResponse> responseObserver) {
StreamObserver<StreamingInputCallRequest> requestObserver = new StreamObserver<StreamingInputCallRequest>() {
@Override
public void onNext(StreamingInputCallRequest value) {
throw new RuntimeException("unexpected error due to careless implementation of serviceImpl");
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
return requestObserver;
}
};
serviceRegistry.addService(clientStreamingImpl);
// implement a client
final CountDownLatch finishLatch = new CountDownLatch(1);
final AtomicReference<StreamingInputCallResponse> responseRef = new AtomicReference<>();
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
StreamObserver<StreamingInputCallResponse> responseObserver = new StreamObserver<StreamingInputCallResponse>() {
@Override
public void onNext(StreamingInputCallResponse response) {
responseRef.set(response);
}
@Override
public void onError(Throwable t) {
throwableRef.set(t);
finishLatch.countDown();
}
@Override
public void onCompleted() {
finishLatch.countDown();
}
};
// make a gRPC call
TestServiceGrpc.newStub(inProcessChannel).streamingInputCall(responseObserver).onNext(StreamingInputCallRequest.getDefaultInstance());
assertTrue(finishLatch.await(900, TimeUnit.MILLISECONDS));
assertEquals(Status.UNKNOWN, Status.fromThrowable(throwableRef.get()));
assertNull(responseRef.get());
}
Aggregations