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