|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.h2.test.TestBase
public abstract class TestBase
The base class for all tests.
| Field Summary | |
|---|---|
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 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.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
|
assertThrows(java.lang.Class<?> expectedExceptionClass,
T obj)
Verify the next method call on the object will throw an exception. |
|
protected
|
assertThrows(int expectedErrorCode,
T obj)
Verify the next method call on the object will throw an exception. |
|
protected
|
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. |
|
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 |
createClassProxy(java.lang.Class<?> clazz)
Create a proxy class that extends 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. |
|
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. |
|
protected 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. |
|
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 |
|---|
public static final java.lang.String BASE_TEST_DIR
protected static final java.lang.String TEMP_DIR
protected static int uniqueId
public TestAll config
protected long start
| Constructor Detail |
|---|
public TestBase()
| Method Detail |
|---|
public static java.lang.String getTestDir(java.lang.String name)
name - the directory name suffix
protected void startServerIfRequired()
throws java.sql.SQLException
java.sql.SQLException
public TestBase init()
throws java.lang.Exception
java.lang.Exception
public TestBase init(TestAll conf)
throws java.lang.Exception
conf - the configuration
java.lang.Exception
public void testCase(int seed)
throws java.lang.Exception
seed - the random seed value
java.lang.Exceptionpublic void runTest(TestAll conf)
conf - the test configuration
public java.sql.Connection getConnection(java.lang.String name)
throws java.sql.SQLException
name - the database name
java.sql.SQLException
protected 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 use
java.sql.SQLExceptionprotected java.lang.String getPassword(java.lang.String userPassword)
userPassword - the password of this user
protected 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 admin
protected 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 void fail()
java.lang.AssertionError - always throws an AssertionErrorprotected void fail(java.lang.String string)
string - the error message
java.lang.AssertionError - always throws an AssertionError
public 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 name
protected void deleteDb(java.lang.String dir,
java.lang.String name)
dir - the directory where the database files are locatedname - the database name
public abstract void test()
throws java.lang.Exception
java.lang.Exception - if an exception in the test occurs
public void assertEquals(java.lang.String message,
int expected,
int actual)
message - the message to print in case of errorexpected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
public void assertEquals(int expected,
int actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
public void assertEquals(byte[] expected,
byte[] actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
public void assertEquals(java.lang.Object[] expected,
java.lang.Object[] actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
protected 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 -1
java.lang.AssertionError - if the values are not equal
java.io.IOException
protected 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 -1
java.lang.AssertionError - if the values are not equal
java.io.IOException
protected 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 value
java.lang.AssertionError - if the values are not equal
protected void assertEquals(java.lang.String expected,
java.lang.String actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
protected 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 set
java.lang.AssertionError - if the values are not equal
java.sql.SQLException
protected 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 smaller
protected void assertContains(java.lang.String result,
java.lang.String contains)
result - the result valuecontains - the term that should appear in the result
java.lang.AssertionError - if the term was not found
protected void assertStartsWith(java.lang.String text,
java.lang.String expectedStart)
text - the textexpectedStart - the expected prefix
java.lang.AssertionError - if the text does not start with the expected characters
protected void assertEquals(long expected,
long actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
protected void assertEquals(double expected,
double actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
protected void assertEquals(float expected,
float actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
protected void assertEquals(boolean expected,
boolean actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equalpublic void assertTrue(boolean condition)
condition - the condition
java.lang.AssertionError - if the condition is falsepublic void assertNull(java.lang.Object obj)
obj - the object
java.lang.AssertionError - if the condition is false
protected void assertTrue(java.lang.String message,
boolean condition)
message - the message to print if the condition is falsecondition - the condition
java.lang.AssertionError - if the condition is falseprotected void assertFalse(boolean value)
value - the condition
java.lang.AssertionError - if the condition is true
protected void assertFalse(java.lang.String message,
boolean value)
message - the message to print if the condition is falsevalue - the condition
java.lang.AssertionError - if the condition is true
protected void assertResultRowCount(int expected,
java.sql.ResultSet rs)
throws java.sql.SQLException
expected - the number of expected rowsrs - the result set
java.lang.AssertionError - if a different number of rows have been found
java.sql.SQLException
protected 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 value
java.lang.AssertionError - if a different result value was returned
java.sql.SQLException
protected 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 execute
java.lang.AssertionError - if a different result value was returned
java.sql.SQLException
protected 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 scales
java.sql.SQLException
protected void assertResultSetOrdered(java.sql.ResultSet rs,
java.lang.String[][] data)
throws java.sql.SQLException
rs - the result setdata - the expected data
java.lang.AssertionError - if there is a mismatch
java.sql.SQLExceptionprotected void crash(java.sql.Connection conn)
conn - the database connectionprotected java.lang.String readString(java.io.Reader reader)
reader - the reader
public void assertKnownException(java.sql.SQLException e)
e - the error
protected void assertKnownException(java.lang.String message,
java.sql.SQLException e)
message - the messagee - the exception
protected void assertEquals(java.lang.Integer expected,
java.lang.Integer actual)
expected - the expected valueactual - the actual value
java.lang.AssertionError - if the values are not equal
protected 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 database
java.lang.AssertionError - if the databases don't match
java.sql.SQLExceptionpublic static TestBase createCaller()
public static TestBase createCaller(java.lang.String className)
className - the class name
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 wrap
protected <T> T assertThrows(int expectedErrorCode,
T obj)
T - the class of the objectexpectedErrorCode - the expected error codeobj - the object to wrap
protected <T> T assertThrows(ResultVerifier verifier,
T obj)
T - the class of the objectverifier - the result verifier to callobj - the object to wrap
protected void createClassProxy(java.lang.Class<?> clazz)
clazz - the class
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||