Search in sources :

Example 1 with TraceServiceStub

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

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