org.apache.derbyTesting.functionTests.tests.memorydb
Class BasicInMemoryDbTest

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.memorydb.BasicInMemoryDbTest
All Implemented Interfaces:
junit.framework.Test

public class BasicInMemoryDbTest
extends BaseJDBCTestCase

Basic tests of the in-memory db storage back end.


Field Summary
private static MemoryDbManager dbm
          Helper for dealing with memory databases.
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
BasicInMemoryDbTest(java.lang.String name)
           
 
Method Summary
static java.lang.String getString(int length, CharAlphabet alphabet)
          Generates a string.
static junit.framework.Test suite()
           
 void tearDown()
          Closes all opened statements and connections that are known, and also deletes all known in-memory databases.
 void testBootSameDbDifferentSubSubProtocol()
          Verify that booting two databases with the same name but with different subsubprotocols doesn't result in two connections to the same database.
 void testCreateBackupBootRestore()
          Performs a cycle to test that the in-memory db is compatible with the deafult directory protocol.
 void testDelete()
          Test deletion of an in-memory database: - create database - delete database - try to connection to database, should fail - recreate and delete again
 void testDeleteWhenInUse()
          Deletes the database when in use by a different connection.
 void testEnginehutdown()
          Makes sure shutting down the Derby engine with an in-memory database already booted works.
 void testFunctionalityPresent()
          Tries to connect to a non-existing database with the in-memory protocol, expecting an error saying the database doesn't exist.
 void testShutdown()
          Makes sure shutting down an in-memory database works.
 void testShutdownWhenInUse()
          Shuts down the database when in use by a different connection.
 
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, 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
 

Field Detail

dbm

private static final MemoryDbManager dbm
Helper for dealing with memory databases. For now we use a single instance for all test classes / cases, as the tests are run single threaded.

Constructor Detail

BasicInMemoryDbTest

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

tearDown

public void tearDown()
              throws java.lang.Exception
Closes all opened statements and connections that are known, and also deletes all known in-memory databases.

Overrides:
tearDown in class BaseJDBCTestCase
Throws:
java.lang.Exception - if something goes wrong

testFunctionalityPresent

public void testFunctionalityPresent()
Tries to connect to a non-existing database with the in-memory protocol, expecting an error saying the database doesn't exist.


testCreateBackupBootRestore

public void testCreateBackupBootRestore()
                                 throws java.io.IOException,
                                        java.sql.SQLException
Performs a cycle to test that the in-memory db is compatible with the deafult directory protocol.

  1. Create an in-memory db and add a table with a few rows.
  2. Backup to disk.
  3. Boot the database with the directory (default) protocol.
  4. Verify content, add a new row, shutdown.
  5. Use createFrom to restore database from disk into the in-memory representation.
  6. Verify new content.

Throws:
java.io.IOException - if something goes wrong
java.sql.SQLException - if something goes wrong

testShutdown

public void testShutdown()
                  throws java.sql.SQLException
Makes sure shutting down an in-memory database works.

Throws:
java.sql.SQLException - if something goes wrong

testEnginehutdown

public void testEnginehutdown()
                       throws java.sql.SQLException
Makes sure shutting down the Derby engine with an in-memory database already booted works.

Related to DERBY-4093

Throws:
java.sql.SQLException - if something goes wrong

testBootSameDbDifferentSubSubProtocol

public void testBootSameDbDifferentSubSubProtocol()
                                           throws java.sql.SQLException
Verify that booting two databases with the same name but with different subsubprotocols doesn't result in two connections to the same database.

Throws:
java.sql.SQLException - if something goes wrong

testDelete

public void testDelete()
                throws java.sql.SQLException
Test deletion of an in-memory database: - create database - delete database - try to connection to database, should fail - recreate and delete again

Throws:
java.sql.SQLException - if something else goes wrong

testDeleteWhenInUse

public void testDeleteWhenInUse()
                         throws java.io.IOException,
                                java.sql.SQLException
Deletes the database when in use by a different connection.

The expected outcome is that the first connection will be closed when the second one deletes the database.

Throws:
java.io.IOException - if something goes wrong
java.sql.SQLException - if something goes wrong

testShutdownWhenInUse

public void testShutdownWhenInUse()
                           throws java.io.IOException,
                                  java.sql.SQLException
Shuts down the database when in use by a different connection.

The expected outcome is that the first connection will be closed when the second one shuts down the database.

Throws:
java.io.IOException - if something goes wrong
java.sql.SQLException - if something goes wrong

suite

public static junit.framework.Test suite()

getString

public static java.lang.String getString(int length,
                                         CharAlphabet alphabet)
                                  throws java.io.IOException
Generates a string.

Parameters:
length - length of the string
alphabet - the alphabet to use for the content
Returns:
A string.
Throws:
java.io.IOException - if reading from the source stream fails

Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

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