use of io.opencensus.proto.agent.trace.v1.TraceServiceGrpc.TraceServiceStub 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