Search in sources :

Example 11 with TransactionDataTestBuilder

use of com.newrelic.agent.TransactionDataTestBuilder in project newrelic-java-agent by newrelic.

the class ProfileTest method generateTransactionData.

private TransactionData generateTransactionData(Multimap<Long, Duration> threadIdToDuration, long startTime, long endTime, String appName) {
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(true);
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(endTime - startTime);
    rootTracer.setStartTime(startTime);
    rootTracer.setEndTime(endTime);
    AgentConfig agentConfig = ServiceFactory.getConfigService().getAgentConfig(appName);
    return new TransactionDataTestBuilder(appName, agentConfig, rootTracer).setDispatcher(rootTracer).setFrontendMetricName("keyTransaction").setThreadIdToDuration(threadIdToDuration).build();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 12 with TransactionDataTestBuilder

use of com.newrelic.agent.TransactionDataTestBuilder in project newrelic-java-agent by newrelic.

the class EventTestHelper method generateTransactionData.

private static TransactionData generateTransactionData(Map<String, Object> userParams, String appName, long durationInMillis) {
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(true);
    MockDispatcherTracer rootTracer = new MockDispatcherTracer();
    rootTracer.setDurationInMilliseconds(durationInMillis);
    long baseTime = System.nanoTime();
    rootTracer.setStartTime(baseTime);
    rootTracer.setEndTime(baseTime + TimeUnit.NANOSECONDS.convert(durationInMillis, TimeUnit.MILLISECONDS));
    // create a new string instance to verify that the transaction name cache is working
    String frontendMetricName = "Frontend/metricname" + System.currentTimeMillis();
    final AgentConfig agentConfig = ServiceFactory.getConfigService().getAgentConfig(appName);
    return new TransactionDataTestBuilder(appName, agentConfig, rootTracer).setDispatcher(rootTracer).setFrontendMetricName(frontendMetricName).setUserParams(userParams).setIncludeDistributedTracePayload(true).build();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 13 with TransactionDataTestBuilder

use of com.newrelic.agent.TransactionDataTestBuilder in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method createTransactionData.

private TransactionData createTransactionData(boolean isWebTransaction, int responseStatus, Throwable throwable, boolean expectedError, Map<String, String> requestParams, Map<String, Object> userParams, Map<String, Object> agentParams, Map<String, Object> errorParams, Map<String, Object> intrinsics) {
    AgentConfig iAgentConfig = mock(AgentConfig.class);
    ErrorCollectorConfig errorCollectorConfig = mock(ErrorCollectorConfig.class);
    when(iAgentConfig.getErrorCollectorConfig()).thenReturn(errorCollectorConfig);
    MockDispatcher dispatcher = new MockDispatcher();
    dispatcher.setWebTransaction(isWebTransaction);
    Tracer rootTracer = new MockDispatcherTracer();
    String frontendMetricName = isWebTransaction ? "WebTransaction/Uri/dude" : "OtherTransaction/Custom/dude";
    return new TransactionDataTestBuilder(APP_NAME, iAgentConfig, rootTracer).setDispatcher(dispatcher).setFrontendMetricName(frontendMetricName).setThrowable(throwable).setExpectedError(expectedError).setRequestUri("/dude").setResponseStatus(responseStatus).setStatusMessage("").setRequestParams(requestParams).setAgentParams(agentParams).setUserParams(userParams).setErrorParams(errorParams).setIntrinsics(intrinsics).build();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) Tracer(com.newrelic.agent.tracers.Tracer) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 14 with TransactionDataTestBuilder

use of com.newrelic.agent.TransactionDataTestBuilder in project newrelic-java-agent by newrelic.

the class TransactionTraceTest method serializeAttsDisabledWithIntrinsics.

@SuppressWarnings("unchecked")
@Test
public void serializeAttsDisabledWithIntrinsics() throws Exception {
    setUp(false, true, false);
    Tracer rootTracer = new TestMethodExitTracer();
    Map<String, Object> parameters = Collections.emptyMap();
    Tracer tracer = Mockito.mock(Tracer.class);
    Mockito.when(tracer.getClassMethodSignature()).thenReturn(new ClassMethodSignature(getClass().getName(), "testMethod", "testSignature"));
    Mockito.when(tracer.getAgentAttributes()).thenReturn(parameters);
    Mockito.when(tracer.getEndTime()).thenReturn(5000000000L);
    Mockito.when(tracer.getDuration()).thenReturn(3000000000L);
    ;
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key2", "value2");
    Map<String, Object> errorParams = new HashMap<>();
    errorParams.put("error1", "valueError");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key3", "value3");
    Map<String, Object> intrinsics = new HashMap<>();
    intrinsics.put("key4", "value4");
    intrinsics.put("key5", 5L);
    long startTime = System.currentTimeMillis();
    String frontendMetricName = "Frontend/dude";
    String requestUri = "/dude";
    String appName = "dude";
    String transactionGuid = "guid";
    TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, tracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Collections.singletonList(rootTracer)).setRequestParams(requestParams).setUserParams(userParams).setAgentParams(agentParams).setErrorParams(errorParams).setIntrinsics(intrinsics).build();
    TransactionTrace trace = TransactionTrace.getTransactionTrace(transactionData, SqlObfuscator.getDefaultSqlObfuscator());
    JSONParser parser = new JSONParser();
    // Get the raw data
    JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(trace);
    // Manually create an "inflated" version for comparison with simple compression
    JSONArray inflatedJsonArray = new JSONArray();
    inflatedJsonArray.addAll(jsonArray);
    // Extract and inflate
    Object decodedTTData = decodeTransactionTraceData(inflatedJsonArray.get(4));
    // Store back in array to compare with simple compression below
    inflatedJsonArray.set(4, decodedTTData);
    Assert.assertNotNull(jsonArray);
    // Second, serialize with simple compression off (data will be deflated)
    byte[] jsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
    JSONArray parsedJsonByteArray = (JSONArray) parser.parse(new String(jsonByteArray, StandardCharsets.UTF_8));
    Assert.assertEquals(jsonArray, parsedJsonByteArray);
    // Third, turn on simple compression and compare with raw data above
    setUp(false, true, true);
    byte[] simpleCompressionJsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
    JSONArray parsedSimpleCompressionJsonByteArray = (JSONArray) parser.parse(new String(simpleCompressionJsonByteArray, StandardCharsets.UTF_8));
    Assert.assertEquals(inflatedJsonArray, parsedSimpleCompressionJsonByteArray);
    JSONArray jsonRootSegment = (JSONArray) decodedTTData;
    Assert.assertEquals(8, jsonArray.size());
    Assert.assertEquals(startTime, jsonArray.get(0));
    Assert.assertEquals(5000L, jsonArray.get(1));
    Assert.assertEquals(frontendMetricName, jsonArray.get(2));
    Object serializedRequestUri = jsonArray.get(3);
    Assert.assertEquals(null, serializedRequestUri);
    Assert.assertEquals(transactionGuid, jsonArray.get(5));
    Assert.assertNull(jsonArray.get(6));
    // obsolete forcePersist flag
    Assert.assertEquals(false, jsonArray.get(7));
    Assert.assertEquals(5, jsonRootSegment.size());
    Assert.assertEquals(startTime, jsonRootSegment.get(0));
    JSONObject emptyObject = (JSONObject) jsonRootSegment.get(1);
    Assert.assertEquals(0, emptyObject.size());
    emptyObject = (JSONObject) jsonRootSegment.get(2);
    Assert.assertEquals(0, emptyObject.size());
    JSONObject atts = (JSONObject) jsonRootSegment.get(4);
    Assert.assertEquals(1, atts.size());
    Map<String, Object> innerAtts = (Map<String, Object>) atts.get("intrinsics");
    Assert.assertEquals(3, innerAtts.size());
    Assert.assertEquals("value4", innerAtts.get("key4"));
    Assert.assertEquals(5L, innerAtts.get("key5"));
    Assert.assertNotNull(innerAtts.get("totalTime"));
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) MethodExitTracer(com.newrelic.agent.tracers.MethodExitTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) JSONArray(org.json.simple.JSONArray) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with TransactionDataTestBuilder

use of com.newrelic.agent.TransactionDataTestBuilder in project newrelic-java-agent by newrelic.

the class TransactionTraceTest method serializeUserOnlyEnabledRequestAttsDisabled.

@SuppressWarnings("unchecked")
@Test
public void serializeUserOnlyEnabledRequestAttsDisabled() throws Exception {
    setUp(true, false, false);
    Tracer rootTracer = new TestMethodExitTracer();
    Map<String, Object> parameters = Collections.emptyMap();
    Tracer tracer = Mockito.mock(Tracer.class);
    Mockito.when(tracer.getClassMethodSignature()).thenReturn(new ClassMethodSignature(getClass().getName(), "testMethod", "testSignature"));
    Mockito.when(tracer.getAgentAttributes()).thenReturn(parameters);
    long rootTracerDurationInMilliseconds = 100L;
    Mockito.when(tracer.getDurationInMilliseconds()).thenReturn(rootTracerDurationInMilliseconds);
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key3", "value3");
    Map<String, Object> intrinsics = new HashMap<>();
    intrinsics.put("key4", "value4");
    intrinsics.put("key5", 5L);
    long startTime = System.currentTimeMillis();
    String frontendMetricName = "Frontend/dude";
    String requestUri = "/dude";
    String appName = "dude";
    TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, tracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Collections.singletonList(rootTracer)).setRequestParams(requestParams).setAgentParams(agentParams).setIntrinsics(intrinsics).build();
    TransactionTrace trace = TransactionTrace.getTransactionTrace(transactionData, SqlObfuscator.getDefaultSqlObfuscator());
    JSONParser parser = new JSONParser();
    // Get the raw data
    JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(trace);
    // Manually create an "inflated" version for comparison with simple compression
    JSONArray inflatedJsonArray = new JSONArray();
    inflatedJsonArray.addAll(jsonArray);
    // Extract and inflate
    Object decodedTTData = decodeTransactionTraceData(inflatedJsonArray.get(4));
    // Store back in array to compare with simple compression below
    inflatedJsonArray.set(4, decodedTTData);
    Assert.assertNotNull(jsonArray);
    // Second, serialize with simple compression off (data will be deflated)
    byte[] jsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
    JSONArray parsedJsonByteArray = (JSONArray) parser.parse(new String(jsonByteArray, StandardCharsets.UTF_8));
    Assert.assertEquals(jsonArray, parsedJsonByteArray);
    // Third, turn on simple compression and compare with raw data above
    setUp(true, false, true);
    byte[] simpleCompressionJsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
    JSONArray parsedSimpleCompressionJsonByteArray = (JSONArray) parser.parse(new String(simpleCompressionJsonByteArray, StandardCharsets.UTF_8));
    Assert.assertEquals(inflatedJsonArray, parsedSimpleCompressionJsonByteArray);
    JSONArray jsonRootSegment = (JSONArray) decodedTTData;
    Assert.assertEquals(requestUri, jsonArray.get(3));
    Assert.assertEquals(5, jsonRootSegment.size());
    JSONObject atts = (JSONObject) jsonRootSegment.get(4);
    Assert.assertEquals(2, atts.size());
    Map<String, Object> innerAtts = (Map<String, Object>) atts.get("agentAttributes");
    Assert.assertEquals(2, innerAtts.size());
    Assert.assertEquals("value3", innerAtts.get("key3"));
    innerAtts = (Map<String, Object>) atts.get("intrinsics");
    Assert.assertEquals(3, innerAtts.size());
    Assert.assertEquals("value4", innerAtts.get("key4"));
    Assert.assertEquals(5L, innerAtts.get("key5"));
    Assert.assertNotNull(innerAtts.get("totalTime"));
}
Also used : HashMap(java.util.HashMap) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) MethodExitTracer(com.newrelic.agent.tracers.MethodExitTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) JSONArray(org.json.simple.JSONArray) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)20 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)11 MockDispatcher (com.newrelic.agent.MockDispatcher)10 TransactionData (com.newrelic.agent.TransactionData)10 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)10 Tracer (com.newrelic.agent.tracers.Tracer)10 Test (org.junit.Test)10 AgentConfig (com.newrelic.agent.config.AgentConfig)9 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)9 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)9 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)9 JSONArray (org.json.simple.JSONArray)9 JSONObject (org.json.simple.JSONObject)9 JSONParser (org.json.simple.parser.JSONParser)9 HashMap (java.util.HashMap)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Map (java.util.Map)7 Transaction (com.newrelic.agent.Transaction)2 TransactionActivity (com.newrelic.agent.TransactionActivity)1 ErrorCollectorConfig (com.newrelic.agent.config.ErrorCollectorConfig)1