Search in sources :

Example 1 with MockDispatcher

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

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

Example 3 with MockDispatcher

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());
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionData(com.newrelic.agent.TransactionData) ServerProp(com.newrelic.agent.config.ServerProp) Test(org.junit.Test)

Example 4 with MockDispatcher

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());
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 5 with MockDispatcher

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());
}
Also used : SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Aggregations

MockDispatcher (com.newrelic.agent.MockDispatcher)17 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)11 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)10 AgentConfig (com.newrelic.agent.config.AgentConfig)9 Transaction (com.newrelic.agent.Transaction)8 Tracer (com.newrelic.agent.tracers.Tracer)7 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)6 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)6 TransactionData (com.newrelic.agent.TransactionData)5 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)5 Test (org.junit.Test)5 SqlTraceConfig (com.newrelic.agent.config.SqlTraceConfig)4 HashMap (java.util.HashMap)4 TransactionActivity (com.newrelic.agent.TransactionActivity)2 ServerProp (com.newrelic.agent.config.ServerProp)2 TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)2 JSONObject (org.json.simple.JSONObject)2 ErrorCollectorConfig (com.newrelic.agent.config.ErrorCollectorConfig)1 NoOpTrackingSqlTracer (com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer)1 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)1