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