Search in sources :

Example 6 with StreamInfo

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

the class ClientStreamTracerTest method streamInfo_empty.

@Test
public void streamInfo_empty() {
    StreamInfo info = StreamInfo.newBuilder().build();
    assertThat(info.getCallOptions()).isSameInstanceAs(CallOptions.DEFAULT);
}
Also used : StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) Test(org.junit.Test)

Example 7 with StreamInfo

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

the class ClientStreamTracerTest method streamInfo_noEquality.

@Test
public void streamInfo_noEquality() {
    StreamInfo info1 = StreamInfo.newBuilder().setCallOptions(callOptions).build();
    StreamInfo info2 = StreamInfo.newBuilder().setCallOptions(callOptions).build();
    assertThat(info1).isNotSameInstanceAs(info2);
    assertThat(info1).isNotEqualTo(info2);
}
Also used : StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) Test(org.junit.Test)

Example 8 with StreamInfo

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

the class ClientStreamTracerTest method streamInfo_withInfo.

@Test
public void streamInfo_withInfo() {
    StreamInfo info = StreamInfo.newBuilder().setCallOptions(callOptions).build();
    assertThat(info.getCallOptions()).isSameInstanceAs(callOptions);
}
Also used : StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) Test(org.junit.Test)

Example 9 with StreamInfo

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

the class RetryTest method transparentRetryStatsRecorded.

@Test
public void transparentRetryStatsRecorded() throws Exception {
    startNewServer();
    createNewChannel();
    final AtomicBoolean originalAttemptFailed = new AtomicBoolean();
    class TransparentRetryTriggeringTracer extends ClientStreamTracer {

        @Override
        public void streamCreated(Attributes transportAttrs, Metadata metadata) {
            if (originalAttemptFailed.get()) {
                return;
            }
            // Send GOAWAY from server. The client may either receive GOAWAY or create the underlying
            // netty stream and write headers first, even we await server termination as below.
            // In the latter case, we rerun the test. We can also call localServer.shutdown() to trigger
            // GOAWAY, but it takes a lot longer time to gracefully shut down.
            localServer.shutdownNow();
            try {
                localServer.awaitTermination();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new AssertionError(e);
            }
        }

        @Override
        public void streamClosed(Status status) {
            if (originalAttemptFailed.get()) {
                return;
            }
            originalAttemptFailed.set(true);
            try {
                startNewServer();
                channel.resetConnectBackoff();
            } catch (Exception e) {
                throw new AssertionError("local server can not be restarted", e);
            }
        }
    }
    class TransparentRetryTracerFactory extends ClientStreamTracer.Factory {

        @Override
        public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) {
            return new TransparentRetryTriggeringTracer();
        }
    }
    CallOptions callOptions = CallOptions.DEFAULT.withWaitForReady().withStreamTracerFactory(new TransparentRetryTracerFactory());
    while (true) {
        ClientCall<String, Integer> call = channel.newCall(clientStreamingMethod, callOptions);
        call.start(mockCallListener, new Metadata());
        // original attempt
        assertRpcStartedRecorded();
        MetricsRecord record = clientStatsRecorder.pollRecord(5, SECONDS);
        assertThat(record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT)).isEqualTo(1);
        TagValue statusTag = record.tags.get(RpcMeasureConstants.GRPC_CLIENT_STATUS);
        if (statusTag.asString().equals(Code.UNAVAILABLE.toString())) {
            break;
        } else {
            // Due to race condition, GOAWAY is not received/processed before the stream is closed due
            // to connection error. Rerun the test.
            assertThat(statusTag.asString()).isEqualTo(Code.UNKNOWN.toString());
            assertRetryStatsRecorded(0, 0, 0);
            originalAttemptFailed.set(false);
        }
    }
    // retry attempt
    assertRpcStartedRecorded();
    ServerCall<String, Integer> serverCall = serverCalls.poll(5, SECONDS);
    serverCall.close(Status.INVALID_ARGUMENT, new Metadata());
    assertRpcStatusRecorded(Code.INVALID_ARGUMENT, 0, 0);
    assertRetryStatsRecorded(0, 1, 0);
}
Also used : Status(io.grpc.Status) ClientStreamTracer(io.grpc.ClientStreamTracer) MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord) Attributes(io.grpc.Attributes) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) TagValue(io.opencensus.tags.TagValue) Test(org.junit.Test)

Example 10 with StreamInfo

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

StreamInfo (io.grpc.ClientStreamTracer.StreamInfo)11 Test (org.junit.Test)9 ClientStreamTracer (io.grpc.ClientStreamTracer)7 Metadata (io.grpc.Metadata)6 CallOptions (io.grpc.CallOptions)5 Subchannel (io.grpc.LoadBalancer.Subchannel)3 MethodDescriptor (io.grpc.MethodDescriptor)3 Status (io.grpc.Status)3 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)2 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)2 ForwardingSubchannel (io.grpc.util.ForwardingSubchannel)2 Attributes (io.grpc.Attributes)1 Ticker (io.grpc.Deadline.Ticker)1 SocketStats (io.grpc.InternalChannelz.SocketStats)1 InternalMetadata (io.grpc.InternalMetadata)1 MetricsRecord (io.grpc.internal.testing.StatsTestUtils.MetricsRecord)1 TagValue (io.opencensus.tags.TagValue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1