Search in sources :

Example 1 with StatsComponentImpl

use of io.opencensus.impl.stats.StatsComponentImpl in project grpc-java by grpc.

the class CensusModulesTest method newTagsPopulateOldViews.

@Deprecated
@Test
public void newTagsPopulateOldViews() throws InterruptedException {
    StatsComponent localStats = new StatsComponentImpl();
    // Test views that contain both of the remap tags: method & status.
    localStats.getViewManager().registerView(RpcViewConstants.RPC_CLIENT_ERROR_COUNT_VIEW);
    localStats.getViewManager().registerView(RpcViewConstants.GRPC_CLIENT_COMPLETED_RPC_VIEW);
    CensusStatsModule localCensusStats = new CensusStatsModule(tagger, tagCtxSerializer, localStats.getStatsRecorder(), fakeClock.getStopwatchSupplier(), false, false, true, false, /* real-time */
    true);
    CensusStatsModule.CallAttemptsTracerFactory callAttemptsTracerFactory = new CensusStatsModule.CallAttemptsTracerFactory(localCensusStats, tagger.empty(), method.getFullMethodName());
    Metadata headers = new Metadata();
    ClientStreamTracer tracer = callAttemptsTracerFactory.newClientStreamTracer(STREAM_INFO, headers);
    tracer.streamCreated(Attributes.EMPTY, headers);
    fakeClock.forwardTime(30, MILLISECONDS);
    Status status = Status.PERMISSION_DENIED.withDescription("No you don't");
    tracer.streamClosed(status);
    callAttemptsTracerFactory.callEnded(status);
    // Give OpenCensus a chance to update the views asynchronously.
    Thread.sleep(100);
    assertWithMessage("Legacy error count view had unexpected count").that(getAggregationValueAsLong(localStats, RpcViewConstants.RPC_CLIENT_ERROR_COUNT_VIEW, ImmutableList.of(TagValue.create("PERMISSION_DENIED"), TagValue.create(method.getFullMethodName())))).isEqualTo(1);
    assertWithMessage("New error count view had unexpected count").that(getAggregationValueAsLong(localStats, RpcViewConstants.GRPC_CLIENT_COMPLETED_RPC_VIEW, ImmutableList.of(TagValue.create(method.getFullMethodName()), TagValue.create("PERMISSION_DENIED")))).isEqualTo(1);
}
Also used : Status(io.grpc.Status) ClientStreamTracer(io.grpc.ClientStreamTracer) StatsComponentImpl(io.opencensus.impl.stats.StatsComponentImpl) Metadata(io.grpc.Metadata) StatsComponent(io.opencensus.stats.StatsComponent) CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory) Test(org.junit.Test)

Aggregations

ClientStreamTracer (io.grpc.ClientStreamTracer)1 Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1 CallAttemptsTracerFactory (io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)1 StatsComponentImpl (io.opencensus.impl.stats.StatsComponentImpl)1 StatsComponent (io.opencensus.stats.StatsComponent)1 Test (org.junit.Test)1