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);
}
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);
}
Aggregations