Search in sources :

Example 11 with MockDispatcher

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

the class EventTestHelper method generateTransactionData.

private static TransactionData generateTransactionData(Map<String, Object> userParams, String appName, long durationInMillis) {
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(true);
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(durationInMillis);
    long baseTime = System.nanoTime();
    rootTracer.setStartTime(baseTime);
    rootTracer.setEndTime(baseTime + TimeUnit.NANOSECONDS.convert(durationInMillis, TimeUnit.MILLISECONDS));
    // create a new string instance to verify that the transaction name cache is working
    String frontendMetricName = "Frontend/metricname" + System.currentTimeMillis();
    final AgentConfig agentConfig = ServiceFactory.getConfigService().getAgentConfig(appName);
    return new TransactionDataTestBuilder(appName, agentConfig, rootTracer).setDispatcher(rootTracer).setFrontendMetricName(frontendMetricName).setUserParams(userParams).setIncludeDistributedTracePayload(true).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 12 with MockDispatcher

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

the class ErrorServiceTest method createTransactionData.

private TransactionData createTransactionData(boolean isWebTransaction, int responseStatus, Throwable throwable, boolean expectedError, Map<String, String> requestParams, Map<String, Object> userParams, Map<String, Object> agentParams, Map<String, Object> errorParams, Map<String, Object> intrinsics) {
    AgentConfig iAgentConfig = mock(AgentConfig.class);
    ErrorCollectorConfig errorCollectorConfig = mock(ErrorCollectorConfig.class);
    when(iAgentConfig.getErrorCollectorConfig()).thenReturn(errorCollectorConfig);
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(isWebTransaction);
    Tracer rootTracer = new MockDispatcherTracer();
    String frontendMetricName = isWebTransaction ? "WebTransaction/Uri/dude" : "OtherTransaction/Custom/dude";
    return new TransactionDataTestBuilder(APP_NAME, iAgentConfig, rootTracer).setDispatcher(dispatcher).setFrontendMetricName(frontendMetricName).setThrowable(throwable).setExpectedError(expectedError).setRequestUri("/dude").setResponseStatus(responseStatus).setStatusMessage("").setRequestParams(requestParams).setAgentParams(agentParams).setUserParams(userParams).setErrorParams(errorParams).setIntrinsics(intrinsics).build();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) Tracer(com.newrelic.agent.tracers.Tracer) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 13 with MockDispatcher

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

the class TransactionTraceTest method createTransactionData.

public TransactionData createTransactionData(final TimeoutCause cause) {
    return new TransactionData(Mockito.mock(Transaction.class), 2) {

        @Override
        public Map<String, Object> getIntrinsicAttributes() {
            HashMap<String, Object> atts = new HashMap<>();
            atts.put(AttributeNames.TIMEOUT_CAUSE, cause.cause);
            return atts;
        }

        @Override
        public PriorityTransactionName getPriorityTransactionName() {
            return PriorityTransactionName.NONE;
        }

        @Override
        public Dispatcher getDispatcher() {
            return new MockDispatcher();
        }

        @Override
        public Tracer getRootTracer() {
            Tracer mock = Mockito.mock(Tracer.class);
            Mockito.when(mock.getClassMethodSignature()).thenReturn(new ClassMethodSignature("class", "method", "methodDesc"));
            return mock;
        }

        @Override
        public TransactionTimer getTransactionTime() {
            return new TransactionTimer(0);
        }

        @Override
        public String getApplicationName() {
            return "appName";
        }

        @Override
        public TimeoutCause getTimeoutCause() {
            return cause;
        }
    };
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) MethodExitTracer(com.newrelic.agent.tracers.MethodExitTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) JSONObject(org.json.simple.JSONObject) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionData(com.newrelic.agent.TransactionData) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer)

Example 14 with MockDispatcher

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

the class SlowQueryAggregatorImplTest method createTransactionData.

private TransactionData createTransactionData(String appName, String transactionName, long durationInMillis) {
    AgentConfig agentConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(true);
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(durationInMillis);
    rootTracer.setStartTime(System.nanoTime());
    rootTracer.setEndTime(rootTracer.getStartTime() + TimeUnit.NANOSECONDS.convert(durationInMillis, TimeUnit.MILLISECONDS));
    TransactionTracerConfig ttconf = Mockito.mock(TransactionTracerConfig.class);
    when(ttconf.isEnabled()).thenReturn(true);
    when(ttconf.getInsertSqlMaxLength()).thenReturn(10 * 1000);
    Transaction tx = mock(Transaction.class);
    TransactionActivity txa = mock(TransactionActivity.class);
    when(txa.getTransaction()).thenReturn(tx);
    when(tx.getTransactionActivity()).thenReturn(txa);
    when(tx.getTransactionTracerConfig()).thenReturn(ttconf);
    List<SlowQueryInfo> tracers = new ArrayList<>(1);
    String sql = "select * from TABLE" + Integer.toString(count.incrementAndGet()) + " where Time = 'nigh'";
    String obfuscatedSql = sqlObfuscator.obfuscateSql(sql);
    SqlTracer sqlTracer = new NoOpTrackingSqlTracer(tx, sql);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(null, sqlTracer, sql, obfuscatedSql, agentConfig.getSqlTraceConfig());
    tracers.add(slowQueryInfo);
    SlowQueryListener slowQueryListener = Mockito.mock(SlowQueryListener.class);
    org.mockito.Mockito.when(slowQueryListener.getSlowQueries()).thenReturn(tracers);
    return new TransactionDataTestBuilder(appName, agentConfig, rootTracer).setTx(tx).setRequestUri(transactionName).setFrontendMetricName(transactionName).setSlowQueryListener(slowQueryListener).build();
}
Also used : MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) ArrayList(java.util.ArrayList) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionActivity(com.newrelic.agent.TransactionActivity) AgentConfig(com.newrelic.agent.config.AgentConfig) Transaction(com.newrelic.agent.Transaction) NoOpTrackingSqlTracer(com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer) NoOpTrackingSqlTracer(com.newrelic.agent.instrumentation.sql.NoOpTrackingSqlTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 15 with MockDispatcher

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

the class SlowQueryInfoTest method testStandardSqlId.

@Test
public void testStandardSqlId() {
    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 hashedObfuscatedQuery = (long) obfuscatedQuery.hashCode();
    assertEquals(hashedObfuscatedQuery, 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)

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