## org.h2.test
Class TestBase

    java.lang.Object
      org.h2.test.TestBase

Direct Known Subclasses:
  Test, TestAlter, TestAutoRecompile, TestAutoReconnect, TestAutoServer, TestBackup, TestBatchUpdates, TestBigDb, TestBigResult, TestBtreeIndex, TestCache, TestCallableStatement, TestCancel, TestCases, TestCheckpoint, TestClearReferences, TestCluster, TestCompatibility, TestCompress, TestConnectionInfo, TestConnectionPool, TestCrashAPI, TestCsv, TestDatabaseEventListener, TestDataPage, TestDataSource, TestDate, TestDateIso8601, TestDeadlock, TestDriver, TestEncryptedDb, TestExclusive, TestExit, TestFile, TestFileLock, TestFileLockSerialized, TestFileSystem, TestFtp, TestFullText, TestFunctionOverload, TestFunctions, TestFuzzOptimizations, TestHalt, TestIndex, TestInit, TestIntArray, TestIntIntHashMap, TestJoin, TestKill, TestKillRestart, TestKillRestartMulti, TestLargeBlob, TestLinkedTable, TestListener, TestLob, TestManyJdbcObjects, TestMathUtils, TestMemoryUsage, TestMetaData, TestMulti, TestMultiConn, TestMultiDimension, TestMultiThread, TestMultiThreaded, TestMultiThreadedKernel, TestMultiThreadedKernel, TestMvcc1, TestMvcc2, TestMvcc3, TestMvccMultiThreaded, TestNativeSQL, TestNestedLoop, TestNetUtils, TestOldVersion, TestOpenClose, TestOptimizations, TestOutOfMemory, TestOverflow, TestPageStore, TestPattern, TestPgServer, TestPowerOff, TestPowerOffFs, TestPowerOffFs2, TestPreparedStatement, TestRandomSQL, TestReader, TestReadOnly, TestRecoverKillLoop, TestRecovery, TestResultSet, TestRights, TestRowLocks, TestRunscript, TestSampleApps, TestScript, TestScriptReader, TestScriptSimple, TestSecurity, TestSequence, TestServlet, TestSessionsLocks, TestShell, TestSimpleIndex, TestSpaceReuse, TestSpeed, TestSQLInjection, TestStatement, TestStreams, TestStringCache, TestStringUtils, TestSynth, TestTableEngines, TestTempTables, TestThreads, TestTimer, TestTools, TestTransaction, TestTransactionIsolation, TestTriggersConstraints, TestTwoPhaseCommit, TestUpdatableResultSet, TestValue, TestValueHashMap, TestValueMemory, TestView, TestViewAlterTable, TestWeb, TestXA, TestXASimple, TestZloty

    public abstract class TestBase

extends java.lang.Object

The base class for all tests.

Field Summary
`protected static java.lang.String` `baseDir` The base directory to write test databases.
`TestAll` `config` The test configuration.
`protected long` `start` The time when the test was started.
`protected static java.lang.String` `TEMP_DIR` The temporary directory.
`protected static int` `uniqueId` An id used to create unique file names.

Constructor Summary
`TestBase()`

