Search in sources :

Example 16 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsMonotonically.

@Test
public void jmxMetricRecordStatsMonotonically() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), .001);
    values.clear();
    values.put("hello", 7f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(7f, stats.getStats("Jmx/Sample/hello").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 17 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsSimpleForMultiBeanAddition.

@Test
public void jmxMetricRecordStatsSimpleForMultiBeanAddition() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    Assert.assertEquals(Float.valueOf(5), actual.get("Jmx/Sample/hello"));
    values.clear();
    // do not clear actual
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    Assert.assertEquals(Float.valueOf(12), actual.get("Jmx/Sample/hello"));
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 18 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsSimpleForMultiBean.

@Test
public void jmxMetricRecordStatsSimpleForMultiBean() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    actual.clear();
    values.put("hello", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(10f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 19 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsSimple.

@Test
public void jmxMetricRecordStatsSimple() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(10f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 20 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsMonotonicallyForMultiBeanAdd.

@Test
public void jmxMetricRecordStatsMonotonicallyForMultiBeanAdd() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    values.clear();
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Aggregations

StatsEngine (com.newrelic.agent.stats.StatsEngine)96 Test (org.junit.Test)78 TransactionDataList (com.newrelic.agent.TransactionDataList)36 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)31 TransactionData (com.newrelic.agent.TransactionData)29 HashMap (java.util.HashMap)25 JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)20 StatsWork (com.newrelic.agent.stats.StatsWork)8 MockRPMService (com.newrelic.agent.MockRPMService)7 ArrayList (java.util.ArrayList)6 AgentConfigFactoryTest (com.newrelic.agent.config.AgentConfigFactoryTest)5 Environment (com.newrelic.agent.environment.Environment)5 MetricName (com.newrelic.agent.metric.MetricName)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Attribute (javax.management.Attribute)5 MBeanServer (javax.management.MBeanServer)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)4 Stats (com.newrelic.agent.stats.Stats)4 HttpError (com.newrelic.agent.transport.HttpError)4 CountStatistic (javax.management.j2ee.statistics.CountStatistic)4