public static interface Grinder.ScriptContext
net.grinder.script.Grinder.grinder
object that supports this interface.| Modifier and Type | Method and Description |
|---|---|
Barrier |
barrier(java.lang.String name)
Create a
Barrier to coordinate worker thread actions across
running worker processes. |
int |
getAgentNumber()
Return the agent number.
|
int |
getFirstProcessNumber()
Return the process number of the first worker process.
|
Logger |
getLogger()
Get a
org.slf4j.Logger. |
java.lang.String |
getProcessName()
Get a unique name for this worker process.
|
int |
getProcessNumber()
Return the process number.
|
GrinderProperties |
getProperties()
Get the global properties for this agent/worker process set.
|
int |
getRunNumber()
Return the current run number, or
-1 if not called from a
worker thread. |
SSLControl |
getSSLControl()
Get an
SSLControl. |
Statistics |
getStatistics()
Get a
Statistics object that allows statistics to be queried
and updated. |
int |
getThreadNumber()
Return the thread number, or
-1 if not called from a
worker thread. |
void |
sleep(long meanTime)
Sleep for a time based on the meanTime parameter.
|
void |
sleep(long meanTime,
long sigma)
Sleep for a time based on the meanTime parameter.
|
int |
startWorkerThread()
Start a new worker thread.
|
int |
startWorkerThread(java.lang.Object testRunner)
Start a new worker thread, specifying a test runner instance.
|
void |
stopThisWorkerThread()
Stop this worker thread immediately and cleanly.
|
boolean |
stopWorkerThread(int threadNumber)
Request a specific worker thread to stop.
|
int getAgentNumber()
The lowest possible number is allocated. When an agent disconnects, its
number will be reused. Script authors can assume that the agent number
lies between 0 and the number of currently connected
agents.
-1 if not launched from the
console.getProcessNumber(),
getThreadNumber()int getProcessNumber()
getAgentNumber(),
getThreadNumber(),
getFirstProcessNumber()java.lang.String getProcessName()
getProcessNumber()int getFirstProcessNumber()
Process numbers are assigned incrementally, so the expression
(grinder.getProcessNumber() - grinder.getFirstProcessNumber())
can be used to as a zero based index for this process against an array
of test data.
getProcessNumber()int getThreadNumber()
-1 if not called from a
worker thread.getAgentNumber(),
getProcessNumber()int getRunNumber()
-1 if not called from a
worker thread.int value.Logger getLogger()
org.slf4j.Logger.Logger.void sleep(long meanTime)
throws GrinderException
meanTime - Mean time in milliseconds.GrinderException - If the sleep failed.void sleep(long meanTime,
long sigma)
throws GrinderException
meanTime - Mean time in milliseconds.sigma - The standard deviation, in milliseconds.GrinderException - If the sleep failed.int startWorkerThread()
throws GrinderException
TestRunner class
will be used to create new test runner instance for the worker thread.InvalidContextException - If the main thread has not yet
initialised the script engine, or all other threads have shut down.
Typically, you should only call startWorkerThread() from
another worker thread.GrinderException - If the new worker thread could not be started.int startWorkerThread(java.lang.Object testRunner)
throws GrinderException
This is a more advanced version of startWorkerThread() that
allows a different test runner to be specified. The test runner should
be a function or a callable object.
testRunner - A function, or some other callable object.InvalidContextException - If the main thread has not yet
initialised the script engine, or all other threads have shut down.
Typically, you should only call startWorkerThread() from
another worker thread.GrinderException - If the new worker thread could not be started.void stopThisWorkerThread()
throws InvalidContextException
This method works by throwing a special unchecked exception. If the caller catches this exception, rather than letting it propagate, the thread will not stop.
InvalidContextException - If called from a non-worker thread.boolean stopWorkerThread(int threadNumber)
Test.threadNumber - The thread number of the worker thread to stop.true if a thread existed with the given
threadNumber, otherwise false.GrinderProperties getProperties()
Statistics getStatistics()
Statistics object that allows statistics to be queried
and updated.SSLControl getSSLControl()
SSLControl. This can be used to create secure
sockets or to set the certificates that a worker thread should
use.Barrier barrier(java.lang.String name) throws GrinderException
Barrier to coordinate worker thread actions across
running worker processes.
Example script:
from net.grinder.script.Grinder import grinder
class TestRunner:
def __init__(self):
# Each worker thread joins the barrier.
self.phase1CompleteBarrier = grinder.barrier("Phase 1")
def __call__(self):
# ... Phase 1 actions.
# Wait for all worker threads to reach this point before proceeding.
self.phase1CompleteBarrier.await()
# ... Further actions.
name - The barrier name.GrinderException - If the barrier could not be created due to a network problem.Barrier