Search in sources :

Example 1 with ExtendedRequest

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

the class CrossProcessTransactionStateImplTest method testBlankHeader.

@Test
public void testBlankHeader() {
    String encodingKey = "test";
    ExtendedRequest request = createRequestFromStandardHeaders(null, null, null);
    configureCatEnabled(encodingKey, null);
    mockDispatcher(request);
    mockConfigFromTransaction();
    mockBasicTransactionMethods();
    when(tx.acceptDistributedTracePayload(anyString())).thenReturn(true);
    InboundHeaderState ihs = new InboundHeaderState(tx, request);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    when(tx.getTransactionActivity()).thenReturn(ta);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    verify(response, never()).setHeader(anyString(), anyString());
    assertNull(tx.getInboundHeaderState().getClientCrossProcessId());
}
Also used : ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with ExtendedRequest

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

the class CrossProcessTransactionStateImplTest method testCrossProcessTracingDisabled.

@Test
public void testCrossProcessTracingDisabled() {
    ExtendedRequest request = createRequestFromStandardHeaders(null, null, null);
    when(crossProcessConfig.getEncodingKey()).thenReturn(null);
    when(crossProcessConfig.getCrossProcessId()).thenReturn(null);
    when(crossProcessConfig.isCrossApplicationTracing()).thenReturn(false);
    when(distributedTracingConfig.isEnabled()).thenReturn(false);
    mockDispatcher(request);
    mockConfigFromTransaction();
    mockBasicTransactionMethods();
    when(tx.acceptDistributedTracePayload(anyString())).thenReturn(true);
    InboundHeaderState ihs = new InboundHeaderState(tx, request);
    assertNull(ihs.getClientCrossProcessId());
}
Also used : ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Test(org.junit.Test)

Example 3 with ExtendedRequest

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

the class CrossProcessTransactionStateImplTest method testAppDataHeader.

@Test
public void testAppDataHeader() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String txGuid = "5001D";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, "12345");
    stats = new TransactionStats();
    configureTestMocks(encodingKey, txGuid, obfuscatedAppData, request);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    crossProcessTransactionState.writeResponseHeaders();
    verifyMocks(obfuscatedAppData);
    assertEquals(1, stats.getUnscopedStats().getSize());
    ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
    assertEquals(1, clientAppStats.getCallCount());
    assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
    assertNull(tx.getInboundHeaderState().getReferrerGuid());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with ExtendedRequest

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

the class CrossProcessTransactionStateImplTest method testNoContentLengthNoQueueTime.

@Test
public void testNoContentLengthNoQueueTime() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String txGuid = "5001D";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",0.0,0.2,-1,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, null);
    doNothing().when(response).setHeader("X-NewRelic-App-Data", obfuscatedAppData);
    configureCatEnabled(encodingKey, true);
    mockDispatcher(request);
    mockConfigFromTransaction();
    mockBasicTransactionMethods();
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getRequestContentLength()).thenReturn(-1L);
    when(ihs.getReferrerGuid()).thenReturn(null);
    when(ihs.isTrustedCatRequest()).thenReturn(true);
    when(ihs.getClientCrossProcessId()).thenReturn(incomingId);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    doNothing().when(tx).freezeTransactionName();
    when(tx.getExternalTime()).thenReturn(0L);
    PriorityTransactionName txName = PriorityTransactionName.create("WebTransaction/test/test", null, TransactionNamePriority.JSP);
    when(tx.getPriorityTransactionName()).thenReturn(txName);
    when(tx.getTransactionActivity()).thenReturn(ta);
    doNothing().when(ta).markAsResponseSender();
    when(ta.getTransactionStats()).thenReturn(stats);
    long durationInNanos = TimeUnit.NANOSECONDS.convert(200L, TimeUnit.MILLISECONDS);
    when(tx.getRunningDurationInNanos()).thenReturn(durationInNanos);
    when(tx.getGuid()).thenReturn(txGuid);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    verifyMocks(obfuscatedAppData);
    assertEquals(1, stats.getUnscopedStats().getSize());
    ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
    assertEquals(1, clientAppStats.getCallCount());
    assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with ExtendedRequest

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

the class CrossProcessTransactionStateImplTest method testUntrustedAccountId.

@Test
public void testUntrustedAccountId() {
    String encodingKey = "test";
    // Set up enough mocks that we can create a real InboundHeaderState instance
    ExtendedRequest request = createRequestFromStandardHeaders(null, null, null);
    configureCatEnabled(encodingKey, false);
    mockDispatcher(request);
    mockBasicTransactionMethods();
    mockConfigFromTransaction();
    when(tx.acceptDistributedTracePayload(anyString())).thenReturn(true);
    InboundHeaderState ihs = new InboundHeaderState(tx, request);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    when(tx.getTransactionActivity()).thenReturn(ta);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    verify(response, never()).setHeader(anyString(), anyString());
    assertNull(tx.getInboundHeaderState().getClientCrossProcessId());
}
Also used : ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)7 Test (org.junit.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)3 Transaction (com.newrelic.agent.Transaction)1 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)1 AgentIdentity (com.newrelic.agent.environment.AgentIdentity)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 Trace (com.newrelic.api.agent.Trace)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)1