Search in sources :

Example 1 with ShortNameStrategy

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

the class InstrumentedTimingCollectorTest method updatesTimerForShortSqlObjectStrategy.

@Test
public void updatesTimerForShortSqlObjectStrategy() throws Exception {
    final StatementNameStrategy strategy = new ShortNameStrategy("jdbi");
    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("updatesTimerForShortSqlObjectStrategy")).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("jdbi", getClass().getSimpleName(), "updatesTimerForShortSqlObjectStrategy"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(1000000000);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) ShortNameStrategy(com.codahale.metrics.jdbi.strategies.ShortNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Example 2 with ShortNameStrategy

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

the class InstrumentedTimingCollectorTest method updatesTimerForShortContextClassStrategy.

@Test
public void updatesTimerForShortContextClassStrategy() throws Exception {
    final StatementNameStrategy strategy = new ShortNameStrategy("jdbi");
    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("updatesTimerForShortContextClassStrategy").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("jdbi", getClass().getSimpleName(), "updatesTimerForShortContextClassStrategy"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(3000000000L);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) ShortNameStrategy(com.codahale.metrics.jdbi.strategies.ShortNameStrategy) StatementContext(org.skife.jdbi.v2.StatementContext) Test(org.junit.Test)

Aggregations

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