Method Summary
`protected void` `assertContains(java.lang.String result, java.lang.String contains)` Check that a result contains the given substring.
`protected void` `assertEqualDatabases(java.sql.Statement stat1, java.sql.Statement stat2)` Check if two databases contain the same met data.
`protected void` `assertEqualReaders(java.io.Reader expected, java.io.Reader actual, int len)` Check if two readers are equal, and if not throw an exception.
`protected void` `assertEquals(boolean expected, boolean actual)` Check if two values are equal, and if not throw an exception.
`void` `assertEquals(byte[] expected, byte[] actual)` Check if two values are equal, and if not throw an exception.
`protected void` `assertEquals(double expected, double actual)` Check if two values are equal, and if not throw an exception.
`protected void` `assertEquals(float expected, float actual)` Check if two values are equal, and if not throw an exception.
`protected void` `assertEquals(java.lang.Integer expected, java.lang.Integer actual)` Check if two values are equal, and if not throw an exception.
`void` `assertEquals(int expected, int actual)` Check if two values are equal, and if not throw an exception.
`protected void` `assertEquals(long expected, long actual)` Check if two values are equal, and if not throw an exception.
`void` `assertEquals(java.lang.String message, int expected, int actual)` Check if two values are equal, and if not throw an exception.
`protected void` `assertEquals(java.lang.String expected, java.lang.String actual)` Check if two values are equal, and if not throw an exception.
`protected void` `assertEqualStreams(java.io.InputStream expected, java.io.InputStream actual, int len)` Check if two streams are equal, and if not throw an exception.
`protected void` `assertFalse(boolean value)` Check that the passed boolean is false.
`protected void` `assertFalse(java.lang.String message, boolean value)` Check that the passed boolean is false.
`protected void` `assertKnownException(java.sql.SQLException e)` Check that a given exception is not an unexpected 'general error' exception.
`protected void` `assertKnownException(java.lang.String message, java.sql.SQLException e)` Check that a given exception is not an unexpected 'general error' exception.
`protected void` `assertResult(java.lang.String expected, java.sql.Statement stat, java.lang.String sql)` Check that the result set of a query is exactly this value.
`protected void` `assertResultRowCount(int expected, java.sql.ResultSet rs)` Check that the result set row count matches.
`protected void` `assertResultSetMeta(java.sql.ResultSet rs, int columnCount, java.lang.String[] labels, int[] datatypes, int[] precision, int[] scale)` Check if the result set meta data is correct.
`protected void` `assertResultSetOrdered(java.sql.ResultSet rs, java.lang.String[][] data)` Check if a result set contains the expected data.
`protected void` `assertSingleValue(java.sql.Statement stat, java.lang.String sql, int expected)` Check that the result set of a query is exactly this value.
`protected void` `assertSmaller(long a, long b)` Check if the first value is larger or equal than the second value, and if not throw an exception.
`protected void` `assertStartsWith(java.lang.String text, java.lang.String expectedStart)` Check that a text starts with the expected characters..
`void` `assertTrue(boolean condition)` Check that the passed boolean is true.
`protected void` `assertTrue(java.lang.String message, boolean condition)` Check that the passed boolean is true.
`protected void` `crash(java.sql.Connection conn)` Simulate a database crash.
`static TestBase` `createCaller()` Create a new object of the calling class.
`static TestBase` `createCaller(java.lang.String className)` Create a new object of the given class.
`protected void` `deleteDb(java.lang.String name)` Delete all database files for this database.
`protected void` `deleteDb(java.lang.String dir, java.lang.String name)` Delete all database files for a database.
`protected void` `eatMemory(int remainingKB)` Use up almost all memory.
`protected void` `fail()` Called if the test reached a point that was not expected.
`protected void` `fail(java.lang.String string)` Called if the test reached a point that was not expected.
`protected void` `freeMemory()` Remove the hard reference to the memory.
`protected java.lang.String` `getClassPath()` Get the classpath list used to execute java -cp ...
`java.sql.Connection` `getConnection(java.lang.String name)` Open a database connection in admin mode.
`protected java.sql.Connection` `getConnection(java.lang.String name, java.lang.String user, java.lang.String password)` Open a database connection.
`static int` `getMemoryUsed()` Get the number of megabytes heap memory in use.
`protected java.lang.String` `getPassword()` Get the login password.
`protected java.lang.String` `getPassword(java.lang.String userPassword)` Get the password to use to login for the given user password.
`protected int` `getSize(int small, int big)` Get the small or the big value depending on the configuration.
`static java.lang.String` `getTestDir(java.lang.String name)` Get the test directory for this test.
`protected java.lang.String` `getURL(java.lang.String name, boolean admin)` Get the database URL for the given database name using the current configuration options.
`protected java.lang.String` `getUser()`
`TestBase` `init()` Initialize the test configuration using the default settings.
`TestBase` `init(TestAll conf)` Initialize the test configuration.
`static void` `logError(java.lang.String s, java.lang.Throwable e)` Log an error message.
`void` `println(java.lang.String s)` Print a message to system out.
`protected void` `printTime(java.lang.String s)` Print the current time and a message to system out.
`void` `printTimeMemory(java.lang.String s, long time)` Print the currently used memory, the message and the given time in milliseconds.
`protected java.lang.String` `readString(java.io.Reader reader)` Read a string from the reader.
`void` `runTest(TestAll conf)` This method is initializes the test, runs the test by calling the test() method, and prints status information.
`protected void` `startServerIfRequired()` Start the TCP server if enabled in the configuration.
`abstract void` `test()` This method will be called by the test framework.
`void` `testCase(int seed)` Run a test case using the given seed value.
`protected void` `trace(int x)` Write a message to system out if trace is enabled.
`void` `trace(java.lang.String s)` Write a message to system out if trace is enabled.
`protected void` `traceMemory()` Print how much memory is currently used.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### baseDir

    protected static java.lang.String baseDir

  The base directory to write test databases.

