Search in sources :

Example 1 with InstrumentedSqlLogger

use of com.codahale.metrics.jdbi3.InstrumentedSqlLogger in project metrics by dropwizard.

the class InstrumentedSqlLoggerTest method logsExceptionTime.

@Test
public void logsExceptionTime() {
    final MetricRegistry mockRegistry = mock(MetricRegistry.class);
    final StatementNameStrategy mockNameStrategy = mock(StatementNameStrategy.class);
    final InstrumentedSqlLogger logger = new InstrumentedSqlLogger(mockRegistry, mockNameStrategy);
    final StatementContext mockContext = mock(StatementContext.class);
    final Timer mockTimer = mock(Timer.class);
    final String statementName = "my-fake-name";
    final long fakeElapsed = 1234L;
    when(mockNameStrategy.getStatementName(mockContext)).thenReturn(statementName);
    when(mockRegistry.timer(statementName)).thenReturn(mockTimer);
    when(mockContext.getElapsedTime(ChronoUnit.NANOS)).thenReturn(fakeElapsed);
    logger.logException(mockContext, new SQLException());
    verify(mockTimer).update(fakeElapsed, TimeUnit.NANOSECONDS);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi3.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) SQLException(java.sql.SQLException) MetricRegistry(com.codahale.metrics.MetricRegistry) StatementContext(org.jdbi.v3.core.statement.StatementContext) Test(org.junit.Test)

Example 2 with InstrumentedSqlLogger

use of com.codahale.metrics.jdbi3.InstrumentedSqlLogger in project metrics by dropwizard.

the class InstrumentedSqlLoggerTest method logsExecutionTime.

@Test
public void logsExecutionTime() {
    final MetricRegistry mockRegistry = mock(MetricRegistry.class);
    final StatementNameStrategy mockNameStrategy = mock(StatementNameStrategy.class);
    final InstrumentedSqlLogger logger = new InstrumentedSqlLogger(mockRegistry, mockNameStrategy);
    final StatementContext mockContext = mock(StatementContext.class);
    final Timer mockTimer = mock(Timer.class);
    final String statementName = "my-fake-name";
    final long fakeElapsed = 1234L;
    when(mockNameStrategy.getStatementName(mockContext)).thenReturn(statementName);
    when(mockRegistry.timer(statementName)).thenReturn(mockTimer);
    when(mockContext.getElapsedTime(ChronoUnit.NANOS)).thenReturn(fakeElapsed);
    logger.logAfterExecution(mockContext);
    verify(mockTimer).update(fakeElapsed, TimeUnit.NANOSECONDS);
}
Also used : StatementNameStrategy(com.codahale.metrics.jdbi3.strategies.StatementNameStrategy) Timer(com.codahale.metrics.Timer) MetricRegistry(com.codahale.metrics.MetricRegistry) StatementContext(org.jdbi.v3.core.statement.StatementContext) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)2 Timer (com.codahale.metrics.Timer)2 StatementNameStrategy (com.codahale.metrics.jdbi3.strategies.StatementNameStrategy)2 StatementContext (org.jdbi.v3.core.statement.StatementContext)2 Test (org.junit.Test)2 SQLException (java.sql.SQLException)1