-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrades Oracle database libraries to version 21.9.0.0. Adds tests un…
…der datasource-ucp CDI integration. (#8221) Upgrades Oracle database libraries to version 21.9.0.0. Adds test under datasource-ucp CDI integration. Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
- Loading branch information
Showing
11 changed files
with
222 additions
and
19 deletions.
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
72 changes: 72 additions & 0 deletions
72
...datasource-ucp/src/test/java/io/helidon/integrations/datasource/ucp/cdi/TestUcpAndH2.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,72 @@ | ||
/* | ||
* 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.UniversalConnectionPoolException; | ||
import oracle.ucp.admin.UniversalConnectionPoolManager; | ||
import oracle.ucp.admin.UniversalConnectionPoolManagerImpl; | ||
import oracle.ucp.jdbc.PoolDataSource; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static oracle.ucp.jdbc.PoolDataSourceFactory.getPoolDataSource; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class TestUcpAndH2 { | ||
|
||
TestUcpAndH2() { | ||
super(); | ||
} | ||
|
||
@AfterEach | ||
void destroyPools() throws SQLException, UniversalConnectionPoolException { | ||
UniversalConnectionPoolManager ucpManager = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager(); | ||
for (String n : ucpManager.getConnectionPoolNames()) { | ||
ucpManager.destroyConnectionPool(n); | ||
} | ||
} | ||
|
||
/** | ||
* Ensures we don't accidentally upgrade to a version of the Universal Connection Pool that throws {@link | ||
* NullPointerException}s when no {@code serviceName} is set on a {@link PoolDataSource}. | ||
* | ||
* <p>The only way to set a service name on a {@link PoolDataSource} is, when the {@link PoolDataSource} is actually | ||
* a {@link PoolDataSourceImpl}, by invoking its {@code private void setServiceName(String)} method via | ||
* reflection.</p> | ||
* | ||
* @exception SQLException if a database access error occurs | ||
* | ||
* @exception NullPointerException if the Universal Connection Pool version in effect cannot handle unset service | ||
* names | ||
*/ | ||
@Test | ||
void testUcpAndH2Canary() throws SQLException { | ||
PoolDataSource pds = getPoolDataSource(); | ||
pds.setConnectionFactoryClassName("org.h2.jdbcx.JdbcDataSource"); | ||
pds.setURL("jdbc:h2:mem:test"); | ||
pds.setUser("sa"); | ||
pds.setPassword(""); | ||
try (Connection c = pds.getConnection()) { // Throws NullPointerException in versions 21.10.0.0 and 21.11.0.0 and possibly others | ||
assertThat(c, not(nullValue())); | ||
} | ||
} | ||
|
||
} |
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