TestBase

The base class for all tests.

Methods
static TestBase createCaller()
Create a new object of the calling class.
static TestBase createCaller()
Create a new object of the calling class.
Returns:
the new test
static ByteArrayInputStream createFailingStream(Exception e)
Construct a stream of 20 KB that fails while reading with the provided exception.
static ByteArrayInputStream createFailingStream(Exception e)
Construct a stream of 20 KB that fails while reading with the provided exception.
Parameters:
e - the exception
Returns:
the stream
static String formatTime(long millis)
Format the time in the format hh:mm:ss.1234 where 1234 is milliseconds.
static String formatTime(long millis)
Format the time in the format hh:mm:ss.1234 where 1234 is milliseconds.
Parameters:
millis - the time in milliseconds
Returns:
the formatted time
static int getMemoryUsed()
Get the number of megabytes heap memory in use.
static int getMemoryUsed()
Get the number of megabytes heap memory in use.
Returns:
the used megabytes
static long getMemoryUsedBytes()
Get the number of bytes heap memory in use.
static long getMemoryUsedBytes()
Get the number of bytes heap memory in use.
Returns:
the used bytes
static String getTestDir(String name)
Get the test directory for this test.
static String getTestDir(String name)
Get the test directory for this test.
Parameters:
name - the directory name suffix
Returns:
the test directory
static void logError(String s, Throwable e)
Log an error message.
static void logError(String s, Throwable e)
Log an error message.
Parameters:
s - the message
e - the exception
static void logErrorMessage(String s)
Log an error message.
static void logErrorMessage(String s)
Log an error message.
Parameters:
s - the message
static void printlnWithTime(long millis, String s)
Print a message, prepended with the specified time in milliseconds.
static void printlnWithTime(long millis, String s)
Print a message, prepended with the specified time in milliseconds.
Parameters:
millis - the time in milliseconds
s - the message
static void throwException(Throwable e)
Throw a checked exception, without having to declare the method as throwing a checked exception.
static void throwException(Throwable e)
Throw a checked exception, without having to declare the method as throwing a checked exception.
Parameters:
e - the exception to throw
void assertContains(String result, String contains)
Check that a result contains the given substring.
void assertContains(String result, 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:
AssertionError - if the term was not found
void assertEqualDatabases(Statement stat1, Statement stat2)
Check if two databases contain the same met data.
void assertEqualDatabases(Statement stat1, Statement stat2) throws 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:
AssertionError - if the databases don't match
void assertEqualReaders(Reader expected, Reader actual, int len)
Check if two readers are equal, and if not throw an exception.
void assertEqualReaders(Reader expected, Reader actual, int len) throws IOException
Check if two readers are equal, and if not throw an exception.
Parameters:
expected - the expected value
actual - the actual value
len - the maximum length, or -1
Throws:
AssertionError - if the values are not equal
void assertEqualStreams(InputStream expected, InputStream actual, int len)
Check if two streams are equal, and if not throw an exception.
void assertEqualStreams(InputStream expected, InputStream actual, int len) throws IOException
Check if two streams are equal, and if not throw an exception.
Parameters:
expected - the expected value
actual - the actual value
len - the maximum length, or -1
Throws:
AssertionError - if the values are not equal
void assertEquals(String message, int expected, int actual)
Check if two values are equal, and if not throw an exception.
void assertEquals(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:
AssertionError - if the values are not equal
void assertEquals(int expected, int 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.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(byte[] expected, byte[] 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.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(Date expected, Date actual)
Check if two values are equal, and if not throw an exception.
void assertEquals(Date expected, Date actual)
Check if two values are equal, and if not throw an exception.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(Object[] expected, Object[] actual)
Check if two arrays are equal, and if not throw an exception.
void assertEquals(Object[] expected, Object[] actual)
Check if two arrays are equal, and if not throw an exception. If some of the elements in the arrays are themselves arrays this check is called recursively.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(Object expected, Object actual)
Check if two values are equal, and if not throw an exception.
void assertEquals(Object expected, Object actual)
Check if two values are equal, and if not throw an exception.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(String message, String expected, String actual)
Check if two values are equal, and if not throw an exception.
void assertEquals(String message, String expected, String actual)
Check if two values are equal, and if not throw an exception.
Parameters:
message - the message to use if the check fails
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(String expected, String actual)
Check if two values are equal, and if not throw an exception.
void assertEquals(String expected, String actual)
Check if two values are equal, and if not throw an exception.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertEquals(String message, ResultSet rs0, ResultSet rs1)
Check if two result sets are equal, and if not throw an exception.
void assertEquals(String message, ResultSet rs0, ResultSet rs1) throws SQLException
Check if two result sets are equal, and if not throw an exception.
Parameters:
message - the message to use if the check fails
rs0 - the first result set
rs1 - the second result set
Throws:
AssertionError - if the values are not equal
void assertEquals(long expected, long actual)
Check if two values are equal, and if not throw an exception.
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:
AssertionError - if the values are not equal
void assertEquals(double expected, double actual)
Check if two values are equal, and if not throw an exception.
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:
AssertionError - if the values are not equal
void assertEquals(float expected, float actual)
Check if two values are equal, and if not throw an exception.
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:
AssertionError - if the values are not equal
void assertEquals(boolean expected, boolean actual)
Check if two values are equal, and if not throw an exception.
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:
AssertionError - if the values are not equal
void assertEquals(Integer expected, Integer actual)
Check if two values are equal, and if not throw an exception.
void assertEquals(Integer expected, Integer actual)
Check if two values are equal, and if not throw an exception.
Parameters:
expected - the expected value
actual - the actual value
Throws:
AssertionError - if the values are not equal
void assertFalse(boolean value)
Check that the passed boolean is false.
void assertFalse(boolean value)
Check that the passed boolean is false.
Parameters:
value - the condition
Throws:
AssertionError - if the condition is true
void assertFalse(String message, boolean value)
Check that the passed boolean is false.
void assertFalse(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:
AssertionError - if the condition is true
void assertKnownException(SQLException e)
Check that a given exception is not an unexpected 'general error' exception.
void assertKnownException(SQLException e)
Check that a given exception is not an unexpected 'general error' exception.
Parameters:
e - the error
void assertKnownException(String message, SQLException e)
Check that a given exception is not an unexpected 'general error' exception.
void assertKnownException(String message, SQLException e)
Check that a given exception is not an unexpected 'general error' exception.
Parameters:
message - the message
e - the exception
void assertNull(Object obj)
Check that the passed object is null.
void assertNull(Object obj)
Check that the passed object is null.
Parameters:
obj - the object
Throws:
AssertionError - if the condition is false
void assertResult(String expected, Statement stat, String sql)
Check that the result set of a query is exactly this value.
void assertResult(String expected, Statement stat, String sql) throws 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:
AssertionError - if a different result value was returned
void assertResultRowCount(int expected, ResultSet rs)
Check that the result set row count matches.
void assertResultRowCount(int expected, ResultSet rs) throws SQLException
Check that the result set row count matches.
Parameters:
expected - the number of expected rows
rs - the result set
Throws:
AssertionError - if a different number of rows have been found
void assertResultSetMeta(ResultSet rs, int columnCount, String[] labels, int[] datatypes, int[] precision, int[] scale)
Check if the result set meta data is correct.
void assertResultSetMeta(ResultSet rs, int columnCount, String[] labels, int[] datatypes, int[] precision, int[] scale) throws 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
void assertResultSetOrdered(ResultSet rs, String[][] data)
Check if a result set contains the expected data.
void assertResultSetOrdered(ResultSet rs, String[][] data) throws 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:
AssertionError - if there is a mismatch
void assertSingleValue(Statement stat, String sql, int expected)
Check that the result set of a query is exactly this value.
void assertSingleValue(Statement stat, String sql, int expected) throws 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:
AssertionError - if a different result value was returned
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.
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:
AssertionError - if the first value is smaller
void assertStartsWith(String text, String expectedStart)
Check that a text starts with the expected characters..
void assertStartsWith(String text, String expectedStart)
Check that a text starts with the expected characters..
Parameters:
text - the text
expectedStart - the expected prefix
Throws:
AssertionError - if the text does not start with the expected characters
void assertThrows(int expectedErrorCode, Statement stat, String sql)
Check that executing the specified query results in the specified error.
void assertThrows(int expectedErrorCode, Statement stat, String sql)
Check that executing the specified query results in the specified error.
Parameters:
expectedErrorCode - the expected error code
stat - the statement
sql - the SQL statement to execute
T assertThrows(Class expectedExceptionClass, T obj)
Verify the next method call on the object will throw an exception.
T assertThrows(Class expectedExceptionClass, T obj)
Verify the next method call on the object will throw an exception.
Parameters:
expectedExceptionClass - the expected exception class to be thrown
obj - the object to wrap
Returns:
a proxy for the object
T assertThrows(int expectedErrorCode, T obj)
Verify the next method call on the object will throw an exception.
T assertThrows(int expectedErrorCode, T obj)
Verify the next method call on the object will throw an exception.
Parameters:
expectedErrorCode - the expected error code
obj - the object to wrap
Returns:
a proxy for the object
T assertThrows(ResultVerifier verifier, T obj)
Verify the next method call on the object will throw an exception.
T assertThrows(ResultVerifier verifier, T obj)
Verify the next method call on the object will throw an exception.
Parameters:
verifier - the result verifier to call
obj - the object to wrap
Returns:
a proxy for the object
void assertTrue(boolean condition)
Check that the passed boolean is true.
void assertTrue(boolean condition)
Check that the passed boolean is true.
Parameters:
condition - the condition
Throws:
AssertionError - if the condition is false
void assertTrue(String message, boolean condition)
Check that the passed boolean is true.
void assertTrue(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:
AssertionError - if the condition is false
ProcessBuilder buildChild(String name, Class childClass, String... jvmArgs)
Build a child process.
ProcessBuilder buildChild(String name, Class childClass, String... jvmArgs)
Build a child process.
Parameters:
name - the name
childClass - the class
jvmArgs - the argument list
Returns:
the process builder
void crash(Connection conn)
Simulate a database crash.
void crash(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
void createClassProxy(Class clazz)
Create a proxy class that extends the given class.
void createClassProxy(Class clazz)
Create a proxy class that extends the given class.
Parameters:
clazz - the class
void deleteDb(String name)
Delete all database files for this database.
void deleteDb(String name)
Delete all database files for this database.
Parameters:
name - the database name
void deleteDb(String dir, String name)
Delete all database files for a database.
void deleteDb(String dir, String name)
Delete all database files for a database.
Parameters:
dir - the directory where the database files are located
name - the database name
void eatMemory(int remainingKB)
Use up almost all memory.
void eatMemory(int remainingKB)
Use up almost all memory.
Parameters:
remainingKB - the number of kilobytes that are not referenced
void execute(PreparedStatement stat)
Execute the statement.
void execute(PreparedStatement stat) throws SQLException
Execute the statement.
Parameters:
stat - the statement
void execute(Statement stat, String sql)
Execute the statement.
void execute(Statement stat, String sql) throws SQLException
Execute the statement.
Parameters:
stat - the statement
sql - the SQL command
void fail()
Called if the test reached a point that was not expected.
void fail()
Called if the test reached a point that was not expected.
Throws:
AssertionError - always throws an AssertionError
void fail(String string)
Called if the test reached a point that was not expected.
void fail(String string)
Called if the test reached a point that was not expected.
Parameters:
string - the error message
Throws:
AssertionError - always throws an AssertionError
void freeMemory()
Remove the hard reference to the memory.
void freeMemory()
Remove the hard reference to the memory.
String getBaseDir()
Get the base directory for tests.
String getBaseDir()
Get the base directory for tests. If a special file system is used, the prefix is prepended.
Returns:
the directory, possibly including file system prefix
String getClassPath()
Get the classpath list used to execute java -cp ...
String getClassPath()
Get the classpath list used to execute java -cp ...
Returns:
the classpath list
Connection getConnection(String name)
Open a database connection in admin mode.
Connection getConnection(String name) throws SQLException
Open a database connection in admin mode. The default user name and password is used.
Parameters:
name - the database name
Returns:
the connection
Connection getConnection(String name, String user, String password)
Open a database connection.
Connection getConnection(String name, String user, String password) throws SQLException
Open a database connection.
Parameters:
name - the database name
user - the user name to use
password - the password to use
Returns:
the connection
String getFilePassword()
Get the file password (only required if file encryption is used).
String getFilePassword()
Get the file password (only required if file encryption is used).
Returns:
the file password
String getPassword(String userPassword)
Get the password to use to login for the given user password.
String getPassword(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
String getPassword()
Get the login password.
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
int getSize(int small, int big)
Get the small or the big value depending on the configuration.
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
String getTestName()
Get the name of the test.
String getTestName()
Get the name of the test.
Returns:
the name of the test class
String getURL(String name, boolean admin)
Get the database URL for the given database name using the current configuration options.
String getURL(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
String getUser()
String getUser()
TestBase init()
Initialize the test configuration using the default settings.
TestBase init() throws Exception
Initialize the test configuration using the default settings.
Returns:
itself
TestBase init(TestAll conf)
Initialize the test configuration.
TestBase init(TestAll conf) throws Exception
Initialize the test configuration.
Parameters:
conf - the configuration
Returns:
itself
void printTime(String s)
Print the current time and a message to system out.
void printTime(String s)
Print the current time and a message to system out.
Parameters:
s - the message
void printTimeMemory(String s, long time)
Print the currently used memory, the message and the given time in milliseconds.
void printTimeMemory(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
void println(String s)
Print a message to system out.
void println(String s)
Print a message to system out.
Parameters:
s - the message
String readString(Reader reader)
Read a string from the reader.
String readString(Reader reader)
Read a string from the reader. This method reads until end of file.
Parameters:
reader - the reader
Returns:
the string read
void runTest(TestAll conf)
This method is initializes the test, runs the test by calling the test() method, and prints status information.
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
void startServerIfRequired()
Start the TCP server if enabled in the configuration.
void startServerIfRequired() throws SQLException
Start the TCP server if enabled in the configuration.
void test()
This method will be called by the test framework.
void test() throws Exception
This method will be called by the test framework.
Throws:
Exception - if an exception in the test occurs
void trace(int x)
Write a message to system out if trace is enabled.
void trace(int x)
Write a message to system out if trace is enabled.
Parameters:
x - the value to write
void trace(String s)
Write a message to system out if trace is enabled.
void trace(String s)
Write a message to system out if trace is enabled.
Parameters:
s - the message to write
void traceMemory()
Print how much memory is currently used.
void traceMemory()
Print how much memory is currently used.

Fields
static String BASE_TEST_DIR = "./data"
static TestAll config
static long start
static int uniqueId

BASE_TEST_DIR = "./data"

The base directory.

config

The test configuration.

start

The time when the test was started.

uniqueId

An id used to create unique file names.