use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method setup.
@Before
public void setup() {
transactionAgentAttributes = new HashMap<>();
transactionUserAttributes = new HashMap<>();
tracerAgentAttributes = new HashMap<>();
tracerUserAttributes = new HashMap<>();
expectedAgentAttributes = new HashMap<>();
expectedUserAttributes = new HashMap<>();
expectedAgentAttributes.put("error.class", "0");
expectedAgentAttributes.put("port", 9191);
expectedIntrinsicAttributes = new HashMap<>();
expectedIntrinsicAttributes.put("traceId", traceId);
expectedIntrinsicAttributes.put("duration", (float) duration / TimeConversion.NANOSECONDS_PER_SECOND);
expectedIntrinsicAttributes.put("type", "Span");
expectedIntrinsicAttributes.put("category", "generic");
expectedIntrinsicAttributes.put("sampled", sampled);
expectedIntrinsicAttributes.put("nr.entryPoint", true);
expectedIntrinsicAttributes.put("timestamp", timestamp);
expectedIntrinsicAttributes.put("priority", priority);
expectedIntrinsicAttributes.put("transaction.name", txnName.getName());
tracer = mock(Tracer.class);
txnData = mock(TransactionData.class);
spanErrorBuilder = mock(SpanErrorBuilder.class);
spanError = mock(SpanError.class);
spanProxy = mock(SpanProxy.class);
throwable = mock(TransactionThrowable.class);
environmentService = mock(EnvironmentService.class);
environment = mock(Environment.class);
transactionDataToDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
txnStats = mock(TransactionStats.class, RETURNS_DEEP_STUBS);
errorBuilderMap = new HashMap<>();
errorBuilderMap.put(appName, spanErrorBuilder);
when(tracer.getDuration()).thenReturn(duration);
when(tracer.getStartTimeInMillis()).thenReturn(timestamp);
when(tracer.getAgentAttributes()).thenReturn(tracerAgentAttributes);
when(tracer.getCustomAttributes()).thenReturn(tracerUserAttributes);
when(spanErrorBuilder.buildSpanError(tracer, isRoot, responseStatus, statusMessage, throwable)).thenReturn(spanError);
when(spanErrorBuilder.areErrorsEnabled()).thenReturn(true);
when(txnData.getApplicationName()).thenReturn(appName);
when(txnData.getResponseStatus()).thenReturn(responseStatus);
when(txnData.getStatusMessage()).thenReturn(statusMessage);
when(txnData.getThrowable()).thenReturn(throwable);
when(txnData.getPriority()).thenReturn(priority);
when(txnData.sampled()).thenReturn(sampled);
when(txnData.getSpanProxy()).thenReturn(spanProxy);
when(txnData.getPriorityTransactionName()).thenReturn(txnName);
when(txnData.getUserAttributes()).thenReturn(transactionUserAttributes);
when(spanProxy.getOrCreateTraceId()).thenReturn(traceId);
when(environmentService.getEnvironment()).thenReturn(environment);
when(environment.getAgentIdentity()).thenReturn(new AgentIdentity("dispatcher", "1.2.3", 9191, "myInstance"));
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class ServletFilterTest method testInit.
@Test
public void testInit() throws ServletException {
MockServletContext context = new MockServletContext() {
@Override
public String getServerInfo() {
return "Awesome Dude/3.13";
}
};
FilterConfigImpl config = new FilterConfigImpl(context);
Filter filter = new MyFilter();
filter.init(config);
Environment env = ServiceFactory.getEnvironmentService().getEnvironment();
Assert.assertEquals("Awesome Dude", env.getAgentIdentity().getDispatcher());
Assert.assertEquals("3.13", env.getAgentIdentity().getDispatcherVersion());
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method metricLimit.
@Test
public void metricLimit() throws Exception {
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
environment.setServerPort(null);
final CountDownLatch latch = new CountDownLatch(2);
MyRPMService rpmService = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
latch.countDown();
if (latch.getCount() == 1) {
Assert.assertEquals(MetricIdRegistry.METRIC_LIMIT + 100, statsEngine.getSize());
} else {
Assert.assertEquals(1, statsEngine.getSize());
}
}
};
TestHarvestService harvestService = new TestHarvestService();
harvestService.setReportingPeriod(500L);
harvestService.start();
StatsEngineImpl statsEngine = new StatsEngineImpl();
for (int i = 0; i < MetricIdRegistry.METRIC_LIMIT + 100; i++) {
Stats stats = statsEngine.getStats("Test" + String.valueOf(i));
stats.recordDataPoint(100f);
}
ServiceFactory.getStatsService().doStatsWork(new MergeStatsWork("test", statsEngine), "statsWorkTest");
harvestService.startHarvest(rpmService);
Assert.assertTrue(latch.await(5L, TimeUnit.SECONDS));
harvestService.stop();
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method reportingPeriod.
@Test
public void reportingPeriod() throws Exception {
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
environment.setServerPort(null);
final CountDownLatch latch = new CountDownLatch(2);
MyRPMService rpmService = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
latch.countDown();
}
};
TestHarvestService harvestService = new TestHarvestService();
harvestService.setReportingPeriod(500L);
harvestService.start();
harvestService.startHarvest(rpmService);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
harvestService.stop();
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method setup.
@Before
public void setup() throws Exception {
AgentHelper.initializeConfig();
ConfigService configService = ConfigServiceFactory.createConfigService(mock(Logger.class), false);
MockServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
Environment env = new Environment(config, "c:\\test\\log");
EnvironmentService envService = Mockito.mock(EnvironmentService.class, new Returns(env));
Mockito.doNothing().when(envService).stop();
serviceManager.setEnvironmentService(envService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
statsService.start();
}
Aggregations