Search in sources :

Example 1 with Token

use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.

the class TransactionPropagationTest method asyncPropagationSanityCheck.

@Test
public void asyncPropagationSanityCheck() throws InterruptedException {
    AtomicBoolean hadTransaction = new AtomicBoolean();
    CountDownLatch done = new CountDownLatch(1);
    inTransaction(() -> {
        Token token = createToken();
        inAnotherThread(() -> inAnnotatedWithTraceAsync(() -> {
            token.linkAndExpire();
            checkTransaction(hadTransaction);
            done.countDown();
        }));
    });
    done.await();
    assertCapturedData(hadTransaction);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Token(com.newrelic.agent.bridge.Token) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with Token

use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.

the class TransactionPropagationTest method testLambdaSubscriberOnError.

@Test(timeout = 10000L)
public void testLambdaSubscriberOnError() {
    AtomicBoolean hadTransaction = new AtomicBoolean();
    CountDownLatch done = new CountDownLatch(1);
    inTransaction(() -> {
        Token token = createToken();
        Flux.error(new RuntimeException()).subscribeOn(Schedulers.elastic()).doOnError(v -> checkTransaction(hadTransaction)).subscribe(nil(), v -> done.countDown());
        await(done);
        token.expire();
    });
    assertCapturedData(hadTransaction);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TokenLinkingSubscriber(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber) Trace(com.newrelic.api.agent.Trace) BeforeClass(org.junit.BeforeClass) Token(com.newrelic.agent.bridge.Token) Context(reactor.util.context.Context) RunWith(org.junit.runner.RunWith) Introspector(com.newrelic.agent.introspec.Introspector) Hooks(reactor.core.publisher.Hooks) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TokenLinkingSubscriber.tokenLift(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Duration(java.time.Duration) Schedulers(reactor.core.scheduler.Schedulers) InstrumentationTestConfig(com.newrelic.agent.introspec.InstrumentationTestConfig) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) InstrumentationTestRunner(com.newrelic.agent.introspec.InstrumentationTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Token(com.newrelic.agent.bridge.Token) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with Token

use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.

the class TransactionPropagationTest method testMonoNestedInFlatMap.

@Test
public void testMonoNestedInFlatMap() {
    AtomicBoolean hadTransaction = new AtomicBoolean();
    inTransaction(() -> {
        Token token = createToken();
        Mono.just(A_VALUE).subscribeOn(Schedulers.elastic()).flatMap(v -> Mono.just(A_VALUE).subscribeOn(Schedulers.elastic()).doOnSuccess(v2 -> checkTransaction(hadTransaction))).subscriberContext(with(token)).block();
        token.expire();
    });
    assertCapturedData(hadTransaction);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TokenLinkingSubscriber(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber) Trace(com.newrelic.api.agent.Trace) BeforeClass(org.junit.BeforeClass) Token(com.newrelic.agent.bridge.Token) Context(reactor.util.context.Context) RunWith(org.junit.runner.RunWith) Introspector(com.newrelic.agent.introspec.Introspector) Hooks(reactor.core.publisher.Hooks) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TokenLinkingSubscriber.tokenLift(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Duration(java.time.Duration) Schedulers(reactor.core.scheduler.Schedulers) InstrumentationTestConfig(com.newrelic.agent.introspec.InstrumentationTestConfig) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) InstrumentationTestRunner(com.newrelic.agent.introspec.InstrumentationTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Token(com.newrelic.agent.bridge.Token) Test(org.junit.Test)

Example 4 with Token

use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.

the class TransactionPropagationTest method testLambdaMonoSubscriberOnSuccess.

@Test(timeout = 10000L)
public void testLambdaMonoSubscriberOnSuccess() {
    AtomicBoolean hadTransaction = new AtomicBoolean();
    CountDownLatch done = new CountDownLatch(1);
    inTransaction(() -> {
        Token token = createToken();
        Mono.empty().subscribeOn(Schedulers.elastic()).doOnSuccess(v -> checkTransaction(hadTransaction)).subscribe(nil(), nil(), done::countDown);
        await(done);
        token.expire();
    });
    assertCapturedData(hadTransaction);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TokenLinkingSubscriber(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber) Trace(com.newrelic.api.agent.Trace) BeforeClass(org.junit.BeforeClass) Token(com.newrelic.agent.bridge.Token) Context(reactor.util.context.Context) RunWith(org.junit.runner.RunWith) Introspector(com.newrelic.agent.introspec.Introspector) Hooks(reactor.core.publisher.Hooks) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TokenLinkingSubscriber.tokenLift(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Duration(java.time.Duration) Schedulers(reactor.core.scheduler.Schedulers) InstrumentationTestConfig(com.newrelic.agent.introspec.InstrumentationTestConfig) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) InstrumentationTestRunner(com.newrelic.agent.introspec.InstrumentationTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Token(com.newrelic.agent.bridge.Token) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with Token

use of com.newrelic.agent.bridge.Token in project newrelic-java-agent by newrelic.

the class TransactionPropagationTest method testMonoRetryBackoffOnSuccess.

@Test
public void testMonoRetryBackoffOnSuccess() {
    AtomicBoolean hadTransaction = new AtomicBoolean();
    inTransaction(() -> {
        Token token = createToken();
        AtomicBoolean firstCall = new AtomicBoolean(true);
        Mono.create(monoSink -> inAnotherThread(() -> {
            if (firstCall.getAndSet(false))
                monoSink.error(new RuntimeException("failing the first call"));
            else
                monoSink.success(A_VALUE);
        })).doOnSuccess(v -> checkTransaction(hadTransaction)).retryBackoff(2, Duration.ZERO).subscriberContext(with(token)).block();
        token.expire();
    });
    assertCapturedData(hadTransaction);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TokenLinkingSubscriber(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber) Trace(com.newrelic.api.agent.Trace) BeforeClass(org.junit.BeforeClass) Token(com.newrelic.agent.bridge.Token) Context(reactor.util.context.Context) RunWith(org.junit.runner.RunWith) Introspector(com.newrelic.agent.introspec.Introspector) Hooks(reactor.core.publisher.Hooks) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TokenLinkingSubscriber.tokenLift(com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Duration(java.time.Duration) Schedulers(reactor.core.scheduler.Schedulers) InstrumentationTestConfig(com.newrelic.agent.introspec.InstrumentationTestConfig) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) InstrumentationTestRunner(com.newrelic.agent.introspec.InstrumentationTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Token(com.newrelic.agent.bridge.Token) Test(org.junit.Test)

Aggregations

Token (com.newrelic.agent.bridge.Token)20 Test (org.junit.Test)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 AgentBridge (com.newrelic.agent.bridge.AgentBridge)8 Trace (com.newrelic.api.agent.Trace)7 InstrumentationTestConfig (com.newrelic.agent.introspec.InstrumentationTestConfig)6 InstrumentationTestRunner (com.newrelic.agent.introspec.InstrumentationTestRunner)6 Introspector (com.newrelic.agent.introspec.Introspector)6 TokenLinkingSubscriber (com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber)6 TokenLinkingSubscriber.tokenLift (com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift)6 Duration (java.time.Duration)6 Consumer (java.util.function.Consumer)6 CoreMatchers.is (org.hamcrest.CoreMatchers.is)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 Matchers (org.hamcrest.Matchers)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 BeforeClass (org.junit.BeforeClass)6 RunWith (org.junit.runner.RunWith)6 Flux (reactor.core.publisher.Flux)6