mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #1069 from ma459006574/master
新增对simple-jndi的支持,就可以在kettle的simple-jndi中配置druid数据库连接池了
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.osjava.sj.SimpleContext;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class DruidDataSourceConverterTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
String root = DruidDataSourceConverterTest.class
|
||||
.getResource("/com/alibaba/druid/pool/simplejndi/").toString();
|
||||
if (root.startsWith("file:/"))
|
||||
root = root.substring("file://".length() - 1);
|
||||
Properties props = new Properties();
|
||||
props.put("org.osjava.sj.root", root);
|
||||
props.put("java.naming.factory.initial",
|
||||
"org.osjava.sj.SimpleContextFactory");
|
||||
props.put("org.osjava.sj.delimiter", "/");
|
||||
javax.naming.Context ctx = new SimpleContext(props);
|
||||
dataSource = (DruidDataSource) ctx.lookup("jdbc/druidTest");
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_conn() throws Exception {
|
||||
Assert.assertEquals(true, dataSource.isInited());
|
||||
Connection conn = dataSource.getConnection();
|
||||
Assert.assertEquals(1, dataSource.getActiveCount());
|
||||
conn.close();
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user