use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.
the class CascadingTest method startChainingServer.
/**
* Create a chain of client to server calls which can be cancelled top down.
*
* @return a Future that completes when call chain is created
*/
private Future<?> startChainingServer(final int depthThreshold) throws IOException {
final AtomicInteger serversReady = new AtomicInteger();
final SettableFuture<Void> chainReady = SettableFuture.create();
class ChainingService extends TestServiceGrpc.TestServiceImplBase {
@Override
public void unaryCall(final SimpleRequest request, final StreamObserver<SimpleResponse> responseObserver) {
((ServerCallStreamObserver) responseObserver).setOnCancelHandler(new Runnable() {
@Override
public void run() {
receivedCancellations.countDown();
}
});
if (serversReady.incrementAndGet() == depthThreshold) {
// Stop recursion
chainReady.set(null);
return;
}
Context.currentContextExecutor(otherWork).execute(new Runnable() {
@Override
public void run() {
try {
blockingStub.unaryCall(request);
} catch (StatusRuntimeException e) {
Status status = e.getStatus();
if (status.getCode() == Status.Code.CANCELLED) {
observedCancellations.countDown();
} else {
responseObserver.onError(e);
}
}
}
});
}
}
server = InProcessServerBuilder.forName("channel").executor(otherWork).addService(new ChainingService()).build().start();
return chainReady;
}
use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.
the class CascadingTest method testDeadlinePropagation.
@Test
public void testDeadlinePropagation() throws Exception {
final AtomicInteger recursionDepthRemaining = new AtomicInteger(3);
final SettableFuture<Deadline> finalDeadline = SettableFuture.create();
class DeadlineSaver extends TestServiceGrpc.TestServiceImplBase {
@Override
public void unaryCall(final SimpleRequest request, final StreamObserver<SimpleResponse> responseObserver) {
Context.currentContextExecutor(otherWork).execute(new Runnable() {
@Override
public void run() {
try {
if (recursionDepthRemaining.decrementAndGet() == 0) {
finalDeadline.set(Context.current().getDeadline());
responseObserver.onNext(SimpleResponse.getDefaultInstance());
} else {
responseObserver.onNext(blockingStub.unaryCall(request));
}
responseObserver.onCompleted();
} catch (Exception ex) {
responseObserver.onError(ex);
}
}
});
}
}
server = InProcessServerBuilder.forName("channel").executor(otherWork).addService(new DeadlineSaver()).build().start();
Deadline initialDeadline = Deadline.after(1, TimeUnit.MINUTES);
blockingStub.withDeadline(initialDeadline).unaryCall(SimpleRequest.getDefaultInstance());
assertNotSame(initialDeadline, finalDeadline);
// Since deadline is re-calculated at each hop, some variance is acceptable and expected.
assertAbout(deadline()).that(finalDeadline.get()).isWithin(1, TimeUnit.SECONDS).of(initialDeadline);
}
use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.
the class TransportCompressionTest method compresses.
@Test
public void compresses() {
expectFzip = true;
final SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(314159).setResponseCompression(CompressionType.GZIP).setResponseType(PayloadType.COMPRESSABLE).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[314159]))).build();
assertEquals(goldenResponse, blockingStub.unaryCall(request));
// Assert that compression took place
assertTrue(FZIPPER.anyRead);
assertTrue(FZIPPER.anyWritten);
}
use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.
the class StubConfigTest method testStubCallOptionsPopulatedToNewCall.
@Test
public void testStubCallOptionsPopulatedToNewCall() {
TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
CallOptions options1 = stub.getCallOptions();
SimpleRequest request = SimpleRequest.getDefaultInstance();
stub.unaryCall(request, responseObserver);
verify(channel).newCall(same(TestServiceGrpc.METHOD_UNARY_CALL), same(options1));
stub = stub.withDeadlineAfter(2, NANOSECONDS);
CallOptions options2 = stub.getCallOptions();
assertNotSame(options1, options2);
stub.unaryCall(request, responseObserver);
verify(channel).newCall(same(TestServiceGrpc.METHOD_UNARY_CALL), same(options2));
}
use of io.grpc.testing.integration.Messages.SimpleRequest in project grpc-java by grpc.
the class AbstractInteropTest method veryLargeResponse.
@Test(timeout = 30000)
public void veryLargeResponse() throws Exception {
assumeEnoughMemory();
final SimpleRequest request = SimpleRequest.newBuilder().setResponseSize(unaryPayloadLength()).setResponseType(PayloadType.COMPRESSABLE).build();
final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[unaryPayloadLength()]))).build();
assertEquals(goldenResponse, blockingStub.unaryCall(request));
}
Aggregations