Search in sources :

Example 1 with SmartNameStrategy

use of com.codahale.metrics.jdbi.strategies.SmartNameStrategy in project metrics by dropwizard.

the class InstrumentedTimingCollectorTest method updatesTimerForTemplateFile.

@Test
public void updatesTimerForTemplateFile() throws Exception {
    final StatementNameStrategy strategy = new SmartNameStrategy();
    final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
    final StatementContext ctx = mock(StatementContext.class);
    doReturn("SELECT 1").when(ctx).getRawSql();
    doReturn("foo/bar.stg").when(ctx).getAttribute(NameStrategies.STATEMENT_GROUP);
    doReturn("updatesTimerForTemplateFile").when(ctx).getAttribute(NameStrategies.STATEMENT_NAME);
    collector.collect(TimeUnit.SECONDS.toNanos(4), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name("foo", "bar", "updatesTimerForTemplateFile"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(4000000000L);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) SmartNameStrategy(com.codahale.metrics.jdbi.strategies.SmartNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Example 2 with SmartNameStrategy

use of com.codahale.metrics.jdbi.strategies.SmartNameStrategy in project metrics by dropwizard.

the class InstrumentedTimingCollectorTest method updatesTimerForSqlObjects.

@Test
public void updatesTimerForSqlObjects() throws Exception {
    final StatementNameStrategy strategy = new SmartNameStrategy();
    final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
    final StatementContext ctx = mock(StatementContext.class);
    doReturn("SELECT 1").when(ctx).getRawSql();
    doReturn(getClass()).when(ctx).getSqlObjectType();
    doReturn(getClass().getMethod("updatesTimerForSqlObjects")).when(ctx).getSqlObjectMethod();
    collector.collect(TimeUnit.SECONDS.toNanos(1), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name(getClass(), "updatesTimerForSqlObjects"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(1000000000);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) SmartNameStrategy(com.codahale.metrics.jdbi.strategies.SmartNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Example 3 with SmartNameStrategy

use of com.codahale.metrics.jdbi.strategies.SmartNameStrategy in project metrics by dropwizard.

the class InstrumentedTimingCollectorTest method updatesTimerForNoRawSql.

@Test
public void updatesTimerForNoRawSql() throws Exception {
    final StatementNameStrategy strategy = new SmartNameStrategy();
    final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
    final StatementContext ctx = mock(StatementContext.class);
    collector.collect(TimeUnit.SECONDS.toNanos(2), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name("sql", "empty"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(2000000000);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) SmartNameStrategy(com.codahale.metrics.jdbi.strategies.SmartNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Example 4 with SmartNameStrategy

use of com.codahale.metrics.jdbi.strategies.SmartNameStrategy in project metrics by dropwizard.

the class InstrumentedTimingCollectorTest method updatesTimerForContextClass.

@Test
public void updatesTimerForContextClass() throws Exception {
    final StatementNameStrategy strategy = new SmartNameStrategy();
    final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
    final StatementContext ctx = mock(StatementContext.class);
    doReturn("SELECT 1").when(ctx).getRawSql();
    doReturn(getClass().getName()).when(ctx).getAttribute(NameStrategies.STATEMENT_CLASS);
    doReturn("updatesTimerForContextClass").when(ctx).getAttribute(NameStrategies.STATEMENT_NAME);
    collector.collect(TimeUnit.SECONDS.toNanos(3), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name(getClass(), "updatesTimerForContextClass"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(3000000000L);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) SmartNameStrategy(com.codahale.metrics.jdbi.strategies.SmartNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Example 5 with SmartNameStrategy

use of com.codahale.metrics.jdbi.strategies.SmartNameStrategy in project metrics by dropwizard.

the class InstrumentedTimingCollectorTest method updatesTimerForSqlObjectsWithoutMethod.

@Test
public void updatesTimerForSqlObjectsWithoutMethod() throws Exception {
    final StatementNameStrategy strategy = new SmartNameStrategy();
    final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
    final StatementContext ctx = mock(StatementContext.class);
    doReturn("SELECT 1").when(ctx).getRawSql();
    doReturn(getClass()).when(ctx).getSqlObjectType();
    collector.collect(TimeUnit.SECONDS.toNanos(1), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name(getClass(), "SELECT 1"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(1000000000);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) SmartNameStrategy(com.codahale.metrics.jdbi.strategies.SmartNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Aggregations

Timer (com.codahale.metrics.Timer)9 SmartNameStrategy (com.codahale.metrics.jdbi.strategies.SmartNameStrategy)9 StatementNameStrategy (com.codahale.metrics.jdbi.strategies.StatementNameStrategy)9 Test (org.junit.Test)9 StatementContext (org.skife.jdbi.v2.StatementContext)9