Search in sources :

Example 11 with StatementNameStrategy

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

the class InstrumentedTimingCollectorTest method updatesTimerForContextGroupAndName.

@Test
public void updatesTimerForContextGroupAndName() 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("my-group").when(ctx).getAttribute(NameStrategies.STATEMENT_GROUP);
    doReturn("updatesTimerForContextGroupAndName").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("my-group", "updatesTimerForContextGroupAndName", ""));
    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)

Aggregations

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