Search in sources :

Example 76 with StatsEngine

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

the class J2EEStatsAttributeTest method addJcaValueJdbcTest.

@Test
public void addJcaValueJdbcTest() throws MalformedObjectNameException {
    JCAStats count = new JCAStats() {

        @Override
        public JCAConnectionStats[] getConnections() {
            return new JCAConnectionStats[0];
        }

        @Override
        public JCAConnectionPoolStats[] getConnectionPools() {
            return new JCAConnectionPoolStats[] { new TestJcaConnectionPool() };
        }

        @Override
        public Statistic getStatistic(String statisticName) {
            return null;
        }

        @Override
        public String[] getStatisticNames() {
            return null;
        }

        @Override
        public Statistic[] getStatistics() {
            return new Statistic[0];
        }
    };
    Attribute att = new Attribute("stats", count);
    J2EEStatsAttributeProcessor processor = new J2EEStatsAttributeProcessor();
    StatsEngine engine = new StatsEngineImpl();
    processor.process(engine, new ObjectInstance("tezt:type=2", "test"), att, "JMX/Test", new HashMap<String, Float>());
    // check count stats
    Assert.assertEquals(6, engine.getStats("JMX/Test/Create").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Create").getCallCount(), .001);
    Assert.assertEquals(99, engine.getStats("JMX/Test/Closed").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Closed").getCallCount(), .001);
    // check time stats
    Assert.assertEquals(10, engine.getResponseTimeStats("JMX/Test/Wait").getMaxCallTime(), .001);
    Assert.assertEquals(5, engine.getResponseTimeStats("JMX/Test/Wait").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/Wait").getCallCount(), .001);
    Assert.assertEquals(6, engine.getResponseTimeStats("JMX/Test/User").getMaxCallTime(), .001);
    Assert.assertEquals(4, engine.getResponseTimeStats("JMX/Test/User").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/User").getCallCount(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JCAConnectionStats(javax.management.j2ee.statistics.JCAConnectionStats) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) TimeStatistic(javax.management.j2ee.statistics.TimeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) BoundaryStatistic(javax.management.j2ee.statistics.BoundaryStatistic) Statistic(javax.management.j2ee.statistics.Statistic) JCAStats(javax.management.j2ee.statistics.JCAStats) JCAConnectionPoolStats(javax.management.j2ee.statistics.JCAConnectionPoolStats) Test(org.junit.Test)

Example 77 with StatsEngine

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

the class JmxMetricTest method jmxMetricRecordStatsSubTypeMonoMulti.

@Test
public void jmxMetricRecordStatsSubTypeMonoMulti() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create(new String[] { "first", "second" }, "theDiff", JmxAction.SUBTRACT_ALL_FROM_FIRST, JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("first", 10f);
    values.put("second", 7f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theDiff").getCallCount());
    Assert.assertEquals(3f, stats.getStats("Jmx/Sample/theDiff").getTotal(), .001);
    values.clear();
    actual.clear();
    values.put("first", 12f);
    values.put("second", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/theDiff").getCallCount());
    Assert.assertEquals(7f, stats.getStats("Jmx/Sample/theDiff").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 78 with StatsEngine

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

the class JmxMetricTest method jmxMetricRecordStatsMonotonicallyForMultiBean.

@Test
public void jmxMetricRecordStatsMonotonicallyForMultiBean() {
    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);
    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", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(7f, 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 79 with StatsEngine

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

the class JmxMetricTest method jmxMetricRecordStatsChangeNameSimpleMultiAdd.

@Test
public void jmxMetricRecordStatsChangeNameSimpleMultiAdd() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", "theHello", 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(0, stats.getStats("Jmx/Sample/theHello").getCallCount());
    values.clear();
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/theHello").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 80 with StatsEngine

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

the class JmxMetricTest method jmxMetricRecordStatsChangeNameSimpleMulti.

@Test
public void jmxMetricRecordStatsChangeNameSimpleMulti() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", "theHello", 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/theHello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/theHello").getTotal(), 0);
    values.clear();
    values.put("hello", 7f);
    actual.clear();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/theHello").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)

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