2017-06-16 5 views
0

私はHikariCP2.6.1で作業しています。HikariPool PoolInitializationException @Testメソッドが追加されたとき

MySQLJUnit 4.xを安心して使用しています。ちょうど今日、私は新しい@Testメソッドを追加しましたが、テストは失敗します。私がをこの新しい@Testに当てはめると、もちろんすべてが再び機能します。 @Ignoreを他の先に置き換えた場合@Testにはが渡され、この新しい@Testにはすべて@Ignoreが削除されます。

そこでDB接続は次の例外が発生する作品以上が必要です。この新しい@Test方法の追加:

Caused by: org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [javax.sql.DataSource]: 
Factory method 'dataSource' threw exception; 
nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: 
Failed to initialize pool: Could not create connection to database server. Attempted reconnect 3 times. Giving up. 
    a 
... 
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: 
Failed to initialize pool: Could not create connection to database server. Attempted reconnect 3 times. Giving up. 
    a 
... 
Caused by: java.sql.SQLNonTransientConnectionException: 
Could not create connection to database server. 
Attempted reconnect 3 times. Giving up. 
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:526) 
... 
Caused by: java.lang.ArrayIndexOutOfBoundsException: 24 
    at com.mysql.cj.mysqla.io.Buffer.readInteger(Buffer.java:271) 

私の現在の設定は次のとおりです。

@Bean(destroyMethod = "close") 
public DataSource dataSource() throws SQLException { 

    HikariConfig hc = new HikariConfig(); 

    hc.setDriverClassName(environment.getProperty("mysql.driverClass")); 
    hc.setJdbcUrl(environment.getProperty("mysql.jdbcUrl")); 
    hc.setUsername(environment.getProperty("mysql.user")); 
    hc.setPassword(environment.getProperty("mysql.password")); 

    hc.setPoolName(environment.getProperty("hikaricp.poolName")); 

    hc.addDataSourceProperty("databaseName", environment.getProperty("hikaricp.databaseName")); 
    hc.addDataSourceProperty("cachePrepStmts", environment.getProperty("hikaricp.cachePrepStmts")); 
    hc.addDataSourceProperty("prepStmtCacheSize", environment.getProperty("hikaricp.prepStmtCacheSize")); 
    hc.addDataSourceProperty("prepStmtCacheSqlLimit", environment.getProperty("hikaricp.prepStmtCacheSqlLimit")); 
    hc.addDataSourceProperty("useServerPrepStmts", environment.getProperty("hikaricp.useServerPrepStmts")); 

    HikariDataSource hds = new HikariDataSource(hc); 

    return hds; 
} 

そして

hikaricp.poolName = "hikaricp-channels-pool" 
hikaricp.databaseName = batch 
hikaricp.cachePrepStmts = true 
hikaricp.prepStmtCacheSize = 250 
hikaricp.prepStmtCacheSqlLimit = 2048 
hikaricp.useServerPrepStmts = true 

mysql.user = root 
mysql.password = somepassword 
mysql.driverClass = com.mysql.cj.jdbc.Driver 
mysql.jdbcUrl = jdbc:mysql://localhost:3306/batch?autoReconnect=true&useSSL=false 

追加の設定にはどのようなものが必要ですか?

アルファ

版01

  • から:mysql.jdbcUrl = jdbc:mysql://localhost:3306/batch?autoReconnect=true&useSSL=false
  • へ:mysql.jdbcUrl = jdbc:mysql://localhost:3306/batch?useSSL=false

版02

  • を追加しました:hc.addDataSourceProperty("maximumPoolSize", 2);DEBUGレポートについて