### TEMP_DIR

    protected static final java.lang.String TEMP_DIR

  The temporary directory.

  See Also:
    Constant Field Values

### uniqueId

    protected static int uniqueId

  An id used to create unique file names.

### config

    public TestAll config

  The test configuration.

### start

    protected long start

  The time when the test was started.

Constructor Detail

### TestBase

    public TestBase()

Method Detail

### getTestDir

    public static java.lang.String getTestDir(java.lang.String name)

  Get the test directory for this test.

  Parameters:
    `name` - the directory name suffix
  Returns:
    the test directory

### startServerIfRequired

    protected void startServerIfRequired()
                                  throws java.sql.SQLException

  Start the TCP server if enabled in the configuration.

  Throws:
    `java.sql.SQLException`

### init

    public TestBase init()
                  throws java.lang.Exception

  Initialize the test configuration using the default settings.

  Returns:
    itself
  Throws:
    `java.lang.Exception`

### init

    public TestBase init(TestAll conf)
                  throws java.lang.Exception

  Initialize the test configuration.

  Parameters:
    `conf` - the configuration
  Returns:
    itself
  Throws:
    `java.lang.Exception`

### testCase

    public void testCase(int seed)
                  throws java.lang.Exception

  Run a test case using the given seed value.

  Parameters:
    `seed` - the random seed value
  Throws:
    `java.lang.Exception`

### runTest

    public void runTest(TestAll conf)

  This method is initializes the test, runs the test by calling the test() method, and prints status information. It also catches exceptions so that the tests can continue.

  Parameters:
    `conf` - the test configuration

### getConnection

    public java.sql.Connection getConnection(java.lang.String name)
                                      throws java.sql.SQLException

  Open a database connection in admin mode. The default user name and password is used.

  Parameters:
    `name` - the database name
  Returns:
    the connection
  Throws:
    `java.sql.SQLException`

### getConnection

    protected java.sql.Connection getConnection(java.lang.String name,
                                                java.lang.String user,
                                                java.lang.String password)
                                         throws java.sql.SQLException

  Open a database connection.

  Parameters:
    `name` - the database name
    `user` - the user name to use
    `password` - the password to use
  Returns:
    the connection
  Throws:
    `java.sql.SQLException`

### getPassword

    protected java.lang.String getPassword(java.lang.String userPassword)

  Get the password to use to login for the given user password. The file password is added if required.

  Parameters:
    `userPassword` - the password of this user
  Returns:
    the login password

### getPassword

    protected java.lang.String getPassword()

  Get the login password. This is usually the user password. If file encryption is used it is combined with the file password.

  Returns:
    the login password

### getURL

    protected java.lang.String getURL(java.lang.String name,
                                      boolean admin)

  Get the database URL for the given database name using the current configuration options.

  Parameters:
    `name` - the database name
    `admin` - true if the current user is an admin
  Returns:
    the database URL

### getSize

    protected int getSize(int small,
                          int big)

  Get the small or the big value depending on the configuration.

  Parameters:
    `small` - the value to return if the current test mode is 'small'
    `big` - the value to return if the current test mode is 'big'
  Returns:
    small or big, depending on the configuration

### getUser

    protected java.lang.String getUser()

### trace

    protected void trace(int x)

  Write a message to system out if trace is enabled.

  Parameters:
    `x` - the value to write

### trace

    public void trace(java.lang.String s)

  Write a message to system out if trace is enabled.

  Parameters:
    `s` - the message to write

### traceMemory

    protected void traceMemory()

  Print how much memory is currently used.

### printTimeMemory

    public void printTimeMemory(java.lang.String s,
                                long time)

  Print the currently used memory, the message and the given time in milliseconds.

  Parameters:
    `s` - the message
    `time` - the time in millis

### getMemoryUsed

    public static int getMemoryUsed()

  Get the number of megabytes heap memory in use.

  Returns:
    the used megabytes

