Search in sources :

Example 6 with ServiceManagerImpl

use of com.newrelic.agent.service.ServiceManagerImpl in project newrelic-java-agent by newrelic.

the class AgentLinkingMetadataTest method getLogEventLinkingMetadata.

@Test
public void getLogEventLinkingMetadata() {
    // Given
    final String expectedTraceId = "traceId1234";
    final String expectedSpanId = "spanId5678";
    final String expectedEntityGuid = "entityGuid91011";
    final String expectedEntityName = "entityName91011";
    TraceMetadataImpl traceMetadataMock = mock(TraceMetadataImpl.class);
    ServiceManagerImpl serviceManagerMock = mock(ServiceManagerImpl.class);
    RPMServiceManagerImpl rpmServiceManagerMock = mock(RPMServiceManagerImpl.class);
    RPMService rpmServiceMock = mock(RPMService.class);
    ConfigServiceImpl configServiceMock = mock(ConfigServiceImpl.class);
    AgentConfigImpl agentConfigMock = mock(AgentConfigImpl.class);
    ServiceFactory.setServiceManager(serviceManagerMock);
    // When
    when(traceMetadataMock.getTraceId()).thenReturn(expectedTraceId);
    when(traceMetadataMock.getSpanId()).thenReturn(expectedSpanId);
    when(serviceManagerMock.getRPMServiceManager()).thenReturn(rpmServiceManagerMock);
    when(serviceManagerMock.getConfigService()).thenReturn(configServiceMock);
    when(rpmServiceManagerMock.getRPMService()).thenReturn(rpmServiceMock);
    when(configServiceMock.getDefaultAgentConfig()).thenReturn(agentConfigMock);
    when(agentConfigMock.getApplicationName()).thenReturn(expectedEntityName);
    when(rpmServiceMock.getEntityGuid()).thenReturn(expectedEntityGuid);
    // Then
    Map<String, String> linkingMetadata = AgentLinkingMetadata.getLogEventLinkingMetadata(traceMetadataMock, ServiceFactory.getConfigService(), ServiceFactory.getRPMService());
    assertFalse("linkingMetadata map shouldn't be empty", linkingMetadata.isEmpty());
    // Can't assert on a specific hostname value as it will resolve to the actual hostname of the machine running the test
    assertFalse("hostname shouldn't be empty", linkingMetadata.get(AgentLinkingMetadata.HOSTNAME).isEmpty());
    assertFalse("entity.type should not be included in LogEvent linking metadata", linkingMetadata.containsKey(AgentLinkingMetadata.ENTITY_TYPE));
    assertEquals(expectedEntityName, linkingMetadata.get(AgentLinkingMetadata.ENTITY_NAME));
    assertEquals(expectedEntityGuid, linkingMetadata.get(AgentLinkingMetadata.ENTITY_GUID));
    assertEquals(expectedTraceId, linkingMetadata.get(AgentLinkingMetadata.TRACE_ID));
    assertEquals(expectedSpanId, linkingMetadata.get(AgentLinkingMetadata.SPAN_ID));
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Test(org.junit.Test)

Aggregations

ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)6 AgentConfigImpl (com.newrelic.agent.config.AgentConfigImpl)4 ConfigServiceImpl (com.newrelic.agent.config.ConfigServiceImpl)4 Test (org.junit.Test)4 ServiceManager (com.newrelic.agent.service.ServiceManager)2 ConfigService (com.newrelic.agent.config.ConfigService)1 CoreService (com.newrelic.agent.core.CoreService)1 CoreServiceImpl (com.newrelic.agent.core.CoreServiceImpl)1 Logger (com.newrelic.api.agent.Logger)1