use of com.newrelic.agent.LazyMapImpl in project newrelic-java-agent by newrelic.
the class TransactionEventTest method testJSONuserParametersEmptyWithAgentAtts.
@Test
public void testJSONuserParametersEmptyWithAgentAtts() throws Exception {
float duration = 0.001931f;
float totalTime = .012345f;
TransactionEvent event = new TransactionEventBuilder().setAppName(APP_NAME).setTimestamp(startTime).setName(metricName).setDuration(duration).setGuid(null).setReferringGuid(null).setPort(8081).setTripId(null).setApdexPerfZone(ApdexPerfZone.SATISFYING).setError(false).setpTotalTime(totalTime).setTimeoutCause(null).setPriority(.25F).build();
Map<String, Object> agentAtts = new LazyMapImpl<>();
agentAtts.put("key1", "value1");
agentAtts.put("key2", "value2");
event.agentAttributes = agentAtts;
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
assertEquals(3, jsonArray.size());
JSONObject jsonObject = (JSONObject) jsonArray.get(0);
assertEquals(9, jsonObject.size());
assertEquals(startTime, jsonObject.get("timestamp"));
assertEquals(metricName, jsonObject.get("name"));
assertEquals(duration, ((Number) jsonObject.get("duration")).floatValue(), Float.NaN);
assertEquals("Transaction", jsonObject.get("type"));
assertEquals(false, jsonObject.get("error"));
assertEquals(totalTime, ((Number) jsonObject.get("totalTime")).floatValue(), Float.NaN);
assertEquals(.25, ((Number) jsonObject.get("priority")).floatValue(), Float.NaN);
jsonObject = (JSONObject) jsonArray.get(1);
assertEquals(0, jsonObject.size());
jsonObject = (JSONObject) jsonArray.get(2);
assertEquals(2, jsonObject.size());
assertEquals("value1", jsonObject.get("key1"));
assertEquals("value2", jsonObject.get("key2"));
}
use of com.newrelic.agent.LazyMapImpl in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testUserParameters.
@Test
public void testUserParameters() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
Map<String, Object> userParams = new LazyMapImpl<>();
userParams.put("key1", "value1");
userParams.put("key2", "value2");
TransactionData transactionData = generateTransactionDataAndComplete(userParams, APP_NAME);
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
// populate the eventData map
service.harvestEvents(APP_NAME);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
assertEquals(1, currentEventData.size());
final TransactionEvent queueHead = currentEventData.peek();
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, queueHead.getDuration(), 0);
final Map<String, Object> attributes = queueHead.getUserAttributesCopy();
assertEquals(2, attributes.size());
assertEquals("value1", attributes.get("key1"));
assertEquals("value2", attributes.get("key2"));
service.harvestEvents(APP_NAME);
currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
}
use of com.newrelic.agent.LazyMapImpl in project newrelic-java-agent by newrelic.
the class TransactionEventTest method testJSONUserAndAgentAttributes.
@Test
public void testJSONUserAndAgentAttributes() throws Exception {
float duration = 0.001931f;
float totalTime = .002934f;
TransactionEvent event = new TransactionEventBuilder().setAppName(APP_NAME).setTimestamp(startTime).setName(metricName).setDuration(duration).setGuid(null).setReferringGuid(null).setPort(8081).setTripId(null).setApdexPerfZone(ApdexPerfZone.SATISFYING).setError(false).setpTotalTime(totalTime).setTimeoutCause(null).setPriority(.25F).putAllUserAttributes(ImmutableMap.<String, Object>of("key1", "value1", "key2", "value2", "user", "value3")).build();
Map<String, Object> agentAtts = new LazyMapImpl<>();
agentAtts.put("key1", "value1");
agentAtts.put("key2", "value2");
agentAtts.put("agent", "value4");
event.agentAttributes = agentAtts;
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
assertEquals(3, jsonArray.size());
JSONObject jsonObject = (JSONObject) jsonArray.get(0);
assertEquals(9, jsonObject.size());
assertEquals(startTime, jsonObject.get("timestamp"));
assertEquals(metricName, jsonObject.get("name"));
assertEquals(duration, ((Number) jsonObject.get("duration")).floatValue(), Float.NaN);
assertEquals("Transaction", jsonObject.get("type"));
assertEquals(false, jsonObject.get("error"));
assertEquals(totalTime, ((Number) jsonObject.get("totalTime")).floatValue(), Float.NaN);
assertEquals(.25, ((Number) jsonObject.get("priority")).floatValue(), Float.NaN);
jsonObject = (JSONObject) jsonArray.get(1);
assertEquals(3, jsonObject.size());
assertEquals("value1", jsonObject.get("key1"));
assertEquals("value2", jsonObject.get("key2"));
assertEquals("value3", jsonObject.get("user"));
jsonObject = (JSONObject) jsonArray.get(2);
assertEquals(3, jsonObject.size());
assertEquals("value1", jsonObject.get("key1"));
assertEquals("value2", jsonObject.get("key2"));
assertEquals("value4", jsonObject.get("agent"));
}
use of com.newrelic.agent.LazyMapImpl in project newrelic-java-agent by newrelic.
the class TransactionEventTest method testWebRequestAgentAttributes.
@Test
public void testWebRequestAgentAttributes() throws Exception {
float duration = 0.001931f;
float totalTime = .002934f;
TransactionEvent event = new TransactionEventBuilder().setAppName(APP_NAME).setTimestamp(startTime).setName(metricName).setDuration(duration).setGuid(null).setReferringGuid(null).setPort(8081).setTripId(null).setApdexPerfZone(ApdexPerfZone.SATISFYING).setError(false).setpTotalTime(totalTime).setTimeoutCause(null).setPriority(.25F).build();
Map<String, Object> agentAtts = new LazyMapImpl<>();
agentAtts.put(AttributeNames.REQUEST_ACCEPT_PARAMETER_NAME, "requestAccept");
agentAtts.put(AttributeNames.REQUEST_CONTENT_LENGTH_PARAMETER_NAME, "requestContentLength");
agentAtts.put(AttributeNames.REQUEST_HOST_PARAMETER_NAME, "requestHost");
agentAtts.put(AttributeNames.REQUEST_USER_AGENT_PARAMETER_NAME, "requestUserAgent");
agentAtts.put(AttributeNames.REQUEST_METHOD_PARAMETER_NAME, "requestMethod");
agentAtts.put(AttributeNames.RESPONSE_CONTENT_TYPE_PARAMETER_NAME, "responseContentType");
event.agentAttributes = agentAtts;
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
assertEquals(3, jsonArray.size());
// Agent attributes
JSONObject jsonObject = (JSONObject) jsonArray.get(2);
assertEquals(6, jsonObject.size());
assertEquals("requestAccept", jsonObject.get(AttributeNames.REQUEST_ACCEPT_PARAMETER_NAME));
assertEquals("requestContentLength", jsonObject.get(AttributeNames.REQUEST_CONTENT_LENGTH_PARAMETER_NAME));
assertEquals("requestHost", jsonObject.get(AttributeNames.REQUEST_HOST_PARAMETER_NAME));
assertEquals("requestUserAgent", jsonObject.get(AttributeNames.REQUEST_USER_AGENT_PARAMETER_NAME));
assertEquals("requestMethod", jsonObject.get(AttributeNames.REQUEST_METHOD_PARAMETER_NAME));
assertEquals("responseContentType", jsonObject.get(AttributeNames.RESPONSE_CONTENT_TYPE_PARAMETER_NAME));
}
use of com.newrelic.agent.LazyMapImpl in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testUserParametersDisabled.
@Test
public void testUserParametersDisabled() throws Exception {
setup(true, false, TEST_RESERVOIR_SIZE);
Map<String, Object> userParams = new LazyMapImpl<>();
userParams.put("key1", "value1");
userParams.put("key2", "value2");
TransactionData transactionData = generateTransactionDataAndComplete(userParams, APP_NAME);
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
// populate the eventData map
service.harvestEvents(APP_NAME);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
assertEquals(1, currentEventData.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
assertTrue(currentEventData.peek().getUserAttributesCopy().isEmpty());
service.harvestEvents(APP_NAME);
currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
}
Aggregations