111483 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none 
111483 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>, prepStmtCacheSqlLimit=2048, databaseName=batch, cachePrepStmts=true, useServerPrepStmts=true, maximumPoolSize=2, prepStmtCacheSize=250} 
111483 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."com.mysql.cj.jdbc.Driver" 
111483 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{} 
111484 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none 
111484 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000 
111484 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailFast..........true 
111485 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1 
111485 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false 
111485 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false 
111485 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl........................."jdbc:mysql://localhost:3306/batch?useSSL=false" 
111486 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0 
111486 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000 
111486 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10 
111486 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none 
111486 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none 
111487 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10 
111487 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked> 
111487 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................""hikaricp-channels-pool"" 
111487 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false 
111487 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false 
111488 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none 
111488 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutorService........internal 
111488 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal 
111488 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default 
111488 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - username........................"root" 
111488 [Test worker] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000 

私は実現しなかった以上のことから、私のhc.addDataSourceProperty("maximumPoolSize", 2)

dataSourceProperties............{ 
    password=<masked>, 
    prepStmtCacheSqlLimit=2048, 
    databaseName=batch, 
    cachePrepStmts=true, 
    useServerPrepStmts=true, 
    maximumPoolSize=2, <------ 
    prepStmtCacheSize=250} 

maximumPoolSize.................10

に反映されています上に示した二つの出力の途中に配置されている

Pool stats (total=1, active=0, idle=1, waiting=0)

long値:

ログ出力は

111488 [Test worker] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Starting... 
111495 [Test worker] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - Added connection [email protected] 
111495 [Test worker] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Start completed. 
111595 ["hikaricp-channels-pool" housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - Pool stats (total=10, active=0, idle=10, waiting=0) 
111598 ["hikaricp-channels-pool" connection adder] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - Added connection [email protected] 
111606 ["hikaricp-channels-pool" connection adder] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Failed to create/setup connection: Could not create connection to database server. 
111607 ["hikaricp-channels-pool" connection adder] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - Cannot acquire connection from data source 
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. 
... 
Caused by: java.lang.ArrayIndexOutOfBoundsException: 24 
    at com.mysql.cj.mysqla.io.Buffer.readInteger(Buffer.java:271) 
    at com.mysql.cj.mysqla.io.MysqlaCapabilities.setInitialHandshakePacket(MysqlaCapabilities.java:62) 

を用いて他の場所の他の同様のエラーメッセージに表示されるこのエラースタックトレースと、以下ファイル.logちょうど底に、次のように何度も現れます。

119835 [Thread-7] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
119824 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119828 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119836 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119829 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119829 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119838 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119839 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119839 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119839 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119839 [Thread-5] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
119839 [Thread-5] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
119832 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119835 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119840 [Thread-17] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
119841 [Thread-17] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
119841 [Thread-6] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
119841 [Thread-6] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
119840 [Thread-16] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
119843 [Thread-16] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
119840 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119841 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119845 ["hikaricp-channels-pool" connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - "hikaricp-channels-pool" - Closing connection [email protected]: (connection evicted) 
119845 [Thread-15] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
119846 [Thread-15] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
119846 [Thread-10] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
119846 [Thread-10] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 
123927 [Thread-19] DEBUG com.zaxxer.hikari.pool.HikariPool - "hikaricp-channels-pool" - After shutdown stats (total=0, active=0, idle=0, waiting=0) 
123928 [Thread-19] INFO com.zaxxer.hikari.HikariDataSource - "hikaricp-channels-pool" - Shutdown completed. 

は今だけ変更:

//hc.addDataSourceProperty("maximumPoolSize", 2); 
    hc.setMaximumPoolSize(2); 

すべてが今渡します。

この経験から、現在のドキュメントを改善するための提案をGitHubを通していくつかの「問題」を生じさせます。

答えて

1

私はあなたが間違いなく望んでいないと思います自動返信。また、テストの場合は、おそらくプールサイズが10である必要はありません.1または2を試してください。また、com.zaxxer.hikariのDEBUGロギングを有効にして、プールがテスト間で適切にシャットダウンされていることを確認してください。

+0

「アルファ」セクションが追加されました。ちょうど興味があり、なぜ「2」で動作し、「10」で失敗するのか混乱します。 –

関連する問題