public abstract class TestBase
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
TestBase.Child |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BASE_TEST_DIR
The base directory.
|
TestAll |
config
The test configuration.
|
protected long |
start
The time when the test was started.
|
protected static int |
uniqueId
An id used to create unique file names.
|
| Constructor and Description |
|---|
TestBase() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
assertEquals(java.util.Date expected,
java.util.Date 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.Object[] expected,
java.lang.Object[] actual)
Check if two arrays are equal, and if not throw an exception.
|
void |
assertEquals(java.lang.Object expected,
java.lang.Object 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 message,
java.sql.ResultSet rs0,
java.sql.ResultSet rs1)
Check if two result sets 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 |
assertEquals(java.lang.String message,
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.
|
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.
|
void |
assertNull(java.lang.Object obj)
Check that the passed object is null.
|
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..
|
protected <T> T |
assertThrows(java.lang.Class<?> expectedExceptionClass,
T obj)
Verify the next method call on the object will throw an exception.
|
protected void |
assertThrows(int expectedErrorCode,
java.sql.Statement stat,
java.lang.String sql)
Check that executing the specified query results in the specified error.
|
protected <T> T |
assertThrows(int expectedErrorCode,
T obj)
Verify the next method call on the object will throw an exception.
|
protected <T> T |
assertThrows(ResultVerifier verifier,
T obj)
Verify the next method call on the object will throw an exception.
|
void |
assertTrue(boolean condition)
Check that the passed boolean is true.
|
void |
assertTrue(java.lang.String message,
boolean condition)
Check that the passed boolean is true.
|
java.lang.ProcessBuilder |
buildChild(java.lang.String name,
java.lang.Class<? extends TestBase> childClass,
java.lang.String... jvmArgs)
Build a child process.
|
protected void |
crash(java.sql.Connection conn)
Simulate a database crash.
|
static TestBase |
createCaller()
Create a new object of the calling class.
|
protected void |
createClassProxy(java.lang.Class<?> clazz)
Create a proxy class that extends the given class.
|
static java.io.ByteArrayInputStream |
createFailingStream(java.lang.Exception e)
Construct a stream of 20 KB that fails while reading with the provided
exception.
|
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.
|
void |
execute(java.sql.PreparedStatement stat)
Execute the statement.
|
protected void |
execute(java.sql.Statement stat,
java.lang.String sql)
Execute the statement.
|
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.
|
java.lang.String |
getBaseDir()
Get the base directory for tests.
|
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.
|
java.sql.Connection |
getConnection(java.lang.String name,
java.lang.String user,
java.lang.String password)
Open a database connection.
|
protected java.lang.String |
getFilePassword()
Get the file password (only required if file encryption is used).
|
static int |
getMemoryUsed()
Get the number of megabytes heap memory in use.
|
static long |
getMemoryUsedBytes()
Get the number of bytes 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.
|
java.lang.String |
getTestName()
Get the name of the 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.
|
static void |
logErrorMessage(java.lang.String s)
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.
|
static void |
throwException(java.lang.Throwable e)
Throw a checked exception, without having to declare the method as
throwing a checked exception.
|
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.
|
public static final java.lang.String BASE_TEST_DIR
protected static int uniqueId
public TestAll config
protected long start
public static java.lang.String getTestDir(java.lang.String name)
name - the directory name suffixprotected void startServerIfRequired()
throws java.sql.SQLException
java.sql.SQLExceptionpublic TestBase init() throws java.lang.Exception
java.lang.Exceptionpublic TestBase init(TestAll conf) throws java.lang.Exception
conf - the configurationjava.lang.Exceptionpublic void runTest(TestAll conf)
conf - the test configurationpublic java.sql.Connection getConnection(java.lang.String name)
throws java.sql.SQLException
name - the database namejava.sql.SQLExceptionpublic java.sql.Connection getConnection(java.lang.String name,
java.lang.String user,
java.lang.String password)
throws java.sql.SQLException
name - the database nameuser - the user name to usepassword - the password to usejava.sql.SQLExceptionprotected java.lang.String getPassword(java.lang.String userPassword)
userPassword - the password of this userprotected java.lang.String getFilePassword()
protected java.lang.String getPassword()
public java.lang.String getBaseDir()
protected java.lang.String getURL(java.lang.String name,
boolean admin)
name - the database nameadmin - true if the current user is an adminprotected int getSize(int small,
int big)
small - the value to return if the current test mode is 'small'big - the value to return if the current test mode is 'big'protected java.lang.String getUser()
protected void trace(int x)
x - the value to writepublic void trace(java.lang.String s)
s - the message to writeprotected void traceMemory()
public void printTimeMemory(java.lang.String s,
long time)
s - the messagetime - the time in millispublic static int getMemoryUsed()
public static long getMemoryUsedBytes()
public void fail()
java.lang.AssertionError - always throws an AssertionErrorprotected void fail(java.lang.String string)
string - the error messagejava.lang.AssertionError - always throws an AssertionErrorpublic static void logErrorMessage(java.lang.String s)
s - the messagepublic static void logError(java.lang.String s,
java.lang.Throwable e)
s - the messagee - the exceptionpublic void println(java.lang.String s)
s - the messageprotected void printTime(java.lang.String s)
s - the messageprotected void deleteDb(java.lang.String name)
name - the database nameprotected void deleteDb(java.lang.String dir,
java.lang.String name)
dir - the directory where the database files are locatedname - the database namepublic abstract void test()
throws java.lang.Exception
java.lang.Exception - if an exception in the test occurspublic void assertEquals(java.lang.String message,
int expected,
int actual)
message - the message to print in case of errorexpected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalpublic void assertEquals(int expected,
int actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalpublic void assertEquals(byte[] expected,
byte[] actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalpublic void assertEquals(java.util.Date expected,
java.util.Date actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalpublic void assertEquals(java.lang.Object[] expected,
java.lang.Object[] actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalpublic void assertEquals(java.lang.Object expected,
java.lang.Object actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEqualReaders(java.io.Reader expected,
java.io.Reader actual,
int len)
throws java.io.IOException
expected - the expected valueactual - the actual valuelen - the maximum length, or -1java.lang.AssertionError - if the values are not equaljava.io.IOExceptionprotected void assertEqualStreams(java.io.InputStream expected,
java.io.InputStream actual,
int len)
throws java.io.IOException
expected - the expected valueactual - the actual valuelen - the maximum length, or -1java.lang.AssertionError - if the values are not equaljava.io.IOExceptionprotected void assertEquals(java.lang.String message,
java.lang.String expected,
java.lang.String actual)
message - the message to use if the check failsexpected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEquals(java.lang.String expected,
java.lang.String actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEquals(java.lang.String message,
java.sql.ResultSet rs0,
java.sql.ResultSet rs1)
throws java.sql.SQLException
message - the message to use if the check failsrs0 - the first result setrs1 - the second result setjava.lang.AssertionError - if the values are not equaljava.sql.SQLExceptionprotected void assertSmaller(long a,
long b)
a - the first valueb - the second value (must be smaller than the first value)java.lang.AssertionError - if the first value is smallerprotected void assertContains(java.lang.String result,
java.lang.String contains)
result - the result valuecontains - the term that should appear in the resultjava.lang.AssertionError - if the term was not foundprotected void assertStartsWith(java.lang.String text,
java.lang.String expectedStart)
text - the textexpectedStart - the expected prefixjava.lang.AssertionError - if the text does not start with the expected
charactersprotected void assertEquals(long expected,
long actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEquals(double expected,
double actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEquals(float expected,
float actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEquals(boolean expected,
boolean actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalpublic void assertTrue(boolean condition)
condition - the conditionjava.lang.AssertionError - if the condition is falsepublic void assertNull(java.lang.Object obj)
obj - the objectjava.lang.AssertionError - if the condition is falsepublic void assertTrue(java.lang.String message,
boolean condition)
message - the message to print if the condition is falsecondition - the conditionjava.lang.AssertionError - if the condition is falseprotected void assertFalse(boolean value)
value - the conditionjava.lang.AssertionError - if the condition is trueprotected void assertFalse(java.lang.String message,
boolean value)
message - the message to print if the condition is falsevalue - the conditionjava.lang.AssertionError - if the condition is trueprotected void assertResultRowCount(int expected,
java.sql.ResultSet rs)
throws java.sql.SQLException
expected - the number of expected rowsrs - the result setjava.lang.AssertionError - if a different number of rows have been foundjava.sql.SQLExceptionprotected void assertSingleValue(java.sql.Statement stat,
java.lang.String sql,
int expected)
throws java.sql.SQLException
stat - the statementsql - the SQL statement to executeexpected - the expected result valuejava.lang.AssertionError - if a different result value was returnedjava.sql.SQLExceptionprotected void assertResult(java.lang.String expected,
java.sql.Statement stat,
java.lang.String sql)
throws java.sql.SQLException
expected - the expected result valuestat - the statementsql - the SQL statement to executejava.lang.AssertionError - if a different result value was returnedjava.sql.SQLExceptionprotected void assertThrows(int expectedErrorCode,
java.sql.Statement stat,
java.lang.String sql)
expectedErrorCode - the expected error codestat - the statementsql - the SQL statement to executepublic void execute(java.sql.PreparedStatement stat)
throws java.sql.SQLException
stat - the statementjava.sql.SQLExceptionprotected void execute(java.sql.Statement stat,
java.lang.String sql)
throws java.sql.SQLException
stat - the statementsql - the SQL commandjava.sql.SQLExceptionprotected void assertResultSetMeta(java.sql.ResultSet rs,
int columnCount,
java.lang.String[] labels,
int[] datatypes,
int[] precision,
int[] scale)
throws java.sql.SQLException
rs - the result setcolumnCount - the expected column countlabels - the expected column labelsdatatypes - the expected data typesprecision - the expected precisionsscale - the expected scalesjava.sql.SQLExceptionprotected void assertResultSetOrdered(java.sql.ResultSet rs,
java.lang.String[][] data)
throws java.sql.SQLException
rs - the result setdata - the expected datajava.lang.AssertionError - if there is a mismatchjava.sql.SQLExceptionprotected void crash(java.sql.Connection conn)
conn - the database connectionprotected java.lang.String readString(java.io.Reader reader)
reader - the readerpublic void assertKnownException(java.sql.SQLException e)
e - the errorprotected void assertKnownException(java.lang.String message,
java.sql.SQLException e)
message - the messagee - the exceptionprotected void assertEquals(java.lang.Integer expected,
java.lang.Integer actual)
expected - the expected valueactual - the actual valuejava.lang.AssertionError - if the values are not equalprotected void assertEqualDatabases(java.sql.Statement stat1,
java.sql.Statement stat2)
throws java.sql.SQLException
stat1 - the connection to the first databasestat2 - the connection to the second databasejava.lang.AssertionError - if the databases don't matchjava.sql.SQLExceptionpublic static TestBase createCaller()
protected java.lang.String getClassPath()
protected void eatMemory(int remainingKB)
remainingKB - the number of kilobytes that are not referencedprotected void freeMemory()
protected <T> T assertThrows(java.lang.Class<?> expectedExceptionClass,
T obj)
T - the class of the objectexpectedExceptionClass - the expected exception class to be thrownobj - the object to wrapprotected <T> T assertThrows(int expectedErrorCode,
T obj)
T - the class of the objectexpectedErrorCode - the expected error codeobj - the object to wrapprotected <T> T assertThrows(ResultVerifier verifier, T obj)
T - the class of the objectverifier - the result verifier to callobj - the object to wrapprotected void createClassProxy(java.lang.Class<?> clazz)
clazz - the classpublic static java.io.ByteArrayInputStream createFailingStream(java.lang.Exception e)
e - the exceptionpublic static void throwException(java.lang.Throwable e)
e - the exception to throwpublic java.lang.String getTestName()
public java.lang.ProcessBuilder buildChild(java.lang.String name,
java.lang.Class<? extends TestBase> childClass,
java.lang.String... jvmArgs)
name - the namechildClass - the classjvmArgs - the argument list