Search in sources :

Example 6 with StatementNameStrategy

use of com.codahale.metrics.jdbi.strategies.StatementNameStrategy 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)

Example 7 with StatementNameStrategy

use of com.codahale.metrics.jdbi.strategies.StatementNameStrategy 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)

Example 8 with StatementNameStrategy

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

the class InstrumentedTimingCollectorTest method updatesTimerForNonSqlishRawSql.

@Test
public void updatesTimerForNonSqlishRawSql() throws Exception {
    final StatementNameStrategy strategy = new SmartNameStrategy();
    final InstrumentedTimingCollector collector = new InstrumentedTimingCollector(registry, strategy);
    final StatementContext ctx = mock(StatementContext.class);
    doReturn("don't know what it is but it's not SQL").when(ctx).getRawSql();
    collector.collect(TimeUnit.SECONDS.toNanos(3), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name("sql", "raw", "don't know what it is but it's not SQL"));
    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 9 with StatementNameStrategy

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

the class InstrumentedTimingCollectorTest method updatesTimerForContextGroupTypeAndName.

@Test
public void updatesTimerForContextGroupTypeAndName() 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("my-type").when(ctx).getAttribute(NameStrategies.STATEMENT_TYPE);
    doReturn("updatesTimerForContextGroupTypeAndName").when(ctx).getAttribute(NameStrategies.STATEMENT_NAME);
    collector.collect(TimeUnit.SECONDS.toNanos(5), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name("my-group", "my-type", "updatesTimerForContextGroupTypeAndName"));
    assertThat(timer.getSnapshot().getMax()).isEqualTo(5000000000L);
}
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 10 with StatementNameStrategy

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

the class InstrumentedTimingCollectorTest method updatesTimerForRawSql.

@Test
public void updatesTimerForRawSql() 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();
    collector.collect(TimeUnit.SECONDS.toNanos(2), ctx);
    final String name = strategy.getStatementName(ctx);
    final Timer timer = registry.timer(name);
    assertThat(name).isEqualTo(name("sql", "raw", "SELECT 1"));
    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)

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