Search in sources :

Example 1 with UpdatedLibraryConfig

use of io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig in project instrumentation-java by census-instrumentation.

the class TraceProtoUtilsTest method applyUpdatedConfig.

@Test
public void applyUpdatedConfig() {
    TraceConfig configProto = TraceConfig.newBuilder().setProbabilitySampler(ProbabilitySampler.newBuilder().setSamplingProbability(0.01).build()).build();
    UpdatedLibraryConfig updatedLibraryConfig = UpdatedLibraryConfig.newBuilder().setConfig(configProto).build();
    TraceParams traceParams = TraceProtoUtils.getUpdatedTraceParams(updatedLibraryConfig, mockTraceConfig);
    TraceParams expectedParams = DEFAULT_PARAMS.toBuilder().setSampler(Samplers.probabilitySampler(0.01)).build();
    Mockito.verify(mockTraceConfig, Mockito.times(1)).getActiveTraceParams();
    assertThat(traceParams).isEqualTo(expectedParams);
}
Also used : UpdatedLibraryConfig(io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig) TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Example 2 with UpdatedLibraryConfig

use of io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig in project instrumentation-java by census-instrumentation.

the class OcAgentTraceServiceRpcHandlersTest method config_CreateAndSend.

@Test
public void config_CreateAndSend() throws InterruptedException {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    traceServiceGrpc.setCountDownLatch(countDownLatch);
    // Config RPC handler needs to be running in another thread.
    Runnable configRunnable = new Runnable() {

        @Override
        public void run() {
            TraceServiceStub stub = getStub(serverName);
            OcAgentTraceServiceConfigRpcHandler configRpcHandler = OcAgentTraceServiceConfigRpcHandler.create(stub, mockTraceConfig);
            // connection should succeed
            assertThat(configRpcHandler.isCompleted()).isFalse();
            // this will block this thread
            configRpcHandler.sendInitialMessage(NODE);
        }
    };
    Thread configThread = new Thread(configRunnable);
    configThread.setDaemon(true);
    configThread.setName("TestConfigRpcHandlerThread");
    configThread.start();
    // Wait until fake agent received the first message.
    countDownLatch.await();
    traceServiceGrpc.closeConfigStream();
    // Verify fake Agent (server) received the expected CurrentLibraryConfig.
    CurrentLibraryConfig expectedCurrentConfig = CurrentLibraryConfig.newBuilder().setNode(NODE).setConfig(TRACE_CONFIG_DEFAULT_PROTO).build();
    assertThat(traceServiceGrpc.getCurrentLibraryConfigs()).containsExactly(expectedCurrentConfig);
    // Verify ConfigRpcHandler (client) received the expected UpdatedLibraryConfig.
    TraceParams expectedParams = TraceProtoUtils.getUpdatedTraceParams(traceServiceGrpc.getUpdatedLibraryConfig(), mockTraceConfig);
    verify(mockTraceConfig, times(1)).updateActiveTraceParams(expectedParams);
}
Also used : CurrentLibraryConfig(io.opencensus.proto.agent.trace.v1.CurrentLibraryConfig) TraceServiceStub(io.opencensus.proto.agent.trace.v1.TraceServiceGrpc.TraceServiceStub) CountDownLatch(java.util.concurrent.CountDownLatch) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Aggregations

TraceParams (io.opencensus.trace.config.TraceParams)2 Test (org.junit.Test)2 CurrentLibraryConfig (io.opencensus.proto.agent.trace.v1.CurrentLibraryConfig)1 TraceServiceStub (io.opencensus.proto.agent.trace.v1.TraceServiceGrpc.TraceServiceStub)1 UpdatedLibraryConfig (io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig)1 TraceConfig (io.opencensus.proto.trace.v1.TraceConfig)1 CountDownLatch (java.util.concurrent.CountDownLatch)1