use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doForceRestartException.
private void doForceRestartException() throws Exception {
MockDataSenderFactory dataSenderFactory = new MockDataSenderFactory();
DataSenderFactory.setDataSenderFactory(dataSenderFactory);
Transaction.clearTransaction();
List<String> appNames = singletonList("MyApplication");
RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "test", "()V");
Tracer rootTracer = new BasicRequestRootTracer(Transaction.getTransaction(), sig, this, null, null, new SimpleMetricNameFormat("/test"));
AgentConfig iAgentConfig = mock(AgentConfig.class);
TransactionData data = new TransactionDataTestBuilder("unittest", iAgentConfig, rootTracer).setRequestUri("/unittest").build();
List<TransactionTrace> traces = singletonList(TransactionTrace.getTransactionTrace(data));
MockDataSender dataSender = dataSenderFactory.getLastDataSender();
dataSender.setConnected(false);
dataSender.setException(new ForceRestartException(""));
CountDownLatch latch = new CountDownLatch(1);
dataSender.setLatch(latch);
try {
svc.sendTransactionTraceData(traces);
} finally {
latch.await(10, TimeUnit.SECONDS);
assertTrue(dataSender.isConnected());
}
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doTestTransactionTraces.
private void doTestTransactionTraces() throws Exception {
MockDataSenderFactory dataSenderFactory = new MockDataSenderFactory();
DataSenderFactory.setDataSenderFactory(dataSenderFactory);
Transaction.clearTransaction();
List<String> appNames = singletonList("MyApplication");
RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
svc.launch();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "test", "()V");
Tracer rootTracer = new BasicRequestRootTracer(Transaction.getTransaction(), sig, this, null, null, new SimpleMetricNameFormat("/test"));
AgentConfig iAgentConfig = mock(AgentConfig.class);
TransactionData data = new TransactionDataTestBuilder("unittest", iAgentConfig, rootTracer).setRequestUri("/unittest").build();
List<TransactionTrace> traces = singletonList(TransactionTrace.getTransactionTrace(data));
try {
System.err.println("Transaction trace. JSON: " + DataSenderWriter.toJSONString(traces));
svc.sendTransactionTraceData(traces);
} catch (Exception e) {
System.err.println("Error sending transaction trace. JSON: " + DataSenderWriter.toJSONString(traces));
throw e;
}
assertEquals(traces, dataSenderFactory.getLastDataSender().getTraces());
svc.shutdown();
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class TransactionAsyncUtility method createOtherTracer.
// Create a Tracer for tests that require one.
public static OtherRootTracer createOtherTracer(String methodName) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("MyClass", methodName, "()V");
OtherRootTracer brrt = new OtherRootTracer(tx, sig, new Object(), new SimpleMetricNameFormat(methodName));
return brrt;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class TransactionAsyncUtility method createDefaultTracer.
// Create a Tracer for tests that require one.
public static DefaultTracer createDefaultTracer(String methodName) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("MyClass", methodName, "()V");
DefaultTracer brrt = new DefaultTracer(tx, sig, new Object(), new SimpleMetricNameFormat("Custom/" + methodName));
return brrt;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method startSqlTracer.
private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
DummyConnection conn = new DummyConnection();
Statement statement = conn.createStatement();
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {
@Override
public long getDuration() {
return duration;
}
@Override
public Object getSql() {
return sql;
}
};
sqlTracer.setConnectionFactory(new ConnectionFactory() {
@Override
public Connection getConnection() {
return null;
}
@Override
public DatabaseVendor getDatabaseVendor() {
return UnknownDatabaseVendor.INSTANCE;
}
});
sqlTracer.setRawSql(sql);
tx.getTransactionActivity().tracerStarted(sqlTracer);
return sqlTracer;
}
Aggregations