org.apache.derbyTesting.functionTests.tests.jdbcapi
Class AutoloadTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.AutoloadTest
All Implemented Interfaces:
junit.framework.Test

public class AutoloadTest
extends BaseJDBCTestCase

This JUnit test verifies the autoloading of the jdbc driver. A driver may be autoloaded due to JDBC 4 autoloading from jar files or the driver's name is listed in the system property jdbc.drivers when DriverManager is first loaded. This test must be run in its own VM because we want to verify that the driver was not accidentally loaded by some other test.


Field Summary
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
AutoloadTest(java.lang.String name)
           
 
Method Summary
private static junit.framework.Test baseAutoLoadSuite(java.lang.String which)
          Return the ordered set of tests when autoloading is enabled.
private  void explicitLoad(boolean instanceOnly)
           
private  boolean fullEngineAutoBoot()
          Return true if a full auto-boot of the engine is expected due to jdbc.drivers containing the name of the embedded driver.
private  boolean hasDerbyThreadGroup()
          Return true if a ThreadGroup exists that has a name starting with 'derby.'.
private  boolean isEmbeddedDriverRegistered()
          Return true if there appears to be a Derby embedded driver registered with the DriverManager.
 void noloadTestNodriverLoaded()
          Simple test when auto-loading is not expected.
static junit.framework.Test suite()
          Only run a test if the driver will be auto-loaded.
 void testAutoNetworkServerBoot()
          Test that the auto-load of the network server is as expected.
 void testEmbeddedNotStarted()
          Test indirect artifiacts through public apis that the embedded engine has not been started.
 void testEmbeddedStarted()
          Check the test(s) we use to determine if the embedded driver is not up indicate the opposite once the driver has been fully booted.
 void testExplicitLoad()
          Test an explict load of the driver works as well even though the drivers were loaded automatically.
 void testExplicitReload()
          Test that an explicit reload of the driver works, typically after a shutdown.
 void testRegisteredDriver()
           
 void testShutdownDeRegister()
          Test that after a shutdown that no Derby embedded driver is left registered in the DriverManager.
 void testSuccessfulConnect()
          Test we can connect successfully to a database.
 void testUnsuccessfulConnect()
          Test the error code on an unsuccessful connect to ensure it is not one returned by DriverManager.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AutoloadTest

public AutoloadTest(java.lang.String name)
Method Detail

suite

public static junit.framework.Test suite()
Only run a test if the driver will be auto-loaded. See class desciption for details.


baseAutoLoadSuite

private static junit.framework.Test baseAutoLoadSuite(java.lang.String which)
Return the ordered set of tests when autoloading is enabled.


testRegisteredDriver

public void testRegisteredDriver()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

testShutdownDeRegister

public void testShutdownDeRegister()
                            throws java.sql.SQLException
Test that after a shutdown that no Derby embedded driver is left registered in the DriverManager. See DERBY-2905.

Throws:
java.sql.SQLException - failure

isEmbeddedDriverRegistered

private boolean isEmbeddedDriverRegistered()
Return true if there appears to be a Derby embedded driver registered with the DriverManager.

Returns:
true if there appears to be a Derby embedded driver registered

testSuccessfulConnect

public void testSuccessfulConnect()
                           throws java.sql.SQLException
Test we can connect successfully to a database.

Throws:
java.sql.SQLException

testUnsuccessfulConnect

public void testUnsuccessfulConnect()
                             throws java.sql.SQLException
Test the error code on an unsuccessful connect to ensure it is not one returned by DriverManager.

Throws:
java.sql.SQLException

testExplicitLoad

public void testExplicitLoad()
                      throws java.lang.Exception
Test an explict load of the driver works as well even though the drivers were loaded automatically.

Throws:
java.lang.Exception

testExplicitReload

public void testExplicitReload()
                        throws java.lang.Exception
Test that an explicit reload of the driver works, typically after a shutdown. Note that just loading the driver class here cannot reload the driver as the driver class is already loaded and thus its static initializer will not be re-executed.

Throws:
java.lang.Exception

explicitLoad

private void explicitLoad(boolean instanceOnly)
                   throws java.lang.Exception
Throws:
java.lang.Exception

noloadTestNodriverLoaded

public void noloadTestNodriverLoaded()
Simple test when auto-loading is not expected. This is to basically test that the junit setup code itself does not load the driver, thus defeating the real auto-loading testing.


testAutoNetworkServerBoot

public void testAutoNetworkServerBoot()
                               throws java.lang.Exception
Test that the auto-load of the network server is as expected.

derby.drda.startNetworkServer=false or not set
network server should not auto boot.

derby.drda.startNetworkServer=true
If jdbc.drivers contains the name of the embedded driver then the server must be booted.
Otherwise even if auto-loading the embedded driver due to JDBC 4 auto-loading the network server must not boot. This is because the auto-loaded driver for JDBC 4 is a proxy driver that registers a driver but does not boot the complete embedded engine.

Throws:
java.lang.Exception

fullEngineAutoBoot

private boolean fullEngineAutoBoot()
Return true if a full auto-boot of the engine is expected due to jdbc.drivers containing the name of the embedded driver.


testEmbeddedNotStarted

public void testEmbeddedNotStarted()
Test indirect artifiacts through public apis that the embedded engine has not been started.


testEmbeddedStarted

public void testEmbeddedStarted()
Check the test(s) we use to determine if the embedded driver is not up indicate the opposite once the driver has been fully booted.


hasDerbyThreadGroup

private boolean hasDerbyThreadGroup()
Return true if a ThreadGroup exists that has a name starting with 'derby.'. This needs to run without a security manager as it requires permissions to see all active thread groups. Since this not testing Derby functionality there's harm to not having a security manager, since no code is executed against Derby.


Built on Wed 2009-11-25 18:43:31-0800, from revision 884373

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.