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());
}
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"));
}
Aggregations