Search in sources :

Example 1 with CrossProcessConfig

use of com.newrelic.agent.config.CrossProcessConfig in project newrelic-java-agent by newrelic.

the class InboundHeaderStateTest method setup.

@Before
public void setup() {
    serviceManager.setConfigService(new MockConfigService(AgentConfigFactory.createAgentConfig(Collections.emptyMap(), Collections.emptyMap(), null)));
    ServiceFactory.setServiceManager(serviceManager);
    OutboundHeaders outboundHeaders = mock(OutboundHeaders.class);
    InboundHeaders inboundHeaders = mock(InboundHeaders.class);
    request = mock(ExtendedRequest.class);
    agentConfig = mock(AgentConfig.class);
    crossProcessConfig = mock(CrossProcessConfig.class);
    distributedTracingConfig = mock(DistributedTracingConfig.class);
    tx = mock(Transaction.class);
    when(inboundHeaders.getHeaderType()).thenReturn(HeaderType.HTTP);
    when(outboundHeaders.getHeaderType()).thenReturn(HeaderType.HTTP);
    when(crossProcessConfig.getEncodingKey()).thenReturn(encodingKey);
    when(crossProcessConfig.isCrossApplicationTracing()).thenReturn(true);
    when(distributedTracingConfig.isEnabled()).thenReturn(false);
    when(agentConfig.getDistributedTracingConfig()).thenReturn(distributedTracingConfig);
    when(tx.isIgnore()).thenReturn(false);
    when(tx.getDispatcher()).thenReturn(mock(Dispatcher.class));
    when(tx.getDispatcher().getRequest()).thenReturn(request);
    when(tx.getDispatcher().getRequest().getHeaderType()).thenReturn(HeaderType.HTTP);
    when(tx.getCrossProcessConfig()).thenReturn(crossProcessConfig);
    when(tx.getAgentConfig()).thenReturn(agentConfig);
    when(tx.getPriorityTransactionName()).thenReturn(PriorityTransactionName.create("Test", "TEST", TransactionNamePriority.NONE));
    when(tx.getApplicationName()).thenReturn("TestApp");
    when(tx.getLock()).thenReturn(new Object());
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) InboundHeaders(com.newrelic.api.agent.InboundHeaders) CrossProcessConfig(com.newrelic.agent.config.CrossProcessConfig) OutboundHeaders(com.newrelic.api.agent.OutboundHeaders) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) Before(org.junit.Before)

Example 2 with CrossProcessConfig

use of com.newrelic.agent.config.CrossProcessConfig in project newrelic-java-agent by newrelic.

the class CrossProcessStateCatApiTest method testCatApiResponseExternalMetrics.

@Test
public void testCatApiResponseExternalMetrics() throws UnsupportedEncodingException {
    Transaction transactionOne = Mockito.mock(Transaction.class);
    Mockito.when(transactionOne.getAgentConfig()).thenReturn(ServiceFactory.getConfigService().getDefaultAgentConfig());
    TransactionActivity txaOne = Mockito.mock(TransactionActivity.class);
    CrossProcessConfig cpsOneConfig = getCrossProcessConfig("CrossProcessId", "");
    setUpTransaction(transactionOne, txaOne, new Object(), new MockDispatcher(), cpsOneConfig, "guid");
    MetricNameFormat nameFormat = new ClassMethodMetricNameFormat(new ClassMethodSignature("className", "methodName", "()V"), null, "");
    CatTestCustomTracer requestTracer = new CatTestCustomTracer(transactionOne, new ClassMethodSignature("className", "methodName", "()V"), new Object(), nameFormat, TracerFlags.DISPATCHER);
    when(txaOne.getLastTracer()).thenReturn(requestTracer);
    CrossProcessTransactionStateImpl cpsOne = CrossProcessTransactionStateImpl.create(transactionOne);
    Transaction transactionTwo = Mockito.mock(Transaction.class);
    Mockito.when(transactionTwo.getAgentConfig()).thenReturn(ServiceFactory.getConfigService().getDefaultAgentConfig());
    TransactionActivity txaTwo = Mockito.mock(TransactionActivity.class);
    CrossProcessConfig cpsTwoConfig = getCrossProcessConfig("CrossProcessId", "");
    setUpTransaction(transactionTwo, txaTwo, new Object(), new MockDispatcher(), cpsTwoConfig, "guid");
    InboundHeaderState ihs = Mockito.mock(InboundHeaderState.class);
    when(ihs.isTrustedCatRequest()).thenReturn(true);
    when(transactionTwo.getInboundHeaderState()).thenReturn(ihs);
    CrossProcessTransactionStateImpl cpsTwo = CrossProcessTransactionStateImpl.create(transactionTwo);
    String requestMetadata = cpsOne.getRequestMetadata();
    // Transaction one generates requestMetadata. This metadata is embedded in payload and sent to transaction two.
    // Transaction two gets requestMetadata from payload and provides it to agent.
    cpsTwo.processRequestMetadata(requestMetadata);
    String responseMetadata = cpsTwo.getResponseMetadata();
    // Transaction two generates responseMetadata and sends it to transaction one.
    // Transaction one receives response.
    cpsOne.processResponseMetadata(responseMetadata, null);
    Set<String> rollupMetricNames = requestTracer.getRollupMetricNames();
    assertTrue(rollupMetricNames.contains("External/all"));
    assertTrue(rollupMetricNames.contains("External/allOther"));
    assertTrue(rollupMetricNames.contains("External/Unknown/all"));
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) CrossProcessConfig(com.newrelic.agent.config.CrossProcessConfig) Matchers.anyString(org.mockito.Matchers.anyString) DefaultMetricNameFormat(com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat) ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Test(org.junit.Test)

Aggregations

CrossProcessConfig (com.newrelic.agent.config.CrossProcessConfig)2 AgentConfig (com.newrelic.agent.config.AgentConfig)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)1 DefaultMetricNameFormat (com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat)1 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)1 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)1 InboundHeaders (com.newrelic.api.agent.InboundHeaders)1 OutboundHeaders (com.newrelic.api.agent.OutboundHeaders)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1