Search in sources :

Example 1 with TimedAnnotationNameStrategy

use of com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategy in project dropwizard by dropwizard.

the class JdbiTest method setUp.

@BeforeEach
void setUp() throws Exception {
    environment = new Environment("test");
    metricRegistry = environment.metrics();
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:h2:mem:jdbi3-test");
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.asSingleConnectionPool();
    dbi = new JdbiFactory(new TimedAnnotationNameStrategy()).build(environment, dataSourceFactory, "h2");
    dbi.useTransaction(h -> {
        h.createScript(new String(ByteStreams.toByteArray(getClass().getResourceAsStream("/schema.sql")), StandardCharsets.UTF_8)).execute();
        h.createScript(new String(ByteStreams.toByteArray(getClass().getResourceAsStream("/data.sql")), StandardCharsets.UTF_8)).execute();
    });
    dao = dbi.onDemand(GameDao.class);
    for (LifeCycle lc : environment.lifecycle().getManagedObjects()) {
        lc.start();
    }
}
Also used : LifeCycle(org.eclipse.jetty.util.component.LifeCycle) DataSourceFactory(io.dropwizard.db.DataSourceFactory) Environment(io.dropwizard.setup.Environment) TimedAnnotationNameStrategy(com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TimedAnnotationNameStrategy (com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategy)1 DataSourceFactory (io.dropwizard.db.DataSourceFactory)1 Environment (io.dropwizard.setup.Environment)1 LifeCycle (org.eclipse.jetty.util.component.LifeCycle)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1