-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrades Oracle database libraries to version 21.9.0.0. Adds tests under datasource-ucp CDI integration. #8221
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cddc6f4
Upgrades Oracle database libraries to version 21.9.0.0. Adds test und…
ljnelson ed0fba3
Squashable commit; uses ojdbc11 instead of ojdbc8 throughout the code…
ljnelson 7d28de4
Squashable commit; upgrades ojdbc version to 21.11.0.0
ljnelson 662a9e5
Squashable commit; upgrades the ojdbc/ucp version to 21.9.0.0 which i…
ljnelson 3bf8d6f
Squashable commit; style fix
ljnelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
.../java/io/helidon/integrations/datasource/ucp/cdi/TestUcpConnectionStateResetBehavior.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.integrations.datasource.ucp.cdi; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import oracle.ucp.jdbc.ConnectionInitializationCallback; | ||
import oracle.ucp.jdbc.PoolDataSource; | ||
import oracle.ucp.jdbc.PoolDataSourceFactory; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
/** | ||
* A test class that shows that the Universal Connection Pool does not reset connection state when a borrowed connection | ||
* is returned. | ||
*/ | ||
class TestUcpConnectionStateResetBehavior { | ||
|
||
private PoolDataSource pds; | ||
|
||
private TestUcpConnectionStateResetBehavior() { | ||
super(); | ||
} | ||
|
||
@BeforeEach | ||
void initializeDataSource() throws SQLException { | ||
this.pds = PoolDataSourceFactory.getPoolDataSource(); | ||
|
||
// We register this callback, knowing that UCP will ignore it, despite documentation that does not say so. It | ||
// ignores it because the connection factory (DataSource) we use is H2, not Oracle. In case UCP fixes this | ||
// shortcoming we want to know about it. | ||
this.pds.registerConnectionInitializationCallback(new FailingCallback()); | ||
assertThat(this.pds.getConnectionInitializationCallback(), is(instanceOf(FailingCallback.class))); | ||
|
||
this.pds.setConnectionFactoryClassName("org.h2.jdbcx.JdbcDataSource"); | ||
this.pds.setURL("jdbc:h2:mem:" + this.getClass().getSimpleName()); | ||
this.pds.setUser("sa"); | ||
this.pds.setPassword(""); | ||
|
||
this.pds.setInitialPoolSize(2); | ||
this.pds.setMinPoolSize(2); | ||
this.pds.setMaxPoolSize(8); // actually the default but just being explicit | ||
} | ||
|
||
@AfterEach | ||
void destroyDataSource() throws SQLException { | ||
this.pds.unregisterConnectionInitializationCallback(); | ||
} | ||
|
||
@Test | ||
void testUCPErroneouslyDoesNotResetConnectionStateOnReturn() throws SQLException { | ||
|
||
// The connection pool has two connections in it. | ||
|
||
// Borrow connection zero. | ||
Connection c0 = this.pds.getConnection(); | ||
assertThat(c0.getAutoCommit(), is(true)); // we never set it anywhere; default value is true | ||
|
||
// Borrow connection one. | ||
Connection c1 = this.pds.getConnection(); | ||
assertThat(c1.getAutoCommit(), is(true)); // we never set it anywhere; default value is true | ||
|
||
// There are now no more connections available in the pool. | ||
assertThat(this.pds.getAvailableConnectionsCount(), is(0)); | ||
|
||
// Change the state of connection one. | ||
c1.setAutoCommit(false); | ||
|
||
// Return it to the pool. | ||
c1.close(); | ||
|
||
// There is now exactly one connection available in the pool (the one we just returned). | ||
assertThat(this.pds.getAvailableConnectionsCount(), is(1)); | ||
|
||
// Borrow connection two. (It will be connection one.) | ||
Connection c2 = this.pds.getConnection(); | ||
|
||
// There are now no more connections available in the pool. | ||
assertThat(this.pds.getAvailableConnectionsCount(), is(0)); | ||
|
||
// Note that the state of connection two includes the state of connection one. Oops. The pool really should | ||
// reset at least this portion of the connection state, but it does not. | ||
assertThat(c2.getAutoCommit(), is(false)); | ||
|
||
// Return it. | ||
c2.close(); | ||
|
||
// Return connection zero. | ||
c0.close(); | ||
|
||
// No more borrowed connections are extant. | ||
assertThat(this.pds.getAvailableConnectionsCount(), is(2)); | ||
} | ||
|
||
private static class FailingCallback implements ConnectionInitializationCallback { | ||
|
||
private FailingCallback() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public void initialize(Connection connection) throws SQLException { | ||
// ConnectionInitializationCallbacks are ignored by the UCP unless you are using an Oracle JDBC driver. | ||
fail(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we keeping this property for backward compatibility or should we remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption has always been that if there is a property defined in a
pom.xml
somewhere that appears in the inheritance chain of, say,applications/mp/pom.xml
, which this one does, then it probably should obey the rules of semantic versioning, so should stick around, in this case, until Helidon 5. Maybe others have opinions.