com.ibm.streams.flow.javaprimitives

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 extends ExecutableGraph 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 during operator initialization.
    Test programs can use getInputTester(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 with registerStreamHandler(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 to System.err installed.
    The dynamic setting of SPL trace level is simulated by calling ExecutableGraph.setTraceLevel(com.ibm.streams.operator.logging.TraceLevel).
    The SPL log level may simulated by setting the level of the logger named com.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 Detail

      • 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 returned Future completes successfully, all the operators in the graph have been notified.
        This call results in a call to Operator.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 a Future 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 complete Future.get() returns this.
        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 the Operator invocations in the graph of a shutdown request. When the returned Future completes successfully, all then operators in the graph have been notified.
        This call results in a call to Operator.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 a StreamHandler to a disconnected output port. This call can be made multiple times to connect multiple StreamHandler 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 to processor.
        Parameters:
        port - Disconnected output port
        handler - 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 a StreamingOutput 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 the OperatorContextMXBean for the operator invocation named name.
        Parameters:
        name - Name 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 of T executing in this graph for invocation represented by operator. This may be used by testing code to verify state of the operator
        Type Parameters:
        T - Class of operator invocation that implements Operator.
        Parameters:
        operator - Operator invocation
        Returns:
        Reference to the instance of T that is running within this graph.
        Since:
        InfoSphere® Streams Version 3.2