public abstract class UnitTest extends Object
UnitTest accessor functions
Unit test cases can inherit from, or use a delegate of this class to access transactional abort mode, transactional deadlock detection, transactional leak detection and test timeouts. When using in junit test cases, call in @Before and @After functions :
@Before public void initializeTest() { this.initialize(); } @After public void completeTest() throws TransactionalMemoryLeakException, TransactionalDeadlockDetectedException { this.complete(); }
To avoid test timeouts during debugging sessions, timeouts are automatically disabled if the JVM was started with a Java agent option (e.g -agentlib...)
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_TIMEOUT_SECONDS
Default timeout for test cases
|
Constructor and Description |
---|
UnitTest()
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addVerboseTransactionalMemoryLeakDetection(String verboseClass)
Add verbose transactional memory leak detection for the specified class.
|
void |
complete()
Complete tests - should be called once after tests are run.
|
void |
disableTimeout()
Disable timeout for this test case :
|
void |
disableTransactionalAbortMode()
Disable abort mode for this test case :
|
void |
disableTransactionalDeadlockDetection()
Disable deadlock detection for this test case :
|
void |
disableTransactionalMemoryLeakDetection()
Leak detection is enabled by default for each test case - use this method to
disable :
|
static List<String> |
getNodes()
Determine list of nodes that are currently part of this cluster.
|
void |
initialize()
Initialize test settings - must be called once before tests are run.
|
boolean |
isTimeoutEnabled()
Determine if timeout is enabled
|
boolean |
isTransactionAbortModeEnabled()
Determine if abort mode is enabled
|
boolean |
isTransactionalMemoryLeakDetectionEnabled()
Determine if leak detection is enabled
|
boolean |
isTransactionDeadlockDetectionEnabled()
Determine if deadlock detection is enabled
|
void |
setTimeoutBehavior(Runnable runnable)
Override the default behavior to create node snapshot and exist the jvm
|
void |
setTimeoutSeconds(long timeoutSeconds)
Set the test case timeout - default is 300 seconds.
|
public static final long DEFAULT_TIMEOUT_SECONDS
public void initialize()
Initialize test settings - must be called once before tests are run. If called more than once, test settings are cleared and re-initialized.
This operation :
The replaying of transactions (including transactional memory timer events) in abort mode helps to verify that the unit under test handles transaction replays well. However, since non-transactional resources such as logger and Java heap are not rolled back and replayed, effects such as double logging may be observed when abort mode is enabled.
The system property ignoreLeaks can be set to a comma-separated list of class names - these class names are then ignored in the leak detection report.
public void complete() throws TransactionalMemoryLeakException, TransactionalDeadlockDetectedException
Complete tests - should be called once after tests are run. If called before complete, the operation does nothing.
This operation :
TransactionalMemoryLeakException
- One or more leaks were foundTransactionalDeadlockDetectedException
- One or more deadlocks were foundpublic void disableTransactionalMemoryLeakDetection()
Leak detection is enabled by default for each test case - use this method to disable :
@Test public void myTestCase() { this.disableTransactionalMemoryLeakDetection(); .. some leaky test case }
If already disabled, this operation does nothing.
Can be called at any time.
Note that its highly recommended to keep enabled but add classes that are meant to be persistent to the ignoreleak list in jar manifest files. See the ep-maven documentation for details.
public void addVerboseTransactionalMemoryLeakDetection(String verboseClass)
Add verbose transactional memory leak detection for the specified class. This must be called before the test framework is initialized, for example :
@Before public void initializeTest() { this.setVerboseTransactionalMemoryLeakDetection("com.tibco.ep.testing.framework.MO"); this.setVerboseTransactionalMemoryLeakDetection("com.tibco.ep.testing.framework.ExampleConfig"); this.initialize(); }
With this set, the leak reports include the managed object references of leaked objects along with the results of toString() for each of the leaked objects.
verboseClass
- class name to add to verbose leak reportpublic void disableTransactionalDeadlockDetection()
Disable deadlock detection for this test case :
@Test public void myTestCase() { this.disableTransactionalDeadlockDetection(); .. ignore deadlocks }
If already disabled, this operation does nothing.
Can be called at any time.
public void disableTransactionalAbortMode()
Disable abort mode for this test case :
@Test public void myTestCase() { this.disableTransactionalAbortMode(); .. disable abort mode }
If already disabled, this operation does nothing.
Can be called at any time.
public void disableTimeout()
Disable timeout for this test case :
@Test public void myTestCase() { this.disableTimeout(); .. disable timeout }
If already disabled, this operation does nothing.
Can be called at any time.
public void setTimeoutSeconds(long timeoutSeconds)
Set the test case timeout - default is 300 seconds. Timeout is stopped and re-started.
@Test public void myTestCase() { this.setTimeoutSeconds(400); .. }
timeoutSeconds
- Timeout in secondspublic void setTimeoutBehavior(Runnable runnable)
Override the default behavior to create node snapshot and exist the jvm
@Test public void myTestCase() { this.setTimeoutBehavior(new Runnable() { @Override public void run() { System.out.println("TIMEOUT!"); System.exit(-1); }; }); .. }
runnable
- code to execute on timeoutpublic boolean isTransactionalMemoryLeakDetectionEnabled()
Determine if leak detection is enabled
public boolean isTransactionDeadlockDetectionEnabled()
Determine if deadlock detection is enabled
public boolean isTransactionAbortModeEnabled()
Determine if abort mode is enabled
public boolean isTimeoutEnabled()
Determine if timeout is enabled
public static List<String> getNodes()
Determine list of nodes that are currently part of this cluster.
An example use is to make sure all nodes are discovered before starting test case :
@BeforeClass public static void waitForCluster() { for (int i = 0; i < 10; i++) { if (getNodes().size() == 2) { break; } try { Thread.sleep(500); } catch (InterruptedException e) { } } logger.info("Discovered nodes " + String.join(",", getNodes())); }
Copyright © 2015–2019 Cloud Software Group, Inc.. All rights reserved.