use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class HibernateCRUDTest method setUp.
@Override
public void setUp() throws Exception {
/*init dataSource*/
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:h2:file:~/.h2/HibernateCRUDTest;AUTO_SERVER=TRUE");
dataSource.setUsername("sa");
dataSource.setPassword("");
dataSource.setDefaultAutoCommit(false);
dataSource.setFilters("log4j");
/*init sessionFactory*/
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
factoryBean.setDataSource(dataSource);
Properties prop = new Properties();
prop.put("hibernate.show_sql", "true");
// prop.put("hibernate.format_sql", "true");
prop.put("hibernate.hbm2ddl.auto", "create");
prop.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
factoryBean.setHibernateProperties(prop);
factoryBean.setAnnotatedClasses(new Class<?>[] { Sample.class });
try {
factoryBean.afterPropertiesSet();
} catch (IOException e) {
e.printStackTrace();
}
sessionFactory = factoryBean.getObject();
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DupRegisterTest method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setMinEvictableIdleTimeMillis(10);
dataSource.setTimeBetweenEvictionRunsMillis(10);
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class LoggerTest method test_log.
public void test_log() throws Exception {
TestLoader classLoader = new TestLoader();
Thread.currentThread().setContextClassLoader(classLoader);
dataSource = new DruidDataSource();
dataSource.setFilters("log");
dataSource.setUrl("jdbc:mock:xx");
Connection conn = dataSource.getConnection();
conn.close();
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class AsyncInitTest_1_scheduler method setUp.
protected void setUp() throws Exception {
super.setUp();
dataSource = new DruidDataSource();
dataSource.setAsyncInit(true);
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setInitialSize(10);
dataSource.setMaxActive(10);
scheduler = Executors.newScheduledThreadPool(2);
dataSource.setCreateScheduler(scheduler);
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class Case1 method test_f.
public void test_f() throws Exception {
final DruidDataSource dataSource = new DruidDataSource();
dataSource.setTimeBetweenConnectErrorMillis(100);
final long startTime = System.currentTimeMillis();
final long okTime = startTime + 1000 * 1;
dataSource.setDriver(new MockDriver() {
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (System.currentTimeMillis() < okTime) {
throw new SQLException();
}
return super.connect(url, info);
}
});
dataSource.setUrl("jdbc:mock:");
dataSource.setMinIdle(0);
dataSource.setMaxActive(2);
dataSource.setMaxIdle(2);
Connection conn = dataSource.getConnection();
conn.close();
dataSource.close();
}
Aggregations