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
  public CompositeDataSupport getCompositeData() throws JMException {
    JdbcDataSourceStat stat = this.getDataSourceStat();

    Map<String, Object> map = new HashMap<String, Object>();

    map.put("ID", id);
    map.put("URL", this.getUrl());
    map.put("Name", this.getName());
    map.put("FilterClasses", getFilterClasses());
    map.put("CreatedTime", getCreatedTime());

    map.put("RawDriverClassName", getRawDriverClassName());
    map.put("RawUrl", getRawUrl());
    map.put("RawDriverMajorVersion", getRawDriverMajorVersion());
    map.put("RawDriverMinorVersion", getRawDriverMinorVersion());
    map.put("Properties", getProperties());

    if (stat != null) {
      map.put("ConnectionActiveCount", stat.getConnectionActiveCount());
      map.put("ConnectionActiveCountMax", stat.getConnectionStat().getActiveMax());
      map.put("ConnectionCloseCount", stat.getConnectionStat().getCloseCount());
      map.put("ConnectionCommitCount", stat.getConnectionStat().getCommitCount());
      map.put("ConnectionRollbackCount", stat.getConnectionStat().getRollbackCount());

      map.put("ConnectionConnectLastTime", stat.getConnectionStat().getConnectLastTime());
      map.put("ConnectionConnectErrorCount", stat.getConnectionStat().getConnectErrorCount());
      Throwable lastConnectionConnectError = stat.getConnectionStat().getConnectErrorLast();
      if (lastConnectionConnectError != null) {
        map.put("ConnectionConnectErrorLastTime", stat.getConnectionStat().getErrorLastTime());
        map.put("ConnectionConnectErrorLastMessage", lastConnectionConnectError.getMessage());
        map.put(
            "ConnectionConnectErrorLastStackTrace",
            Utils.getStackTrace(lastConnectionConnectError));
      } else {
        map.put("ConnectionConnectErrorLastTime", null);
        map.put("ConnectionConnectErrorLastMessage", null);
        map.put("ConnectionConnectErrorLastStackTrace", null);
      }

      map.put("StatementCreateCount", stat.getStatementStat().getCreateCount());
      map.put("StatementPrepareCount", stat.getStatementStat().getPrepareCount());
      map.put("StatementPreCallCount", stat.getStatementStat().getPrepareCallCount());
      map.put("StatementExecuteCount", stat.getStatementStat().getExecuteCount());
      map.put("StatementRunningCount", stat.getStatementStat().getRunningCount());

      map.put("StatementConcurrentMax", stat.getStatementStat().getConcurrentMax());
      map.put("StatementCloseCount", stat.getStatementStat().getCloseCount());
      map.put("StatementErrorCount", stat.getStatementStat().getErrorCount());
      Throwable lastStatementError = stat.getStatementStat().getLastException();
      if (lastStatementError != null) {
        map.put("StatementLastErrorTime", stat.getStatementStat().getLastErrorTime());
        map.put("StatementLastErrorMessage", lastStatementError.getMessage());

        map.put("StatementLastErrorStackTrace", Utils.getStackTrace(lastStatementError));
      } else {
        map.put("StatementLastErrorTime", null);
        map.put("StatementLastErrorMessage", null);

        map.put("StatementLastErrorStackTrace", null);
      }
      map.put("StatementExecuteMillisTotal", stat.getStatementStat().getMillisTotal());
      map.put("StatementExecuteLastTime", stat.getStatementStat().getExecuteLastTime());
      map.put("ConnectionConnectingCount", stat.getConnectionStat().getConnectingCount());
      map.put("ResultSetCloseCount", stat.getResultSetStat().getCloseCount());

      map.put("ResultSetOpenCount", stat.getResultSetStat().getOpenCount());
      map.put("ResultSetOpenningCount", stat.getResultSetStat().getOpeningCount());
      map.put("ResultSetOpenningMax", stat.getResultSetStat().getOpeningMax());
      map.put("ResultSetFetchRowCount", stat.getResultSetStat().getFetchRowCount());
      map.put("ResultSetLastOpenTime", stat.getResultSetStat().getLastOpenTime());

      map.put("ResultSetErrorCount", stat.getResultSetStat().getErrorCount());
      map.put("ResultSetOpenningMillisTotal", stat.getResultSetStat().getAliveMillisTotal());
      map.put("ResultSetLastErrorTime", stat.getResultSetStat().getLastErrorTime());
      Throwable lastResultSetError = stat.getResultSetStat().getLastError();
      if (lastResultSetError != null) {
        map.put("ResultSetLastErrorMessage", lastResultSetError.getMessage());
        map.put("ResultSetLastErrorStackTrace", Utils.getStackTrace(lastResultSetError));
      } else {
        map.put("ResultSetLastErrorMessage", null);
        map.put("ResultSetLastErrorStackTrace", null);
      }

      map.put("ConnectionConnectCount", stat.getConnectionStat().getConnectCount());
      Throwable lastConnectionError = stat.getConnectionStat().getErrorLast();
      if (lastConnectionError != null) {
        map.put("ConnectionErrorLastMessage", lastConnectionError.getMessage());
        map.put("ConnectionErrorLastStackTrace", Utils.getStackTrace(lastConnectionError));
      } else {
        map.put("ConnectionErrorLastMessage", null);
        map.put("ConnectionErrorLastStackTrace", null);
      }
      map.put("ConnectionConnectMillisTotal", stat.getConnectionStat().getConnectMillis());
      map.put("ConnectionConnectingCountMax", stat.getConnectionStat().getConnectingMax());

      map.put("ConnectionConnectMillisMax", stat.getConnectionStat().getConnectMillisMax());
      map.put("ConnectionErrorLastTime", stat.getConnectionStat().getErrorLastTime());
      map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
      map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());

      map.put("ConnectionHistogram", stat.getConnectionHistogramValues());
      map.put("StatementHistogram", stat.getStatementStat().getHistogramValues());
    } else {
      map.put("ConnectionActiveCount", null);
      map.put("ConnectionActiveCountMax", null);
      map.put("ConnectionCloseCount", null);
      map.put("ConnectionCommitCount", null);
      map.put("ConnectionRollbackCount", null);

      map.put("ConnectionConnectLastTime", null);
      map.put("ConnectionConnectErrorCount", null);
      map.put("ConnectionConnectErrorLastTime", null);
      map.put("ConnectionConnectErrorLastMessage", null);
      map.put("ConnectionConnectErrorLastStackTrace", null);

      map.put("StatementCreateCount", null);
      map.put("StatementPrepareCount", null);
      map.put("StatementPreCallCount", null);
      map.put("StatementExecuteCount", null);
      map.put("StatementRunningCount", null);

      map.put("StatementConcurrentMax", null);
      map.put("StatementCloseCount", null);
      map.put("StatementErrorCount", null);
      map.put("StatementLastErrorTime", null);
      map.put("StatementLastErrorMessage", null);

      map.put("StatementLastErrorStackTrace", null);
      map.put("StatementExecuteMillisTotal", null);
      map.put("ConnectionConnectingCount", null);
      map.put("StatementExecuteLastTime", null);
      map.put("ResultSetCloseCount", null);

      map.put("ResultSetOpenCount", null);
      map.put("ResultSetOpenningCount", null);
      map.put("ResultSetOpenningMax", null);
      map.put("ResultSetFetchRowCount", null);
      map.put("ResultSetLastOpenTime", null);

      map.put("ResultSetErrorCount", null);
      map.put("ResultSetOpenningMillisTotal", null);
      map.put("ResultSetLastErrorTime", null);
      map.put("ResultSetLastErrorMessage", null);
      map.put("ResultSetLastErrorStackTrace", null);

      map.put("ConnectionConnectCount", null);
      map.put("ConnectionErrorLastMessage", null);
      map.put("ConnectionErrorLastStackTrace", null);
      map.put("ConnectionConnectMillisTotal", null);
      map.put("ConnectionConnectingCountMax", null);

      map.put("ConnectionConnectMillisMax", null);
      map.put("ConnectionErrorLastTime", null);
      map.put("ConnectionAliveMillisMax", null);
      map.put("ConnectionAliveMillisMin", null);

      map.put("ConnectionHistogram", new long[0]);
      map.put("StatementHistogram", new long[0]);
    }

    return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
  }
Exemplo n.º 6
0
  protected void tearDown() throws Exception {
    dataSource.close();
    Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());

    JdbcStatManager.getInstance().setStatContext(null);
  }
Exemplo n.º 7
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());
  }