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

Reply via email to