protected void setUp() throws Exception {
    TabularData sqlList = JdbcStatManager.getInstance().getSqlList();
    if (sqlList.size() > 0) {
      for (Object item : JdbcStatManager.getInstance().getSqlList().values()) {
        String text = JSONUtils.toJSONString(item);
        System.out.println(text);
      }
    }

    Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());

    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xx");
    dataSource.setFilters("mergeStat");
    dataSource.setDbType("mysql");
  }
  protected void setUp() throws Exception {
    Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());

    dataSource = new DruidDataSource();

    dataSource.setExceptionSorter(new OracleExceptionSorter());

    dataSource.setDriver(new OracleMockDriver());
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(100);
  }
Exemplo n.º 3
0
  /**
   * 参数定义: com.alibaba.druid.log.LogFilter=filter com.alibaba.druid.log.LogFilter.p1=prop-value
   * com.alibaba.druid.log.LogFilter.p2=prop-value
   *
   * @param url
   * @return
   * @throws SQLException
   */
  private DataSourceProxyImpl getDataSource(String url, Properties info) throws SQLException {
    DataSourceProxyImpl dataSource = proxyDataSources.get(url);

    if (dataSource == null) {
      DataSourceProxyConfig config = parseConfig(url, info);

      Driver rawDriver = createDriver(config.getRawDriverClassName());

      DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);

      {
        String property = System.getProperty("druid.filters");
        if (property != null && property.length() > 0) {
          for (String filterItem : property.split(",")) {
            FilterManager.loadFilter(config.getFilters(), filterItem);
          }
        }
      }
      {
        int dataSourceId = createDataSourceId();
        newDataSource.setId(dataSourceId);

        for (Filter filter : config.getFilters()) {
          filter.init(newDataSource);
        }
      }

      DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource);
      if (oldDataSource == null) {
        if (config.isJmxOption()) {
          JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
        }
      }

      dataSource = proxyDataSources.get(url);
    }
    return dataSource;
  }
Exemplo n.º 4
0
  protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();

    driver = new MockDriver();

    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000); // 180 / 10
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat,trace");

    JdbcStatContext context = new JdbcStatContext();
    context.setTraceEnable(true);
    JdbcStatManager.getInstance().setStatContext(context);
  }
Exemplo n.º 5
0
  protected void tearDown() throws Exception {
    dataSource.close();
    Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());

    JdbcStatManager.getInstance().setStatContext(null);
  }
Exemplo n.º 6
0
 protected void tearDown() throws Exception {
   DruidDriver.getProxyDataSources().clear();
   Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
 }
  protected void tearDown() throws Exception {
    JdbcUtils.close(dataSource);

    Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
  }