Search in sources :

Example 1 with Ticker

use of io.grpc.Deadline.Ticker in project grpc-java by grpc.

the class RetryTest method serverCancelledAndClientDeadlineExceeded.

@Test
public void serverCancelledAndClientDeadlineExceeded() throws Exception {
    startNewServer();
    createNewChannel();
    class CloseDelayedTracer extends ClientStreamTracer {

        @Override
        public void streamClosed(Status status) {
            fakeClock.forwardTime(10, SECONDS);
        }
    }
    class CloseDelayedTracerFactory extends ClientStreamTracer.Factory {

        @Override
        public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) {
            return new CloseDelayedTracer();
        }
    }
    CallOptions callOptions = CallOptions.DEFAULT.withDeadline(Deadline.after(10, SECONDS, new Ticker() {

        @Override
        public long nanoTime() {
            return fakeClock.getTicker().read();
        }
    })).withStreamTracerFactory(new CloseDelayedTracerFactory());
    ClientCall<String, Integer> call = channel.newCall(clientStreamingMethod, callOptions);
    call.start(mockCallListener, new Metadata());
    assertRpcStartedRecorded();
    ServerCall<String, Integer> serverCall = serverCalls.poll(5, SECONDS);
    serverCall.close(Status.CANCELLED, new Metadata());
    assertRpcStatusRecorded(Code.DEADLINE_EXCEEDED, 10_000, 0);
    assertRetryStatsRecorded(0, 0, 0);
}
Also used : Status(io.grpc.Status) ClientStreamTracer(io.grpc.ClientStreamTracer) Ticker(io.grpc.Deadline.Ticker) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) Test(org.junit.Test)

Aggregations

CallOptions (io.grpc.CallOptions)1 ClientStreamTracer (io.grpc.ClientStreamTracer)1 StreamInfo (io.grpc.ClientStreamTracer.StreamInfo)1 Ticker (io.grpc.Deadline.Ticker)1 Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1 Test (org.junit.Test)1