I think I got this working right by. I removed the override of setUpInternal()
and added this much more straightforward code...
public void testLifeCycleDoubleUnwrap() {
try {
// Use startup SQL when connecting so the connection is
// doubly wrapped (adding LifeCycleConnection).
// That tests ability of OracleDialect to unwrap properly.
Properties addStartupSql = (Properties) fixture.clone();
addStartupSql.setProperty(JDBCDataStoreFactory.SQL_ON_BORROW.key,
"select sysdate from dual");
HashMap params = createDataStoreFactoryParams();
params.putAll(addStartupSql);
DataStore withWrap = (JDBCDataStore)
DataStoreFinder.getDataStore(params);
withWrap.dispose();
} catch (Exception e) {
throw new RuntimeException("Connection unwrap test failed!", e);
}
}
That code makes the test fail without my fix to OracleDialect applied.
So I'm prone to check this in along with my OracleDialect change and create (my
first) pull-request.
Does that make sense?
Thanks - Walter
From: Walter Stovall
Sent: Thursday, October 08, 2015 4:07 PM
To: [email protected]
Subject: Re: [Geotools-devel] My test case cannot reveal the bug I'm fixing
without altering the setup - is this a reasonable way?
I think I see this is not the way to do it. Suggestions are welcome.
From: Walter Stovall
Sent: Thursday, October 08, 2015 3:18 PM
To:
[email protected]<mailto:[email protected]>
Subject: [Geotools-devel] My test case cannot reveal the bug I'm fixing without
altering the setup - is this a reasonable way?
I'm building a test case that will reveal the bug
(https://osgeo-org.atlassian.net/browse/GEOT-5239) I've developed a fix for.
The bug can be distilled to the simple fact that you can't create a
JDBCDataStore for which you have startup-sql configured when using an Oracle
database. If you do, the Connection will get doubly wrapped while the
DataStore is being created and then the OracleDialect.unwrap() fail with an
exception.
I'm in the process of adding code to JDBCConnectionLifecycleOnlineTest to
expose this bug without my fix for it present. But that's difficult to do by
just adding a new public member to do my test. The bug does not occur unless
the connection gets doubly wrapped by adding a LifeCycleConnection as the
DataStore is being setup in this JDBCDataStore code:
if(connectionLifecycleListeners.size() > 0) {
List<ConnectionLifecycleListener> locals = new
ArrayList<ConnectionLifecycleListener>(connectionLifecycleListeners);
cx = new LifecycleConnection(this, cx, locals);
}
Since the above executes when a test case is being setup, I'm sort of past the
point of being able to reveal the bug when my test case actually starts
executing - the connection is not doubly wrapped, so the OracleDialect.unwrap()
will not fail.
So what I've done is to add this code to JDBCConnectionLifecycleOnlineTest:
protected void setUpInternal() throws Exception {
if (getName().equals("testLifeCycleDoubleUnwrap")) {
fixture.setProperty(JDBCDataStoreFactory.SQL_ON_BORROW.key, "select
sysdate from dual");
}
}
public void testLifeCycleDoubleUnwrap() {
}
This overrides setupInternal to test for a setup of my new test case. If my
new case is what's executing this adds startup-sql that will carry forward into
the Map that sets up the data store. That alone will cause OracleDialect to
fail while the DataStore is still being created. So for the case where my fix
has not been applied, the setup (not the actual test itself) is what fails with
this exception:
WARNING: Oracle NG should be used, but could not connect
java.io.IOException: Unable to obtain Oracle Connection require for SDO
Geometry access).Check connection pool implementation to unsure unwrap is
available
at
org.geotools.data.oracle.OracleNGDataStoreFactory.createDataStoreInternal(OracleNGDataStoreFactory.java:149)
at
org.geotools.jdbc.JDBCDataStoreFactory.createDataStore(JDBCDataStoreFactory.java:269)
at
org.geotools.jdbc.JDBCDataStoreFactory.createDataStore(JDBCDataStoreFactory.java:1)
at
org.geotools.data.DataAccessFinder.getDataStore(DataAccessFinder.java:130)
at
org.geotools.data.DataStoreFinder.getDataStore(DataStoreFinder.java:89)
at org.geotools.jdbc.JDBCTestSupport.connect(JDBCTestSupport.java:139)
at
org.geotools.jdbc.JDBCConnectionLifecycleOnlineTest.connect(JDBCConnectionLifecycleOnlineTest.java:44)
at org.geotools.test.OnlineTestCase.setUp(OnlineTestCase.java:243)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at org.geotools.test.OnlineTestCase.run(OnlineTestCase.java:123)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: Could not obtain native oracle connection for
class org.geotools.jdbc.LifecycleConnection
at
org.geotools.data.oracle.OracleDialect.unwrapConnection(OracleDialect.java:655)
at
org.geotools.data.oracle.OracleNGDataStoreFactory.createDataStoreInternal(OracleNGDataStoreFactory.java:147)
... 22 more
OK way to arrange the test? The exception won't happen with my fix to
OracleDialect applied.
Thanks - Walter
------------------------------------------------------------------------------
_______________________________________________
GeoTools-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel