use of jnc.platform.win32.Handle in project dropwizard by dropwizard.
the class DBIHealthCheckTest method testItTimesOutProperly.
@Test
public void testItTimesOutProperly() throws Exception {
String validationQuery = "select 1";
DBI dbi = mock(DBI.class);
Handle handle = mock(Handle.class);
when(dbi.open()).thenReturn(handle);
Mockito.doAnswer(invocation -> {
try {
TimeUnit.SECONDS.sleep(10);
} catch (Exception ignored) {
}
return null;
}).when(handle).execute(validationQuery);
ExecutorService executorService = Executors.newSingleThreadExecutor();
DBIHealthCheck dbiHealthCheck = new DBIHealthCheck(executorService, Duration.milliseconds(5), dbi, validationQuery);
HealthCheck.Result result = dbiHealthCheck.check();
executorService.shutdown();
assertThat("is unhealthy", false, is(result.isHealthy()));
}
use of jnc.platform.win32.Handle in project dropwizard by dropwizard.
the class JDBITest method setUp.
@Before
public void setUp() throws Exception {
when(environment.healthChecks()).thenReturn(healthChecks);
when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
when(environment.metrics()).thenReturn(metricRegistry);
when(environment.getHealthCheckExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
this.dbi = factory.build(environment, hsqlConfig, "hsql");
final ArgumentCaptor<Managed> managedCaptor = ArgumentCaptor.forClass(Managed.class);
verify(lifecycleEnvironment).manage(managedCaptor.capture());
managed.addAll(managedCaptor.getAllValues());
for (Managed obj : managed) {
obj.start();
}
try (Handle handle = dbi.open()) {
handle.createCall("DROP TABLE people IF EXISTS").invoke();
handle.createCall("CREATE TABLE people (name varchar(100) primary key, email varchar(100), age int, created_at timestamp)").invoke();
handle.createStatement("INSERT INTO people VALUES (?, ?, ?, ?)").bind(0, "Coda Hale").bind(1, "chale@yammer-inc.com").bind(2, 30).bind(3, new Timestamp(1365465078000L)).execute();
handle.createStatement("INSERT INTO people VALUES (?, ?, ?, ?)").bind(0, "Kris Gale").bind(1, "kgale@yammer-inc.com").bind(2, 32).bind(3, new Timestamp(1365465078000L)).execute();
handle.createStatement("INSERT INTO people VALUES (?, ?, ?, ?)").bind(0, "Old Guy").bindNull(1, Types.VARCHAR).bind(2, 99).bind(3, new Timestamp(1365465078000L)).execute();
handle.createStatement("INSERT INTO people VALUES (?, ?, ?, ?)").bind(0, "Alice Example").bind(1, "alice@example.org").bind(2, 99).bindNull(3, Types.TIMESTAMP).execute();
}
}
use of jnc.platform.win32.Handle in project dropwizard by dropwizard.
the class OptionalDoubleTest method setupTests.
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:optional-double-" + System.currentTimeMillis() + "?user=sa");
dataSourceFactory.setInitialSize(1);
final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
try (Handle h = dbi.open()) {
h.execute("CREATE TABLE test (id INT PRIMARY KEY, optional DOUBLE)");
}
dao = dbi.onDemand(TestDao.class);
}
use of jnc.platform.win32.Handle in project dropwizard by dropwizard.
the class OptionalIntTest method setupTests.
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:optional-int-" + System.currentTimeMillis() + "?user=sa");
dataSourceFactory.setInitialSize(1);
final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
try (Handle h = dbi.open()) {
h.execute("CREATE TABLE test (id INT PRIMARY KEY, optional INT)");
}
dao = dbi.onDemand(TestDao.class);
}
use of jnc.platform.win32.Handle in project dropwizard by dropwizard.
the class GuavaOptionalLocalDateTest method setupTests.
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:guava-local-date-" + System.currentTimeMillis() + "?user=sa");
dataSourceFactory.setInitialSize(1);
final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
try (Handle h = dbi.open()) {
h.execute("CREATE TABLE IF NOT EXISTS tasks (" + "id INT PRIMARY KEY, " + "assignee VARCHAR(255) NOT NULL, " + "start_date TIMESTAMP, " + "end_date TIMESTAMP, " + "comments VARCHAR(1024) " + ")");
}
dao = dbi.onDemand(TaskDao.class);
}
Aggregations