Package com.sun.ts.lib.util
Class TestUtil
java.lang.Object
com.sun.ts.lib.util.TestUtil
TestUtil is a final utility class responsible for implementing logging across multiple VMs. It also contains many
convenience methods for logging property object contents, stacktraces, and header lines.
- Author:
- Kyle Grucci
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic Stringstatic PropertiesThis method returns the properties objectstatic StringThis method returns the property value for the appropriate property keystatic StringgetProperty(String s, String defaultValue) This method returns the property value for the appropriate property keystatic StringgetProperty(Properties props, String key) Reads a property from the properties object and logs a message if the value is not setstatic StringgetProperty(Properties props, String key, String defaultValue) Reads a property from the properties object and logs a message if the value is not setstatic StringgetRelativePath(String oldVal) static StringgetResponse(URLConnection connection) Convience method to handle sucking in the data from a connection.static PropertiesgetResponseProperties(String string) Loads any properties that might be in a given String.static PropertiesgetResponseProperties(URLConnection connection) One shot method to get Properties directly from a URLConnection.static StringgetSystemProperty(String key) Wrapper for System.getProperty(String) that logs missing propertiesstatic StringgetSystemProperty(String key, String def) static StringgetTableName(String value) Parse a the table name from the ddl string such as: "create table foo" or "delete from foo"static StringgetTransactionStatus(int status) returns the transaction status value as a String given its integer representationstatic voidinit(Properties p) This static method must be called once by each new remote VM.static voidThis static method must be called once by the harness VM.static voidstatic voidThis static method must be called once by a VM which does not rely upon any remote logging.static voidlist(Properties p) prints the contents of a properties object to the logging streamstatic voidprints an error string to the error stream.static voidprints an error string to the error stream.static voidlogHarness(String s) static voidlogHarness(String s, Throwable t) used by TSTestFinder and TSScript to log output to the standard output streamstatic voidused by harness to log debug output to the standard output streamstatic voidprints a string to the log stream.static voidprints a string as well as the provided Throwable's stacktrace to the log stream.static voidprints a debug string to the log stream.static voidPrints a debug string as well as the provided Throwable's stacktrace.static voidprintProperties(Properties props) static voidprints the stacktrace of a Throwable to the logging streamstatic Stringprints the stacktrace of a Throwable to a stringstatic voidprintTransactionStatus(int status) prints the transaction status value as a String given its integer representationstatic StringreplaceLastSrc(String src, String replacement) static URLConnectionsendPostData(Properties p, URL url) static voidprints a line of dashes to the logging streamstatic voidprints a line of asterisks to the logging streamstatic voidstatic voidsetCurrentTest(String testName, PrintWriter outStream, PrintWriter errStream) This static method must be called once by the harness VM in order to set the output and error streams and the name of the current test.static voidsetTrace(boolean b) turns on/off debugging.static voidsleep(int s) pauses the calling thread for the specified number of millisecondsstatic voidsleepMsec(int s) pauses the calling thread for the specified number of millisecondsstatic voidsleepSec(int s) pauses the calling thread for the specified number of secondsstatic Stringstatic PropertiesstrToProps(String strProps) static StringtoEncodedString(Properties args) static voidwriteObject(TestReportInfo info)
-
Field Details
-
traceflag
public static boolean traceflag -
sTestName
-
EMPTY_STRING_ARRAY
-
VM_UNDER_TEST
public static final int VM_UNDER_TEST- See Also:
-
VM_HARNESS
public static final int VM_HARNESS- See Also:
-
VM_JAVATEST
public static final int VM_JAVATEST- See Also:
-
DEBUG_OUTPUT_LEVEL
public static final int DEBUG_OUTPUT_LEVEL- See Also:
-
NORMAL_OUTPUT_LEVEL
public static final int NORMAL_OUTPUT_LEVEL- See Also:
-
ERROR_STREAM
public static final int ERROR_STREAM- See Also:
-
OUTPUT_STREAM
public static final int OUTPUT_STREAM- See Also:
-
NEW_LINE
-
iWhereAreWe
public static int iWhereAreWe -
harnessDebug
public static boolean harnessDebug -
MILLI
public static final int MILLI- See Also:
-
-
Constructor Details
-
TestUtil
public TestUtil()
-
-
Method Details
-
logHarnessDebug
used by harness to log debug output to the standard output stream- Parameters:
s- the output string
-
logHarness
used by TSTestFinder and TSScript to log output to the standard output stream- Parameters:
s- the output stringt- a Throwable whose stacktrace gets printed
-
logHarness
-
getProperties
This method returns the properties object- Returns:
- the properties object
-
getProperty
This method returns the property value for the appropriate property key- Parameters:
s- the property name- Returns:
- the property value
-
getProperty
This method returns the property value for the appropriate property key- Parameters:
s- the property name- Returns:
- the property value
-
getProperty
Reads a property from the properties object and logs a message if the value is not set- Parameters:
props- the properties objectkey- the property key- Returns:
- the property value, null if not set
-
getProperty
Reads a property from the properties object and logs a message if the value is not set- Parameters:
props- the properties objectkey- the property keydefaultValue- the default value- Returns:
- the property value, defaultValue if not set
-
getSystemProperty
Wrapper for System.getProperty(String) that logs missing properties- Parameters:
key- the property key- Returns:
- the property value
-
getSystemProperty
-
getTransactionStatus
returns the transaction status value as a String given its integer representation- Parameters:
status- integer representation of a transaction status- Returns:
- string representation of a transaction status
-
printTransactionStatus
public static void printTransactionStatus(int status) prints the transaction status value as a String given its integer representation- Parameters:
status- integer representation of a transaction status
-
sleepSec
public static void sleepSec(int s) pauses the calling thread for the specified number of seconds- Parameters:
s- number of seconds
-
sleep
public static void sleep(int s) pauses the calling thread for the specified number of milliseconds- Parameters:
s- number of milliseconds
-
sleepMsec
public static void sleepMsec(int s) pauses the calling thread for the specified number of milliseconds- Parameters:
s- number of milliseconds
-
flushStream
public static void flushStream() -
writeObject
-
init
This static method must be called once by each new remote VM. Once called, a socket connection is created back to the host running the test harness. All calls to logMsg, logErr, and logTrace are immediately sent back to the harness host.- Parameters:
p- properties containing harness host, port, and trace flag- Throws:
RemoteLoggingInitException- if an exception occurs while the server side is setting up the socket connection back to the client host
-
initJavaTest
public static void initJavaTest() -
setAdditionalWriter
-
initNoLogging
This static method must be called once by a VM which does not rely upon any remote logging. param p properties containing harness trace flag -
initClient
This static method must be called once by the harness VM. Once called, a serversocket begins listening for Remote VMs to connect on the port specified by harness.log.port.- Parameters:
p- properties containing harness trace flag
-
setCurrentTest
This static method must be called once by the harness VM in order to set the output and error streams and the name of the current test.- Parameters:
testName- the currently running testname as specified in the source code tagsoutStream- stream printed to by the logMsg and logTrace methodserrStream- stream printed to by the logErr methods
-
logMsg
prints a string to the log stream. All tests should use this method for standard logging messages- Parameters:
s- string to print to the log stream
-
logMsg
prints a string as well as the provided Throwable's stacktrace to the log stream. All tests should use this method for standard logging messages- Parameters:
s- string to print to the log streamt- - throwable whose stacktrace gets printed*
-
setTrace
public static void setTrace(boolean b) turns on/off debugging. Once on, all calls to the logTrace method result in messages being printed to the log stream. If off, all logTrace calls are not printed.- Parameters:
b- Iftrue, debugging is on. If false, debugging is turned off.
-
logTrace
prints a debug string to the log stream. All tests should use this method for verbose logging messages. Whether or not the string is printed is determined by the last call to the setTrace method.- Parameters:
s- string to print to the log stream
-
logTrace
Prints a debug string as well as the provided Throwable's stacktrace. Use this if certain exceptions are only desired while tracing.- Parameters:
s- - string to print to the log streamt- - throwable whose stactrace gets printed
-
logErr
prints an error string to the error stream. All tests should use this method for error messages.- Parameters:
s- string to print to the error streame- a Throwable whose stacktrace gets printed
-
logErr
prints an error string to the error stream. All tests should use this method for error messages.- Parameters:
s- string to print to the error stream
-
list
prints the contents of a properties object to the logging stream- Parameters:
p- properties to print
-
printStackTrace
prints the stacktrace of a Throwable to the logging stream- Parameters:
e- exception to print the stacktrace of
-
printStackTraceToString
prints the stacktrace of a Throwable to a string- Parameters:
e- exception to print the stacktrace of
-
separator2
public static void separator2()prints a line of asterisks to the logging stream -
separator1
public static void separator1()prints a line of dashes to the logging stream -
getResponse
Convience method to handle sucking in the data from a connection.- Throws:
IOException
-
getResponseProperties
Loads any properties that might be in a given String.- Throws:
IOException
-
getResponseProperties
One shot method to get Properties directly from a URLConnection.- Throws:
IOException
-
toEncodedString
-
sendPostData
- Throws:
IOException
-
getTableName
Parse a the table name from the ddl string such as: "create table foo" or "delete from foo"- Parameters:
value- buffer to parse- Returns:
- The name of the table
-
srcToDist
-
replaceLastSrc
-
getDistString
-
getRelativePath
-
strToProps
-
printProperties
-