You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by my...@apache.org on 2014/10/22 02:56:21 UTC

svn commit: r1633504 - in /db/derby/code/branches/10.10: ./ java/engine/org/apache/derby/catalog/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/

Author: myrnavl
Date: Wed Oct 22 00:56:21 2014
New Revision: 1633504

URL: http://svn.apache.org/r1633504
Log:
DERBY-6496; Optional tool registration may fail because the CompilerContext is not always available at execution time.
   backport of revision 1574752, revision 15749237 and revision 1574946 from trunk.

Added:
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java
      - copied, changed from r1574752, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java
Modified:
    db/derby/code/branches/10.10/   (props changed)
    db/derby/code/branches/10.10/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1574752,1574927,1574946

Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java?rev=1633504&r1=1633503&r2=1633504&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java Wed Oct 22 00:56:21 2014
@@ -23,7 +23,6 @@ package org.apache.derby.catalog;
 
 import java.sql.SQLException;
 
-import org.apache.derby.iapi.sql.compile.CompilerContext;
 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 import org.apache.derby.iapi.sql.dictionary.OptionalTool;
 import org.apache.derby.iapi.error.PublicAPI;
@@ -31,6 +30,7 @@ import org.apache.derby.iapi.error.Stand
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.context.ContextService;
 import org.apache.derby.iapi.services.loader.ClassFactory;
+import org.apache.derby.iapi.services.loader.ClassFactoryContext;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 /**
@@ -93,8 +93,8 @@ public  class   Java5SystemProcedures
         throws SQLException
     {
         try {
-			CompilerContext cc = (CompilerContext) ContextService.getContext( CompilerContext.CONTEXT_ID );
-            ClassFactory    classFactory = cc.getClassFactory();
+			ClassFactoryContext cfc = (ClassFactoryContext) ContextService.getContext( ClassFactoryContext.CONTEXT_ID );
+            ClassFactory    classFactory = cfc.getClassFactory();
 
             String              toolClassName = findToolClassName( toolName, optionalArgs );            
             OptionalTool    tool = null;

Copied: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java (from r1574752, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java)
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java?p2=db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java&r1=1574752&r2=1633504&rev=1633504&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Test_6496.java Wed Oct 22 00:56:21 2014
@@ -21,24 +21,10 @@
 
 package org.apache.derbyTesting.functionTests.tests.lang;
 
-import java.sql.SQLException;
-import java.sql.SQLWarning;
 import java.sql.Connection;
-import java.sql.Statement;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.DriverManager;
-import java.util.ArrayList;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.JDBC;
-import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
-import org.apache.derbyTesting.junit.JDBC;
-import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
-import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
-import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * <p>
@@ -54,10 +40,11 @@ public class Test_6496 extends Generated
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
-    private static  final   String      TEST_DBO = "TEST_DBO";
+    private static  final   String      LOAD_METADATA_TOOL = "call syscs_util.syscs_register_tool( 'databaseMetaData', true )";
+    private static  final   String      UNLOAD_METADATA_TOOL = "call syscs_util.syscs_register_tool( 'databaseMetaData', false )";
 
-    private static  final   String      LOAD_TOOL = "call syscs_util.syscs_register_tool( 'databaseMetaData', true )";
-    private static  final   String      UNLOAD_TOOL = "call syscs_util.syscs_register_tool( 'databaseMetaData', false )";
+    private static  final   String      LOAD_OPTIMIZER_TOOL = "call syscs_util.syscs_register_tool('optimizerTracing', true, 'custom', 'org.apache.derbyTesting.functionTests.tests.lang.DummyOptTrace')";
+    private static  final   String      UNLOAD_OPTIMIZER_TOOL = "call syscs_util.syscs_register_tool('optimizerTracing', false)";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -105,30 +92,24 @@ public class Test_6496 extends Generated
 
     /**
      * <p>
-     * Test baseline permissions where no grants are made.
+     * Test that we can load the metadata tool twice without popping an NPE.
      * </p>
      */
-    public  void    test_001()
+    public  void    test_001_metadata()
         throws Exception
     {
-        Connection  dboConnection = openUserConnection( TEST_DBO );
-
-        goodStatement( dboConnection, LOAD_TOOL );
-        goodStatement( dboConnection, UNLOAD_TOOL );
+        toolTester( LOAD_METADATA_TOOL, UNLOAD_METADATA_TOOL );
     }
 
     /**
      * <p>
-     * Test that a user can grant access to her indexes.
+     * Test that we can load the optimizer tool twice without popping an NPE.
      * </p>
      */
-    public  void    test_002()
+    public  void    test_002_optimizer()
         throws Exception
     {
-        Connection  dboConnection = openUserConnection( TEST_DBO );
-
-        goodStatement( dboConnection, LOAD_TOOL );
-        goodStatement( dboConnection, UNLOAD_TOOL );
+        toolTester( LOAD_OPTIMIZER_TOOL, UNLOAD_OPTIMIZER_TOOL );
     }
 
     ///////////////////////////////////////////////////////////////////////////////////
@@ -137,4 +118,18 @@ public class Test_6496 extends Generated
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
+    private void    toolTester( String loadTool, String unloadTool ) throws Exception
+    {
+        Connection c1 = openDefaultConnection();
+        goodStatement( c1, loadTool );
+        goodStatement( c1, unloadTool );
+
+        // Loading the tool a second time in a fresh connection, with the
+        // exact same statement text so that the compiled statement is found
+        // in the statement cache, used to result in a NullPointerException
+        // because there was no CompilerContext on the stack.
+        Connection c2 = openDefaultConnection();
+        goodStatement( c2, loadTool );
+        goodStatement( c2, unloadTool );
+    }
 }

Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=1633504&r1=1633503&r2=1633504&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Wed Oct 22 00:56:21 2014
@@ -205,6 +205,7 @@ public class _Suite extends BaseTestCase
         if (JDBC.vmSupportsJDBC4())  
         {
             suite.addTest(OptionalToolsTest.suite());
+            suite.addTest(Test_6496.suite());
         }
        
         suite.addTest(BigDataTest.suite());

Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml?rev=1633504&r1=1633503&r2=1633504&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml Wed Oct 22 00:56:21 2014
@@ -101,6 +101,7 @@
       <exclude name="${this.dir}/_Suite.java"/>
       <exclude name="${this.dir}/VarargsRoutines.java"/>
       <exclude name="${this.dir}/OptionalToolExample.java"/>
+      <exclude name="${this.dir}/Test_6496.java"/>
     </javac>
   </target>
   <target name="compilet2" depends="compilet1">
@@ -176,6 +177,7 @@
       <include name="${this.dir}/LobMode.java"/>
       <include name="${this.dir}/VarargsRoutines.java"/>
       <include name="${this.dir}/OptionalToolExample.java"/>
+      <include name="${this.dir}/Test_6496.java"/>
     </javac>
   </target>