use of com.newrelic.agent.MockDispatcher 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.MockDispatcher 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();
}
use of com.newrelic.agent.MockDispatcher in project newrelic-java-agent by newrelic.
the class SlowQueryInfoTest method testLongerSqlId.
@Test
public void testLongerSqlId() {
setupServiceManager(new HashMap<String, Object>());
Transaction transaction = Transaction.getTransaction();
HashMap<String, Object> sqlMap = new HashMap<>();
ServerProp serverProp = ServerProp.createPropObject(!SqlTraceConfigImpl.DEFAULT_USE_LONGER_SQL_ID);
sqlMap.put(SqlTraceConfigImpl.USE_LONGER_SQL_ID, serverProp);
SqlTraceConfig sqlTraceConfig = SqlTraceConfigImpl.createSqlTraceConfig(sqlMap);
MockDispatcher dispatcher = new MockDispatcher();
dispatcher.setUri("http://jvm.agent.uri");
transaction.setDispatcher(dispatcher);
String obfuscatedQuery = "select ? from ?";
TransactionData data = new TransactionData(transaction, 100);
Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", obfuscatedQuery, sqlTraceConfig);
SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
long hashedQuery = (long) obfuscatedQuery.hashCode();
long longerHash = SlowQueryInfo.createLongerHashCode(hashedQuery);
assertEquals(longerHash, sqlTrace.getId());
}
use of com.newrelic.agent.MockDispatcher in project newrelic-java-agent by newrelic.
the class SlowQueryInfoTest method testEmptyTxnUrlRequestUriDisabled.
@Test
public void testEmptyTxnUrlRequestUriDisabled() {
Map<String, Object> attributeMap = new HashMap<>();
attributeMap.put("exclude", "request.*");
Map<String, Object> settings = new HashMap<>();
settings.put("attributes", attributeMap);
setupServiceManager(settings);
SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
Transaction transaction = Transaction.getTransaction();
MockDispatcher dispatcher = new MockDispatcher();
dispatcher.setUri("http://jvm.agent.uri");
transaction.setDispatcher(dispatcher);
TransactionData data = new TransactionData(transaction, 100);
Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
assertEquals(null, sqlTrace.getUri());
}
use of com.newrelic.agent.MockDispatcher in project newrelic-java-agent by newrelic.
the class SlowQueryInfoTest method testTxnUrl.
@Test
public void testTxnUrl() {
setupServiceManager(new HashMap<String, Object>());
Transaction transaction = Transaction.getTransaction();
SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
MockDispatcher dispatcher = new MockDispatcher();
dispatcher.setUri("http://jvm.agent.uri");
transaction.setDispatcher(dispatcher);
TransactionData data = new TransactionData(transaction, 100);
Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
assertEquals("http://jvm.agent.uri", sqlTrace.getUri());
}
Aggregations