4

junitでユニットテストを行っているplay 2.1アプリがあります。テストは正常に実行されており、データベース操作を実行できます。明らかにドライバー ( org.postgresql.Driver) がロードされています。

ただし、テストの合間に、接続プールがドライバーへのアクセスに問題を抱えているようです。以下は、私のログからの典型的なシーケンスの抜粋です。アプリケーションが問題ないのに、接続プールがドライバにアクセスできない理由を知っている人はいますか?

[info] application - QuickWitness Server shutdown...
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08001
[error] c.j.b.PoolWatchThread - Error in trying to obtain a connection. Retrying in 1000ms
java.sql.SQLException: No suitable driver found for jdbc:postgresql:qw
        at java.sql.DriverManager.getConnection(DriverManager.java:602) ~[na:1.6.0_26]
        at java.sql.DriverManager.getConnection(DriverManager.java:185) ~[na:1.6.0_26]
        at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256) ~[bonecp.jar:0.7.1.RELEASE]
        at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:211) ~[bonecp.jar:0.7.1.RELEASE]
        at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170) ~[bonecp.jar:0.7.1.RELEASE]
        at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:101) [bonecp.jar:0.7.1.RELEASE]
[info] application - QuickWitness Server has started
[debug] application - entering ensureTriggersAndStoredProceduresAreInstalled()
[debug] application - exiting ensureTriggersAndStoredProceduresAreInstalled()
[info] application - logging initialized
[info] application - Register user request from localhost:12345
[info] application - QuickWitness Server shutdown...
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08001
[error] c.j.b.PoolWatchThread - Error in trying to obtain a connection. Retrying in 1000ms
java.sql.SQLException: No suitable driver found for jdbc:postgresql:qw
        at java.sql.DriverManager.getConnection(DriverManager.java:602) ~[na:1.6.0_26]
        at java.sql.DriverManager.getConnection(DriverManager.java:185) ~[na:1.6.0_26]
        at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256) ~[bonecp.jar:0.7.1.RELEASE]
        at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:211) ~[bonecp.jar:0.7.1.RELEASE]
        at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170) ~[bonecp.jar:0.7.1.RELEASE]
        at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:101) [bonecp.jar:0.7.1.RELEASE]
[info] application - QuickWitness Server has started
4

3 に答える 3

1

私も同じ問題を抱えていました。私の場合、データベース接続が不十分なために問題が発生しました。プレイはブロックの終わりで接続を閉じないようです。ドキュメントには別の話がありますが、おそらくそれは遊びの誤りですか?

解決策1:( http://www.playframework.com/documentation/2.1.0/SettingsJDBC)を変更することで、application.confの接続を増やすことができます。

db.default.partitionCount=2
db.default.maxConnectionsPerPartition=5
db.default.minConnectionsPerPartition=5

解決策2:使用後に接続を閉じることができます(http://www.playframework.com/documentation/2.0/ScalaDatabase

DB.withConnection { conn =>   
  // do whatever you need with the connection   
  conn.close()
}
于 2013-03-15T13:31:53.863 に答える
0

スクエリルでも同じ問題がありました。私のコードに問題はないようです。これが起こると思います: 単体テストのために、アプリケーションが何度も連続して開始および停止されます。アプリケーションを停止すると、Play は接続を閉じます。ただし、マシンが十分に高速な場合は、アプリの起動時に、前回の実行で使用された接続が閉じられる前に、新しい接続を要求できます。それは単にタイミングの問題です。データベース接続の最大数を増やすか、グローバルの onStop の最後に短時間スリープするだけで解決できます。

于 2013-07-25T15:01:24.637 に答える