Search in sources :

Example 46 with ClientStreamTracer

use of io.grpc.ClientStreamTracer 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)

Example 47 with ClientStreamTracer

use of io.grpc.ClientStreamTracer in project grpc-java by grpc.

the class RetriableStream method createSubstream.

private Substream createSubstream(int previousAttemptCount, boolean isTransparentRetry) {
    Substream sub = new Substream(previousAttemptCount);
    // one tracer per substream
    final ClientStreamTracer bufferSizeTracer = new BufferSizeTracer(sub);
    ClientStreamTracer.Factory tracerFactory = new ClientStreamTracer.Factory() {

        @Override
        public ClientStreamTracer newClientStreamTracer(ClientStreamTracer.StreamInfo info, Metadata headers) {
            return bufferSizeTracer;
        }
    };
    Metadata newHeaders = updateHeaders(headers, previousAttemptCount);
    // NOTICE: This set _must_ be done before stream.start() and it actually is.
    sub.stream = newSubstream(newHeaders, tracerFactory, previousAttemptCount, isTransparentRetry);
    return sub;
}
Also used : ClientStreamTracer(io.grpc.ClientStreamTracer) Metadata(io.grpc.Metadata)

Example 48 with ClientStreamTracer

use of io.grpc.ClientStreamTracer in project grpc-java by grpc.

the class GrpcUtil method getClientStreamTracers.

/**
 * Gets stream tracers based on CallOptions.
 */
public static ClientStreamTracer[] getClientStreamTracers(CallOptions callOptions, Metadata headers, int previousAttempts, boolean isTransparentRetry) {
    List<ClientStreamTracer.Factory> factories = callOptions.getStreamTracerFactories();
    ClientStreamTracer[] tracers = new ClientStreamTracer[factories.size() + 1];
    StreamInfo streamInfo = StreamInfo.newBuilder().setCallOptions(callOptions).setPreviousAttempts(previousAttempts).setIsTransparentRetry(isTransparentRetry).build();
    for (int i = 0; i < factories.size(); i++) {
        tracers[i] = factories.get(i).newClientStreamTracer(streamInfo, headers);
    }
    // Reserved to be set later by the lb as per the API contract of ClientTransport.newStream().
    // See also GrpcUtil.getTransportFromPickResult()
    tracers[tracers.length - 1] = NOOP_TRACER;
    return tracers;
}
Also used : ClientStreamTracer(io.grpc.ClientStreamTracer) StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) ThreadFactory(java.util.concurrent.ThreadFactory)

Example 49 with ClientStreamTracer

use of io.grpc.ClientStreamTracer in project grpc-java by grpc.

the class FailingClientStream method start.

@Override
public void start(ClientStreamListener listener) {
    Preconditions.checkState(!started, "already started");
    started = true;
    for (ClientStreamTracer tracer : tracers) {
        tracer.streamClosed(error);
    }
    listener.closed(error, rpcProgress, new Metadata());
}
Also used : ClientStreamTracer(io.grpc.ClientStreamTracer) Metadata(io.grpc.Metadata)

Example 50 with ClientStreamTracer

use of io.grpc.ClientStreamTracer in project grpc-java by grpc.

the class CensusModulesTest method traceHeaders_propagateSpanContext.

@Test
public void traceHeaders_propagateSpanContext() throws Exception {
    CallAttemptsTracerFactory callTracer = censusTracing.newClientCallTracer(fakeClientParentSpan, method);
    Metadata headers = new Metadata();
    ClientStreamTracer streamTracer = callTracer.newClientStreamTracer(STREAM_INFO, headers);
    streamTracer.streamCreated(Attributes.EMPTY, headers);
    assertThat(headers.keys()).isNotEmpty();
}
Also used : ClientStreamTracer(io.grpc.ClientStreamTracer) Metadata(io.grpc.Metadata) CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory) Test(org.junit.Test)

Aggregations

ClientStreamTracer (io.grpc.ClientStreamTracer)57 Metadata (io.grpc.Metadata)54 Test (org.junit.Test)44 CallOptions (io.grpc.CallOptions)28 Subchannel (io.grpc.LoadBalancer.Subchannel)22 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)21 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)19 ForwardingSubchannel (io.grpc.util.ForwardingSubchannel)18 MethodDescriptor (io.grpc.MethodDescriptor)16 Status (io.grpc.Status)14 ChannelLogger (io.grpc.ChannelLogger)11 ClientTransportOptions (io.grpc.internal.ClientTransportFactory.ClientTransportOptions)10 ProxiedSocketAddress (io.grpc.ProxiedSocketAddress)9 StreamInfo (io.grpc.ClientStreamTracer.StreamInfo)8 CallAttemptsTracerFactory (io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)8 SocketAddress (java.net.SocketAddress)8 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)7 Helper (io.grpc.LoadBalancer.Helper)7 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)7 ManagedChannel (io.grpc.ManagedChannel)7