Interface JavaTestableGraph
-
- All Superinterfaces:
- ExecutableGraph<JavaTestableGraph>
public interface JavaTestableGraph extends ExecutableGraph<JavaTestableGraph>
An executable flow graph of Java primitive operators with support for disconnected input and output ports.
For the purpose of testing, behavior such as the separation of initialization and ports-ready notification, this class extendsExecutableGraph
to control the execution of the graph. Actions against the graph can be executed asynchronously to allow the testing of the graph and the operators in it during the actions, such as duringoperator initialization
.
Test programs can usegetInputTester(InputPortDeclaration)
to submit tuples and punctuation marks directly to the disconnected input ports.
Output from the disconnected output ports is verified by using handlers that are attached to the output ports withregisterStreamHandler(OutputPortDeclaration, StreamHandler)
.Java platform logging and Apache Log4j may continue to be used by operators executing within the graph. It is generally assumed that the framework being used has correctly initialized the loggers, by installing required handlers or appenders. If Apache Log4j has not been initialized then when a graph is created then the Apache Log4j root logger will have a
ConsoleAppender
pointing toSystem.err
installed.
The dynamic setting of SPL trace level is simulated by callingExecutableGraph.setTraceLevel(com.ibm.streams.operator.logging.TraceLevel)
.
The SPL log level may simulated by setting the level of the logger namedcom.ibm.streams.operator.log
for the logging system used by operators. If both Java platform logging and Apache Log4j are used by operators in the graph, then both loggers should have their level set to the desired level.- Since:
- InfoSphere® Streams Version 3.1
-
-
Method Summary
Methods Modifier and Type Method and Description java.util.concurrent.Future<JavaTestableGraph>
allPortsReady()
Asynchronously notify all the operator invocations in the graph that the ports are ready, and the submission of tuples can start.java.util.concurrent.Future<JavaTestableGraph>
completion()
Return aFuture
that completes when all the operator invocations in the graph have completed.StreamingOutput<OutputTuple>
getInputTester(InputPortDeclaration port)
Obtain aStreamingOutput
that can be used to submit test tuples and punctuation marks to a disconnected input port.OperatorContextMXBean
getOperatorContextMBean(OperatorInvocation<? extends Operator> operator)
Return a proxy to theOperatorContextMXBean
for an operator invocation.OperatorContextMXBean
getOperatorContextMBean(java.lang.String name)
Return a proxy to theOperatorContextMXBean
for the operator invocation namedname
.<T extends Operator>
TgetOperatorInstance(OperatorInvocation<T> operator)
Return the reference to the instance ofT
executing in this graph for invocation represented byoperator
.java.util.concurrent.Future<JavaTestableGraph>
initialize()
Asynchronously initialize all theOperator
invocations in the graph.void
registerStreamHandler(OutputPortDeclaration port, StreamHandler<Tuple> handler)
Register aStreamHandler
to a disconnected output port.java.util.concurrent.Future<JavaTestableGraph>
shutdown()
Asynchronously notify all theOperator
invocations in the graph of a shutdown request.JavaTestableGraph
waitForCompletion()
Wait for all the operator invocations to complete.-
Methods inherited from interface com.ibm.streams.flow.execute.ExecutableGraph
execute, executeToCompletion, setTraceLevel
-
-
-
-
Method Detail
-
initialize
java.util.concurrent.Future<JavaTestableGraph> initialize()
Asynchronously initialize all theOperator
invocations in the graph. When the returnedFuture
completes successfully, all the operators in the graph have been initialized.
For each operator, this results in calls to: The order of initialization is not defined across the operators.After successful initialization the graph is an a running state and is waiting for
allPortsReady()
orExecutableGraph.execute()
to be called, which allows tuple processing to start.
Once initialized the graph must be shutdown usingshutdown()
to ensure any resources opened by the operator or this graph are closed or shutdown.- Returns:
- A
Future
that completes once all operator invocations have been initialized. - See Also:
OperatorContextChecker
,Operator.initialize(com.ibm.streams.operator.OperatorContext)
-
allPortsReady
java.util.concurrent.Future<JavaTestableGraph> allPortsReady()
Asynchronously notify all the operator invocations in the graph that the ports are ready, and the submission of tuples can start. When the returnedFuture
completes successfully, all the operators in the graph have been notified.
This call results in a call toOperator.allPortsReady()
for each operator. The order of the port readiness notification is not defined across the operators.- Returns:
- A
Future
that completes after all the operator invocations are notified of port readiness. - See Also:
Operator.allPortsReady()
-
completion
java.util.concurrent.Future<JavaTestableGraph> completion()
Return aFuture
that completes when all the operator invocations in the graph have completed. When an operator without input ports completes (a source operator)final marks
are sent to all the output ports of the operator.
Once the graph is completeFuture.get()
returnsthis
.- Returns:
- A
Future
that completes after all the operator invocations have completed.
-
waitForCompletion
JavaTestableGraph waitForCompletion() throws java.lang.Exception
Wait for all the operator invocations to complete.- Returns:
- this
- Throws:
java.lang.Exception
-
shutdown
java.util.concurrent.Future<JavaTestableGraph> shutdown()
Asynchronously notify all theOperator
invocations in the graph of a shutdown request. When the returnedFuture
completes successfully, all then operators in the graph have been notified.
This call results in a call toOperator.shutdown()
for each operator. The order of shutdown is not defined across the operators.- Returns:
- A
Future
that completes after all the operator invocations are shut down. - See Also:
Operator.shutdown()
-
registerStreamHandler
void registerStreamHandler(OutputPortDeclaration port, StreamHandler<Tuple> handler)
Register aStreamHandler
to a disconnected output port. This call can be made multiple times to connect multipleStreamHandler
instances to a single output port, which allows for the testing of multiple aspects of the stream output.
All the tuples that are submitted by the output port are delivered toprocessor
.- Parameters:
port
- Disconnected output porthandler
- The handler that receives tuples and punctuation marks from the disconnected output port.- Throws:
java.lang.IllegalStateException
- The output port is connected.
-
getInputTester
StreamingOutput<OutputTuple> getInputTester(InputPortDeclaration port)
Obtain aStreamingOutput
that can be used to submit test tuples and punctuation marks to a disconnected input port.- Parameters:
port
- Disconnected input port- Returns:
- StreamingOutput that can be used to submit tuples and punctuation to the input port.
- Throws:
java.lang.IllegalStateException
- The input port is connected.
-
getOperatorContextMBean
OperatorContextMXBean getOperatorContextMBean(java.lang.String name)
Return a proxy to theOperatorContextMXBean
for the operator invocation namedname
.- Parameters:
name
- Name of the operator invocation- Returns:
- OperatorContextMXBean for the named operator.
-
getOperatorContextMBean
OperatorContextMXBean getOperatorContextMBean(OperatorInvocation<? extends Operator> operator)
Return a proxy to theOperatorContextMXBean
for an operator invocation.- Parameters:
operator
- Declaration of the operator invocation- Returns:
- OperatorContextMXBean for the named operator
-
getOperatorInstance
<T extends Operator> T getOperatorInstance(OperatorInvocation<T> operator)
Return the reference to the instance ofT
executing in this graph for invocation represented byoperator
. This may be used by testing code to verify state of the operator- Type Parameters:
T
- Class of operator invocation that implementsOperator
.- Parameters:
operator
- Operator invocation- Returns:
- Reference to the instance of
T
that is running within this graph. - Since:
- InfoSphere® Streams Version 3.2
-
-