Search in sources :

Example 1 with Environment

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"));
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) SpanProxy(com.newrelic.agent.tracing.SpanProxy) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) TransactionData(com.newrelic.agent.TransactionData) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Before(org.junit.Before)

Example 2 with Environment

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());
}
Also used : Filter(javax.servlet.Filter) Environment(com.newrelic.agent.environment.Environment) MockServletContext(org.apache.struts.mock.MockServletContext) Test(org.junit.Test)

Example 3 with Environment

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();
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Stats(com.newrelic.agent.stats.Stats) Environment(com.newrelic.agent.environment.Environment) CountDownLatch(java.util.concurrent.CountDownLatch) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test) AgentConfigFactoryTest(com.newrelic.agent.config.AgentConfigFactoryTest)

Example 4 with Environment

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();
}
Also used : Environment(com.newrelic.agent.environment.Environment) CountDownLatch(java.util.concurrent.CountDownLatch) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test) AgentConfigFactoryTest(com.newrelic.agent.config.AgentConfigFactoryTest)

Example 5 with Environment

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();
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) Logger(com.newrelic.api.agent.Logger) AgentConfig(com.newrelic.agent.config.AgentConfig) Returns(org.mockito.internal.stubbing.answers.Returns) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) Before(org.junit.Before)

Aggregations

Environment (com.newrelic.agent.environment.Environment)10 Test (org.junit.Test)6 AgentConfigFactoryTest (com.newrelic.agent.config.AgentConfigFactoryTest)5 StatsEngine (com.newrelic.agent.stats.StatsEngine)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AgentConfig (com.newrelic.agent.config.AgentConfig)3 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)3 ConfigService (com.newrelic.agent.config.ConfigService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Before (org.junit.Before)2 Returns (org.mockito.internal.stubbing.answers.Returns)2 MockServiceManager (com.newrelic.agent.MockServiceManager)1 ThreadService (com.newrelic.agent.ThreadService)1 TransactionData (com.newrelic.agent.TransactionData)1 AgentIdentity (com.newrelic.agent.environment.AgentIdentity)1 SpanError (com.newrelic.agent.model.SpanError)1 Stats (com.newrelic.agent.stats.Stats)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 StatsService (com.newrelic.agent.stats.StatsService)1 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)1