Search in sources :

Example 61 with MockServiceManager

use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.

the class DataSenderImplTest method before.

@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    final MockServiceManager serviceManager = new MockServiceManager();
    serviceManager.setStatsService(mockStatsService);
    serviceManager.setAttributesService(mockAttributesService);
    when(mockAttributesService.filterAttributes(anyString(), ArgumentMatchers.<String, Object>anyMap())).thenAnswer(new ReturnsArgumentAt(1));
}
Also used : MockServiceManager(com.newrelic.agent.MockServiceManager) ReturnsArgumentAt(org.mockito.internal.stubbing.answers.ReturnsArgumentAt) Before(org.junit.Before)

Example 62 with MockServiceManager

use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.

the class DockerDataTest method testDockerError.

@Test
public void testDockerError() throws Exception {
    MockCoreService.getMockAgentAndBootstrapTheServiceManager();
    MockServiceManager mockServiceManager = new MockServiceManager();
    StatsService spy = Mockito.spy(new StatsServiceImpl());
    mockServiceManager.setStatsService(spy);
    ServiceFactory.setServiceManager(mockServiceManager);
    // Invalid docker id. Missing characters.
    String invalidDockerId = "47cbd16b77c50cbf71401c069cd2189f0e659af17d5a2daca3bddf59d8a870";
    StringReader reader = new StringReader("2:cpu:/docker/" + invalidDockerId);
    Assert.assertNull(dockerData.readFile(reader));
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 63 with MockServiceManager

use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.

the class DockerDataTest method testDockerGCPError.

@Test
public void testDockerGCPError() throws Exception {
    MockCoreService.getMockAgentAndBootstrapTheServiceManager();
    MockServiceManager mockServiceManager = new MockServiceManager();
    StatsService spy = Mockito.spy(new StatsServiceImpl());
    mockServiceManager.setStatsService(spy);
    ServiceFactory.setServiceManager(mockServiceManager);
    // Invalid docker id. Missing characters.
    String invalidDockerId = "47cbd16b77c50cbf71401c069cd2189f0e659af17d5a2daca3bddf59d8a870";
    StringReader reader = new StringReader("2:cpu:/" + invalidDockerId);
    Assert.assertNull(dockerData.readFile(reader));
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 64 with MockServiceManager

use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.

the class StackTracesTest method testToStringListRemoveParent2.

@Test
public void testToStringListRemoveParent2() {
    // need configuration service set
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    Map<String, Object> configMap = new HashMap<>();
    AgentConfig config = AgentConfigImpl.createAgentConfig(configMap);
    ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
    serviceManager.setConfigService(configService);
    // get stack traces
    StackTraceElement[] parentTraceArray = Thread.currentThread().getStackTrace();
    List<StackTraceElement> parentTrace = changeComNewrelic(parentTraceArray);
    StackTraceElement[] childTraceArray = anotherMethod1();
    List<StackTraceElement> childTrace = changeComNewrelic(childTraceArray);
    List<StackTraceElement> childScrubbed = StackTraces.scrubAndTruncate(childTrace);
    List<String> trimmed = StackTraces.toStringListRemoveParent(childScrubbed, parentTrace);
    Assert.assertEquals(3, trimmed.size());
    Assert.assertTrue("0 failed " + trimmed.get(0), trimmed.get(0).startsWith("hello.howdy.util.StackTracesTest.anotherMethod3("));
    Assert.assertTrue("1 failed" + trimmed.get(1), trimmed.get(1).startsWith("hello.howdy.util.StackTracesTest.anotherMethod2("));
    Assert.assertTrue("2 failed" + trimmed.get(2), trimmed.get(2).startsWith("hello.howdy.util.StackTracesTest.anotherMethod1("));
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 65 with MockServiceManager

use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.

the class StackTracesTest method testToStringListRemoveParent1.

@Test
public void testToStringListRemoveParent1() {
    // need configuration service set
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    Map<String, Object> configMap = new HashMap<>();
    AgentConfig config = AgentConfigImpl.createAgentConfig(configMap);
    ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
    serviceManager.setConfigService(configService);
    // get stack traces
    List<StackTraceElement> parentTrace = generateStack(5, 15);
    List<StackTraceElement> childTrace = generateStack(0, 10);
    List<String> trimmed = StackTraces.toStringListRemoveParent(childTrace, parentTrace);
    Assert.assertEquals(5, trimmed.size());
    for (int i = 0; i < 5; i++) {
        Assert.assertEquals("Test.method(file:" + i + ")", trimmed.get(i));
    }
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Aggregations

MockServiceManager (com.newrelic.agent.MockServiceManager)127 ConfigService (com.newrelic.agent.config.ConfigService)61 Test (org.junit.Test)49 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)48 HashMap (java.util.HashMap)44 TransactionService (com.newrelic.agent.TransactionService)42 MockRPMService (com.newrelic.agent.MockRPMService)37 ThreadService (com.newrelic.agent.ThreadService)34 AgentConfig (com.newrelic.agent.config.AgentConfig)34 AttributesService (com.newrelic.agent.attributes.AttributesService)28 HarvestService (com.newrelic.agent.HarvestService)27 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)27 MockHarvestService (com.newrelic.agent.MockHarvestService)26 MockCoreService (com.newrelic.agent.MockCoreService)21 StatsService (com.newrelic.agent.stats.StatsService)21 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)21 Before (org.junit.Before)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)16 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)16 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)15