### fail

    protected void fail()

  Called if the test reached a point that was not expected.

  Throws:
    `java.lang.AssertionError` - always throws an AssertionError

### fail

    protected void fail(java.lang.String string)

  Called if the test reached a point that was not expected.

  Parameters:
    `string` - the error message
  Throws:
    `java.lang.AssertionError` - always throws an AssertionError

### logError

    public static void logError(java.lang.String s,
                                java.lang.Throwable e)

  Log an error message.

  Parameters:
    `s` - the message
    `e` - the exception

### println

    public void println(java.lang.String s)

  Print a message to system out.

  Parameters:
    `s` - the message

### printTime

    protected void printTime(java.lang.String s)

  Print the current time and a message to system out.

  Parameters:
    `s` - the message

### deleteDb

    protected void deleteDb(java.lang.String name)
                     throws java.sql.SQLException

  Delete all database files for this database.

  Parameters:
    `name` - the database name
  Throws:
    `java.sql.SQLException`

### deleteDb

    protected void deleteDb(java.lang.String dir,
                            java.lang.String name)
                     throws java.sql.SQLException

  Delete all database files for a database.

  Parameters:
    `dir` - the directory where the database files are located
    `name` - the database name
  Throws:
    `java.sql.SQLException`

### test

    public abstract void test()
                       throws java.lang.Exception

  This method will be called by the test framework.

  Throws:
    `java.lang.Exception` - if an exception in the test occurs

