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);
}
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;
}
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;
}
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());
}
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();
}
Aggregations