UIMA-AS Testing Utilities
A brief guide to the utilities for helping
to construct uima-as test cases
Last updated: October, 2013
Test cases run lots of asynchronous parts. The main flow is to have a test case set things up, and then
set up 1 or more monitor threads that will await various latch countdowns (EXCEPTION, CPC, PROCESS).
The monitor threads are "joined" back in the main thread. There's an extra semiphore that is used to delay
sending the first CAS until all monitor threads have started up.
CASes in the system are assigned Cas Ref Ids, which are UUIDs.
There are 2 support / utility classes, with this inheritance:
BaseTestSupport -> ActiveMQSupport -> TestCase
ActiveMQSupport
Starting / stopping broker(s)
-
setup() creates and starts broker
creates, starts broker, addHttpConnector(port = 18888)
Sets system properties:
DefaultBrokerUrl = broker:()/localhost?persistent=false
DefaultHttpBrokerUrl = http://localhost:[portNumber]
-
teardown clears two System properties and stops broker
clear System properties activemq.broker.jmx.domain, BrokerURL
-
cleanBroker(BrokerService broker) sometimes done before stopping
deleteAllMessages - removes messages from all queues
goes thru all known Client connections and "stop()"s them
goes thru all non-topic destinations and removes them
Typical use:
stop-uima-client;
cleanBroker(broker2);
broker2.stop()
broker2.waitUntilStopped();
-
stopBroker() stops main broker
broker, tcpConnector
stop tcpConnector
, removeConnector from broker, removeHttpConnector, deleteAllMessages, stop broker, waitUtilStopped
BrokerConnectors
-
addHttpConnector( [broker], port-number) returns Uri String
set-field TransportConnector httpConnector
Iterates with increasing port-number in case port in use
-
getHttpURI() returns Uri String of field httpConnector
-
removeHttpConnector()
stops httpConnector
removes httpConnector
from broker
-
addConnector(broker, type, basePort) returns TransportConnector
starting with basePort, incr port till get a good return from broker.addConnector using localhost:port
-
getBrokerUri()
uri
-
getConnection() returns Connection
from uri
-
createBroker( [port, useJmx, isSecondaryBroker]) returns BrokerService, used for main broker and 2ndry broker
broker uri broker:()/localhost?persistent=false
sets tcpConnector
to a tcp style connector at the port (default 61617)
if isSecondaryBroker, changes tcpConnector name and JmxDomainName gets ".test" added
-
setupSecondaryBroker(boolean addProperty) returns broker instance
sets system property activemq.broker.jmx.domain = org.apache.activemq.test
creates a secondary broker (calls createBroker(61620, true, treu)
and starts it.
if addProperty, adds system property BrokerURL
BaseTestSupport
Inherits from ActiveMQSupport
deployService(asyncEngine - to hold ref, deploydescriptorPath) returns UUID string
uses SystemProp: BrokerURL or tcp://localhost:8118, sets defaultBrokerURL
addxceptionToIgnore, ignoreException
initialize(asyncEngine, appCtx) calls initialize on engine after adding statusCallbackListener of listener
which is set to a new instance of UimaAsTestCallbackListener, a subclass of this class
buildContext(top-level-svc-broker-uri, top-level-queue-name, [timeout default 0]) returns appCtx map
sets CasPoolSize to 4, ReplyWindow to 15
isMetaRequest(Message)
spinMonitorThread(ctrlSemaphore, howMany, kind) returns thread that will wait
for howMany count-downs; returned threads are typically joined.
Kind/latches: cpcLatch, exceptionCountLatch, processCountLatch
waitUntilInitialized() signalled by callback, set up for one use per test instantiation
initializeMonitor, initialized
waitOnMonitor(Semaphore) used to wait until all monitor threads are spun
runTestWithMultipleThreads(svc-deploy-descr, q-name, how-many-CASes=per-thread, how-many-threads,
timeout, getmeta-timeout, [fail-on-timeout])
engine
= new asyncEngine
deploy into engine, initialize engine
if fail-on-timeout
, set timer task to undeploy in 5 seconds
spin up runner threads and have them send CASes, one at a time
wait till all CASes received, then wait till CPC done
runCrTest(engine, howMany) Run using collection reader
set engine
from the passed-in engine
The engine needs to be set up with a collection reader and
the standard listeners to count down the
PROCESS_LATCH
runTest(2)(appCtx, engine, brokerUri, q-name, howMany, latchKind, is-async-send)
sets engine
if latchKind is EXCEPTION_LATCH, use 1 thread for running client,
else use 2 - one for client, and one for CPC
if runTest, send all CASes at once (up to pool limit) up to howMany.
If runTest2, send each CAS 1 at a time, and wait until it is complete including CPC.
After howMany
CASes, send CPC and wait for completion.
sendCAS(engine, howMany, isAsync)
Gets CAS from casPool, sets doc txt, calls sendCas or SendAndReceiveCAS
spinShutdownThread(asyncEngine, when, [springContainerIds, stop_now or quiesce])
after specified delay, tops either the async engine, or the deployed things. Used
to test recovery from svcs dying
UimaTestCallbackListener
onBeforeProcessCAS writes logmsg to sysout
onBeforeMessageSend writes Received ... notivication with CAS [casRefId]
sets casSent to casRefId)
onUimaAsServiceExit logs msg with cause
entityProcessComplete might have performance metrics or not...
verifies (on exception) receivedExpectedParentReferenceId
For successful test, gets processTraceEvents, checks duration is what's expected expectedProcessTime
For perform metrics: add per-component-performance-metrics to sysout log
isProcessTimeout
initializationComplete
collectionProcessComplete
SimpleCallbackListener
extends UimaTestCallbackListener, overrides entityProcessComplete with a much simpler check/report