Search in sources :

Example 1 with MockDispatcherTracer

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

the class TransactionEventsServiceTest method generateSyntheticTransactionData.

private TransactionData generateSyntheticTransactionData() {
    long durationInMillis = 1000 + System.nanoTime() % 1000;
    long nt = System.nanoTime();
    MockDispatcher dispatcher = new MockDispatcher();
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(durationInMillis);
    rootTracer.setStartTime(System.nanoTime());
    rootTracer.setEndTime(System.nanoTime() + TimeUnit.NANOSECONDS.convert(durationInMillis, TimeUnit.MILLISECONDS));
    AgentConfig agentConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
    return new TransactionDataTestBuilder(APP_NAME, agentConfig, rootTracer).setDispatcher(dispatcher).setRequestUri("/mock/synthetic/transaction").setFrontendMetricName("/mock/synthetic/transaction").setSynJobId("Job" + nt).setSynMonitorId("Monitor" + nt).setSynResourceId("Resource" + nt).build();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 2 with MockDispatcherTracer

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

the class TransactionEventsServiceTest method testSendOther.

@Test
public void testSendOther() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    TransactionActivityInitiator rootTracer = new OtherRootTracer(Transaction.getTransaction(), null, new Object(), null);
    TransactionData transactionData = new TransactionDataTestBuilder(APP_NAME, iAgentConfig, new MockDispatcherTracer()).setDispatcher(rootTracer.createDispatcher()).setFrontendMetricName("Frontend/metricname").build();
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
    // populate the eventData map
    service.harvestEvents(APP_NAME);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    assertEquals(1, currentEventData.size());
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) TransactionStats(com.newrelic.agent.stats.TransactionStats) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 3 with MockDispatcherTracer

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

the class W3CTraceStateSupportTest method testParseHeadersNoPriorityOrSampledTriggersResamplingDecision.

@Test
public void testParseHeadersNoPriorityOrSampledTriggersResamplingDecision() {
    createDistributedTraceService("accountId", "190", "appID", 0, 2);
    Transaction transaction = Transaction.getTransaction(true);
    transaction.startTransactionIfBeginning(new MockDispatcherTracer(transaction));
    DistributedTracePayloadImpl inboundPayload = (DistributedTracePayloadImpl) W3CTracePayload.parseHeaders(transaction, Collections.singletonList("02-12341234123412341234123412341234-4321432143214321-01"), Arrays.asList("190@nr=0-0-709288-8599547-f85f42fd82a4cf1d-164d3b4b0d09cb05164d3b4b0d09cb05---1563574856827")).getPayload();
    assertNotNull(inboundPayload);
    transaction.acceptDistributedTracePayload(inboundPayload);
    transaction.createDistributedTracePayload("meatball!");
    String[] outboundPayload = new W3CTraceStateHeader(true, true).create(transaction.getSpanProxy()).split("-");
    // sampled
    assertFalse(outboundPayload[6].isEmpty());
    // priority
    assertFalse(outboundPayload[7].isEmpty());
}
Also used : Transaction(com.newrelic.agent.Transaction) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) Test(org.junit.Test)

Example 4 with MockDispatcherTracer

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

the class W3CTraceStateSupportTest method testParseHeadersDup.

@Test
public void testParseHeadersDup() {
    createDistributedTraceService("accountId", "190", "appID", 0, 2);
    Transaction transaction = Transaction.getTransaction(true);
    transaction.startTransactionIfBeginning(new MockDispatcherTracer(transaction));
    DistributedTracePayloadImpl inboundPayload = (DistributedTracePayloadImpl) W3CTracePayload.parseHeaders(transaction, Collections.singletonList("02-12341234123412341234123412341234-4321432143214321-01"), Arrays.asList("190@nr=0-0-709288-8599547-f85f42fd82a4cf1d-164d3b4b0d09cb05164d3b4b0d09cb05-1-0.789-1563574856827", "congo@=0-qzx932-abc123", "congo@=0-very-qzx932-abc123")).getPayload();
    assertNotNull(inboundPayload);
    transaction.acceptDistributedTracePayload(inboundPayload);
    String newSpanId = TransactionGuidFactory.generate16CharGuid();
    transaction.createDistributedTracePayload(newSpanId);
    String outboundPayload = new W3CTraceStateHeader(true, true).create(transaction.getSpanProxy());
    // timestamp is generated
    assertTrue(outboundPayload.startsWith("190@nr=0-0-accountId-appID-" + newSpanId + "-" + transaction.getGuid() + "-0-0.789-"));
}
Also used : Transaction(com.newrelic.agent.Transaction) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) Test(org.junit.Test)

Example 5 with MockDispatcherTracer

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

the class BoundedConcurrentCacheTest method before.

@Before
public void before() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    createServiceManager(configMap);
    agentConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(true);
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(3000);
    rootTracer.setStartTime(System.nanoTime());
    rootTracer.setEndTime(rootTracer.getStartTime() + TimeUnit.NANOSECONDS.convert(3000, TimeUnit.MILLISECONDS));
    TransactionTracerConfig ttconf = Mockito.mock(TransactionTracerConfig.class);
    when(ttconf.isEnabled()).thenReturn(true);
    when(ttconf.getInsertSqlMaxLength()).thenReturn(10 * 1000);
    tx = mock(Transaction.class);
    TransactionActivity txa = mock(TransactionActivity.class);
    when(txa.getTransaction()).thenReturn(tx);
    when(tx.getTransactionActivity()).thenReturn(txa);
    when(tx.getTransactionTracerConfig()).thenReturn(ttconf);
    cache = new BoundedConcurrentCache<>(MAX_SIZE);
    sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
}
Also used : Transaction(com.newrelic.agent.Transaction) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionActivity(com.newrelic.agent.TransactionActivity) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Before(org.junit.Before)

Aggregations

MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)14 MockDispatcher (com.newrelic.agent.MockDispatcher)11 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)11 AgentConfig (com.newrelic.agent.config.AgentConfig)9 Transaction (com.newrelic.agent.Transaction)4 Test (org.junit.Test)3 TransactionActivity (com.newrelic.agent.TransactionActivity)2 TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)2 TransactionData (com.newrelic.agent.TransactionData)1 ErrorCollectorConfig (com.newrelic.agent.config.ErrorCollectorConfig)1 NoOpTrackingSqlTracer (com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer)1 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 TransactionActivityInitiator (com.newrelic.agent.tracers.TransactionActivityInitiator)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1