use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TokenTimeoutTest method testTxnAttrTokenTimeout.
@Test
public void testTxnAttrTokenTimeout() throws InterruptedException {
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
tx.getTransactionActivity().tracerStarted(rootTracer);
// Name the transaction so we can identify it in the listener below and create an event
tx.setTransactionName(TransactionNamePriority.CUSTOM_HIGH, true, "TokenTimeout", "timeout");
final List<TransactionEvent> events = new ArrayList<>();
final CountDownLatch latch = new CountDownLatch(1);
ServiceFactory.getServiceManager().getTransactionService().addTransactionListener(new TransactionListener() {
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
if (transactionData.getPriorityTransactionName().getName().equals("WebTransaction/TokenTimeout/timeout")) {
events.add(ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, transactionData.getBlameOrRootMetricName()));
latch.countDown();
}
}
});
tx.getTransactionActivity().tracerStarted(rootTracer);
// Let this timeout the transaction
Token token = tx.getToken();
rootTracer.finish(Opcodes.RETURN, 0);
assertFalse(tx.isFinished());
// Don't start the thread. The timeout is configured to 0 seconds.
// Allow it to expire and then run the code that implements it.
busyWait(1000);
latch.await();
assertTrue(tx.isFinished());
assertFalse(events.isEmpty());
assertEquals("WebTransaction/TokenTimeout/timeout", events.get(0).getName());
assertEquals(TimeoutCause.TOKEN, events.get(0).getTimeoutCause());
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TransactionPropagationTest method testEmptyMonoOnSuccess.
@Test
public void testEmptyMonoOnSuccess() {
AtomicBoolean hadTransaction = new AtomicBoolean();
inTransaction(() -> {
Token token = createToken();
Mono.empty().subscribeOn(Schedulers.elastic()).doOnSuccess(v -> checkTransaction(hadTransaction)).subscriberContext(with(token)).block();
token.expire();
});
assertCapturedData(hadTransaction);
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TransactionPropagationTest method testMonoOnSuccess.
@Test
public void testMonoOnSuccess() {
AtomicBoolean hadTransaction = new AtomicBoolean();
inTransaction(() -> {
Token token = createToken();
Mono.just(A_VALUE).subscribeOn(Schedulers.elastic()).doOnSuccess(v -> checkTransaction(hadTransaction)).subscriberContext(with(token)).block();
token.expire();
});
assertCapturedData(hadTransaction);
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TransactionPropagationTest method testLambdaMonoSubscriberOnError.
@Test(timeout = 10000L)
public void testLambdaMonoSubscriberOnError() {
AtomicBoolean hadTransaction = new AtomicBoolean();
CountDownLatch done = new CountDownLatch(1);
inTransaction(() -> {
Token token = createToken();
Mono.error(new RuntimeException()).subscribeOn(Schedulers.elastic()).doOnError(v -> checkTransaction(hadTransaction)).subscribe(nil(), v -> done.countDown());
await(done);
token.expire();
});
assertCapturedData(hadTransaction);
}
use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.
the class TransactionPropagationTest method testLambdaSubscriberOnComplete.
@Test(timeout = 10000L)
public void testLambdaSubscriberOnComplete() {
AtomicBoolean hadTransaction = new AtomicBoolean();
CountDownLatch done = new CountDownLatch(1);
inTransaction(() -> {
Token token = createToken();
Flux.empty().subscribeOn(Schedulers.elastic()).doOnComplete(() -> checkTransaction(hadTransaction)).subscribe(nil(), nil(), done::countDown);
await(done);
token.expire();
});
assertCapturedData(hadTransaction);
}
Aggregations