Search in sources :

Example 21 with Token

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

the class LambdaMonoSubscriber_Instrumentation method onError.

public final void onError(Throwable t) {
    Token token = this.currentContext().getOrDefault("newrelic-token", null);
    if (token != null) {
        token.expire();
        this.nrContext = null;
    }
    Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token)

Example 22 with Token

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

the class LambdaSubscriber_Instrumentation method onComplete.

public final void onComplete() {
    Token token = this.currentContext().getOrDefault("newrelic-token", null);
    if (token != null) {
        token.expire();
        this.nrContext = null;
    }
    Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token)

Example 23 with Token

use of com.newrelic.api.agent.Token in project ab2d by CMSgov.

the class ContractProcessorImpl method queuePatientClaimsRequest.

/**
 * Create a {@link PatientClaimsRequest} and queue the request into a round robin queue used by the eob thread pool.
 * <p>
 * The queue maintains multiple distinct queues, one for each job running, and offers guarantees that jobs
 * are served equally.
 * <p>
 * On using new-relic tokens with async calls
 * See https://docs.newrelic.com/docs/agents/java-agent/async-instrumentation/java-agent-api-asynchronous-applications
 *
 * @param patient - the patient to process
 * @return a pointer to the queued request which will complete or be cancelled at some point.
 */
private Future<ProgressTrackerUpdate> queuePatientClaimsRequest(List<CoverageSummary> patient, ContractData contractData) {
    final Token token = NewRelic.getAgent().getTransaction().getToken();
    Job job = contractData.getJob();
    // Using a ThreadLocal to communicate contract number to RoundRobinBlockingQueue
    // could be viewed as a hack by many; but on the other hand it saves us from writing
    // tons of extra code.
    var jobUuid = job.getJobUuid();
    RoundRobinBlockingQueue.CATEGORY_HOLDER.set(jobUuid);
    try {
        var patientClaimsRequest = new PatientClaimsRequest(patient, contractData.getContract().getAttestedOn(), job.getSince(), job.getOrganization(), jobUuid, job.getContractNumber(), contractData.getContract().getContractType(), token, job.getFhirVersion(), searchConfig.getEfsMount());
        return patientClaimsProcessor.process(patientClaimsRequest);
    } finally {
        RoundRobinBlockingQueue.CATEGORY_HOLDER.remove();
    }
}
Also used : Token(com.newrelic.api.agent.Token) Job(gov.cms.ab2d.common.model.Job)

Example 24 with Token

use of com.newrelic.api.agent.Token in project ab2d by CMSgov.

the class AggregatorJobTest method testWriteBunch.

@Test
void testWriteBunch() throws ParseException, IOException, InterruptedException {
    String job = "123";
    String contractNo = "ABCD";
    String org = "org1";
    final Token token = NewRelic.getAgent().getTransaction().getToken();
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(1L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(1)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(2L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(2)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(3L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(3)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(4L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(4)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(5L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(5)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(6L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(6)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(7L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(7)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(8L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(8)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(9L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(9)));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(10L), any())).thenReturn(BundleUtils.createBundle(createBundleEntry(10)));
    ContractForCoverageDTO contract = createContract(contractNo);
    PatientClaimsRequest request = new PatientClaimsRequest(createCoverageSummaries(10, contract), OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 9, ZoneOffset.UTC), OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 9, ZoneOffset.UTC), org, job, contract.getContractNumber(), Contract.ContractType.NORMAL, token, FhirVersion.STU3, tempDir.getAbsolutePath());
    ReflectionTestUtils.setField(processor, "earliestDataDate", "01/01/2020");
    Future<ProgressTrackerUpdate> future = processor.process(request);
    while (!future.isDone()) {
        Thread.sleep(500);
    }
    File[] files = (new File(tempDir + "/" + job + "/" + FINISHED)).listFiles();
    assertNotNull(files);
    assertEquals(1, files.length);
    List<String> allLines = Files.readAllLines(Path.of(files[0].getAbsolutePath()));
    assertEquals(10, allLines.size());
    assertTrue(allLines.get(0).contains("Patient/1"));
    assertTrue(allLines.get(1).contains("Patient/2"));
    assertTrue(allLines.get(9).contains("Patient/10"));
}
Also used : ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) Token(com.newrelic.api.agent.Token) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Token (com.newrelic.api.agent.Token)24 Trace (com.newrelic.api.agent.Trace)8 Transaction (com.newrelic.agent.Transaction)4 Tracer (com.newrelic.agent.tracers.Tracer)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 TransactionActivity (com.newrelic.agent.TransactionActivity)1 NoOpToken (com.newrelic.agent.bridge.NoOpToken)1 Transaction (com.newrelic.agent.bridge.Transaction)1 WeavePackageType (com.newrelic.api.agent.weaver.internal.WeavePackageType)1 MuleUtils (com.nr.agent.instrumentation.mule3.MuleUtils)1 Job (gov.cms.ab2d.common.model.Job)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1 FhirVersion (gov.cms.ab2d.fhir.FhirVersion)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1