use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestValidation method validateInvalidValidationTimeout.
@Test
public void validateInvalidValidationTimeout() {
try {
HikariConfig config = newHikariConfig();
config.setValidationTimeout(10L);
fail();
} catch (IllegalArgumentException ise) {
assertTrue(ise.getMessage().contains("validationTimeout cannot be less than 250ms"));
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestValidation method validateInvalidMinIdle.
@Test
public void validateInvalidMinIdle() {
try {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(-1);
fail();
} catch (IllegalArgumentException ise) {
assertTrue(ise.getMessage().contains("minimumIdle cannot be negative"));
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class UnwrapTest method testUnwrapDataSource.
@Test
public void testUnwrapDataSource() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setInitializationFailTimeout(0);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
StubDataSource unwrap = ds.unwrap(StubDataSource.class);
assertNotNull(unwrap);
assertTrue(unwrap instanceof StubDataSource);
assertTrue(ds.isWrapperFor(HikariDataSource.class));
assertTrue(ds.unwrap(HikariDataSource.class) instanceof HikariDataSource);
assertFalse(ds.isWrapperFor(getClass()));
try {
ds.unwrap(getClass());
} catch (SQLException e) {
assertTrue(e.getMessage().contains("Wrapped DataSource"));
}
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestJNDI method testJndiLookup4.
@Test
public void testJndiLookup4() throws Exception {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.osjava.sj.memory.MemoryContextFactory");
System.setProperty("org.osjava.sj.jndi.shared", "true");
InitialContext ic = new InitialContext();
StubDataSource ds = new StubDataSource();
Context subcontext = ic.createSubcontext("java:/comp/env/jdbc");
subcontext.bind("java:/comp/env/jdbc/myDS", ds);
HikariConfig config = newHikariConfig();
config.setDataSourceJNDI("java:/comp/env/jdbc/myDS");
try (HikariDataSource hds = new HikariDataSource(config);
Connection conn = hds.getConnection()) {
assertNotNull(conn);
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestMBean method testMBeanRegistration.
@Test
public void testMBeanRegistration() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(0);
config.setMaximumPoolSize(1);
config.setRegisterMbeans(true);
config.setConnectionTimeout(2800);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
// Close immediately
}
}
Aggregations