Search in sources :

Example 21 with StatementContext

use of org.skife.jdbi.v2.StatementContext 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)

Example 22 with StatementContext

use of org.skife.jdbi.v2.StatementContext 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

StatementContext (org.skife.jdbi.v2.StatementContext)20 Test (org.junit.Test)13 Timer (com.codahale.metrics.Timer)11 StatementNameStrategy (com.codahale.metrics.jdbi.strategies.StatementNameStrategy)11 SmartNameStrategy (com.codahale.metrics.jdbi.strategies.SmartNameStrategy)9 ResultSet (java.sql.ResultSet)8 SQLException (java.sql.SQLException)5 Handle (org.skife.jdbi.v2.Handle)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DataSegment (org.apache.druid.timeline.DataSegment)3 Interval (org.joda.time.Interval)3 ShortNameStrategy (com.codahale.metrics.jdbi.strategies.ShortNameStrategy)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DataSegment (io.druid.timeline.DataSegment)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Nullable (javax.annotation.Nullable)2 TransactionStatus (org.skife.jdbi.v2.TransactionStatus)2