### assertEquals

    public void assertEquals(java.lang.String message,
                             int expected,
                             int actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `message` - the message to print in case of error
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEquals

    public void assertEquals(int expected,
                             int actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEquals

    public void assertEquals(byte[] expected,
                             byte[] actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEqualReaders

    protected void assertEqualReaders(java.io.Reader expected,
                                      java.io.Reader actual,
                                      int len)
                               throws java.io.IOException

  Check if two readers are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal
    `java.io.IOException`

### assertEqualStreams

    protected void assertEqualStreams(java.io.InputStream expected,
                                      java.io.InputStream actual,
                                      int len)
                               throws java.io.IOException

  Check if two streams are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal
    `java.io.IOException`

### assertEquals

    protected void assertEquals(java.lang.String expected,
                                java.lang.String actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertSmaller

    protected void assertSmaller(long a,
                                 long b)

  Check if the first value is larger or equal than the second value, and if not throw an exception.

  Parameters:
    `a` - the first value
    `b` - the second value (must be smaller than the first value)
  Throws:
    `java.lang.AssertionError` - if the first value is smaller

### assertContains

    protected void assertContains(java.lang.String result,
                                  java.lang.String contains)

  Check that a result contains the given substring.

  Parameters:
    `result` - the result value
    `contains` - the term that should appear in the result
  Throws:
    `java.lang.AssertionError` - if the term was not found

### assertStartsWith

    protected void assertStartsWith(java.lang.String text,
                                    java.lang.String expectedStart)

  Check that a text starts with the expected characters..

  Parameters:
    `text` - the text
    `expectedStart` - the expected prefix
  Throws:
    `java.lang.AssertionError` - if the text does not start with the expected characters

### assertEquals

    protected void assertEquals(long expected,
                                long actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEquals

    protected void assertEquals(double expected,
                                double actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEquals

    protected void assertEquals(float expected,
                                float actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEquals

    protected void assertEquals(boolean expected,
                                boolean actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertTrue

    public void assertTrue(boolean condition)

  Check that the passed boolean is true.

  Parameters:
    `condition` - the condition
  Throws:
    `java.lang.AssertionError` - if the condition is false

### assertTrue

    protected void assertTrue(java.lang.String message,
                              boolean condition)

  Check that the passed boolean is true.

  Parameters:
    `message` - the message to print if the condition is false
    `condition` - the condition
  Throws:
    `java.lang.AssertionError` - if the condition is false

### assertFalse

    protected void assertFalse(boolean value)

  Check that the passed boolean is false.

  Parameters:
    `value` - the condition
  Throws:
    `java.lang.AssertionError` - if the condition is true

### assertFalse

    protected void assertFalse(java.lang.String message,
                               boolean value)

  Check that the passed boolean is false.

  Parameters:
    `message` - the message to print if the condition is false
    `value` - the condition
  Throws:
    `java.lang.AssertionError` - if the condition is true

### assertResultRowCount

    protected void assertResultRowCount(int expected,
                                        java.sql.ResultSet rs)
                                 throws java.sql.SQLException

  Check that the result set row count matches.

  Parameters:
    `expected` - the number of expected rows
    `rs` - the result set
  Throws:
    `java.lang.AssertionError` - if a different number of rows have been found
    `java.sql.SQLException`

### assertSingleValue

    protected void assertSingleValue(java.sql.Statement stat,
                                     java.lang.String sql,
                                     int expected)
                              throws java.sql.SQLException

  Check that the result set of a query is exactly this value.

  Parameters:
    `stat` - the statement
    `sql` - the SQL statement to execute
    `expected` - the expected result value
  Throws:
    `java.lang.AssertionError` - if a different result value was returned
    `java.sql.SQLException`

### assertResult

    protected void assertResult(java.lang.String expected,
                                java.sql.Statement stat,
                                java.lang.String sql)
                         throws java.sql.SQLException

  Check that the result set of a query is exactly this value.

  Parameters:
    `expected` - the expected result value
    `stat` - the statement
    `sql` - the SQL statement to execute
  Throws:
    `java.lang.AssertionError` - if a different result value was returned
    `java.sql.SQLException`

### assertResultSetMeta

    protected void assertResultSetMeta(java.sql.ResultSet rs,
                                       int columnCount,
                                       java.lang.String[] labels,
                                       int[] datatypes,
                                       int[] precision,
                                       int[] scale)
                                throws java.sql.SQLException

  Check if the result set meta data is correct.

  Parameters:
    `rs` - the result set
    `columnCount` - the expected column count
    `labels` - the expected column labels
    `datatypes` - the expected data types
    `precision` - the expected precisions
    `scale` - the expected scales
  Throws:
    `java.sql.SQLException`

### assertResultSetOrdered

    protected void assertResultSetOrdered(java.sql.ResultSet rs,
                                          java.lang.String[][] data)
                                   throws java.sql.SQLException

  Check if a result set contains the expected data. The sort order is significant

  Parameters:
    `rs` - the result set
    `data` - the expected data
  Throws:
    `java.lang.AssertionError` - if there is a mismatch
    `java.sql.SQLException`

### crash

    protected void crash(java.sql.Connection conn)

  Simulate a database crash. This method will also close the database files, but the files are in a state as the power was switched off. It doesn't throw an exception.

  Parameters:
    `conn` - the database connection

### readString

    protected java.lang.String readString(java.io.Reader reader)

  Read a string from the reader. This method reads until end of file.

  Parameters:
    `reader` - the reader
  Returns:
    the string read

### assertKnownException

    protected void assertKnownException(java.sql.SQLException e)

  Check that a given exception is not an unexpected 'general error' exception.

  Parameters:
    `e` - the error

### assertKnownException

    protected void assertKnownException(java.lang.String message,
                                        java.sql.SQLException e)

  Check that a given exception is not an unexpected 'general error' exception.

  Parameters:
    `message` - the message
    `e` - the exception

### assertEquals

    protected void assertEquals(java.lang.Integer expected,
                                java.lang.Integer actual)

  Check if two values are equal, and if not throw an exception.

  Parameters:
    `expected` - the expected value
    `actual` - the actual value
  Throws:
    `java.lang.AssertionError` - if the values are not equal

### assertEqualDatabases

    protected void assertEqualDatabases(java.sql.Statement stat1,
                                        java.sql.Statement stat2)
                                 throws java.sql.SQLException

  Check if two databases contain the same met data.

  Parameters:
    `stat1` - the connection to the first database
    `stat2` - the connection to the second database
  Throws:
    `java.lang.AssertionError` - if the databases don't match
    `java.sql.SQLException`

### createCaller

    public static TestBase createCaller()

  Create a new object of the calling class.

  Returns:
    the new test

### createCaller

    public static TestBase createCaller(java.lang.String className)

  Create a new object of the given class.

  Parameters:
    `className` - the class name
  Returns:
    the new test

### getClassPath

    protected java.lang.String getClassPath()

  Get the classpath list used to execute java -cp ...

  Returns:
    the classpath list

### eatMemory

    protected void eatMemory(int remainingKB)

  Use up almost all memory.

  Parameters:
    `remainingKB` - the number of kilobytes that are not referenced

### freeMemory

    protected void freeMemory()

  Remove the hard reference to the memory.