Search in sources :

Example 1 with LazyMapImpl

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"));
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Example 2 with LazyMapImpl

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Example 3 with LazyMapImpl

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"));
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Example 4 with LazyMapImpl

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));
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Example 5 with LazyMapImpl

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Aggregations

LazyMapImpl (com.newrelic.agent.LazyMapImpl)5 Test (org.junit.Test)5 JSONArray (org.json.simple.JSONArray)3 JSONObject (org.json.simple.JSONObject)3 TransactionData (com.newrelic.agent.TransactionData)2 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2