예제 #1
0
  public void test_count_filter() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    config.setUrl("");
    config.setRawUrl("jdbc:mock:");

    StatFilter filter = new StatFilter();

    MockDriver driver = new MockDriver();
    DataSourceProxyImpl dataSource = new DataSourceProxyImpl(driver, config);

    filter.init(dataSource);
    config.getFilters().add(filter);

    Connection conn = dataSource.connect(null);

    Statement stmt = conn.createStatement();
    ResultSetProxy rs = (ResultSetProxy) stmt.executeQuery(sql);
    rs.close();
    stmt.close();

    conn.close();
    conn.close();

    dataSource.getCompositeData();
    dataSource.getProperties();
    dataSource.getDataSourceMBeanDomain();
  }
예제 #2
0
  public void test_countFilter() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    config.setUrl("");

    DataSourceProxyImpl dataSource = new DataSourceProxyImpl(null, config);
    JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();

    StatFilter filter = new StatFilter();
    filter.init(dataSource);

    dataSourceStat.reset();

    Assert.assertNull(StatFilter.getStatFilter(dataSource));
    Assert.assertNull(dataSourceStat.getSqlStat(Integer.MAX_VALUE));
    Assert.assertNull(dataSourceStat.getConnectionStat().getConnectLastTime());

    FilterChain chain =
        new FilterChainImpl(dataSource) {

          public ConnectionProxy connection_connect(Properties info) throws SQLException {
            throw new SQLException();
          }
        };

    Exception error = null;
    try {
      filter.connection_connect(chain, new Properties());
    } catch (SQLException ex) {
      error = ex;
    }
    Assert.assertNotNull(error);
    Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectErrorCount());
    Assert.assertNotNull(dataSourceStat.getConnectionStat().getConnectLastTime());
  }