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