Skip to content

Conversation

@oleosterhagen
Copy link

This PR is a partial fix of JCR-4521. The request for more customization possibilities is not addressed here. Most of the changes are identical to the patch (JCR-4521.diff) from @reschke.

During the execution of the test suite the Derby database will be shut down several times. The associated database connections remain in the pool but are no longer valid and lead to test errors. I have discovered two options to fix the tests:

  1. Activate testOnBorrow and execute a validation query. With Commons DBCP 1.x this is not needed for the tests (see 2).
  2. Deactivate cacheState. If the caching of the readOnly and autoCommit settings is deactivated, these will be reset when returning a connection from the pool. During this operation the invalid connections will be discovered and thrown away. I have chosen this option in the implementation, because it corresponds to the behavior when using Commons DBCP 1.x. (The validation query in option 1 may have different runtime characteristics.)

These options don't work:

  1. Close the pool after a database shut-down: The data source (i.e. the pool) is cached in the class ConnectionFactory and may still be reused. Without reopening the pool this will not work.
  2. Restart (atomically close and reopen) the pool after a database shut-down: When the new pool is created a new connection is created to validate the pool. This starts the database again. But this database instance will soon get corrupted and unusable when its files in the file system are deleted during set up of the next test case. So the database has to stay shut-down until its files have been removed.

The caching of the readOnly and autoCommit settings is deactivated in
order to detect invalid connections from a shut-down Derby database.
This corresponds to the behavior in Commons DBCP 1.x.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant