Class FlowTester

    • Constructor Detail

      • FlowTester

        public FlowTester()

        Create a new flow tester. Use as an expression in a try-with-resources block so that tester is automatically cleaned up, otherwise non-daemon threads will left hanging around and interfere with test life cycle. If running in a TIBCO Streaming node environment, then the underlying TCS engine can be configured, and can accept flow configurations, via TIBCO Streaming configuration services. Note that if you have instantiated multiple flow testers inside a single unit test method, then the most-recently constructed flow tester will be the only one that can be configured via configuration services.

    • Method Detail

      • init

        public void init()
                  throws TCSRuntimeException

        Initialize a flow tester. The flow tester has access to all block types found in the current thread's context class loader. If you want to use an alternate class loader containing block implementations, then set the current thread's context class loader to that alternate prior to invoking this method.

        Throws:
        TCSRuntimeException - if the flow tester cannot be initialized
      • runFlow

        public void runFlow​(FlowConfig flowConfig)
                     throws TCSRuntimeException

        Start this tester's flow. Blocks until all of the flow's stream input blocks are ready. Alternatively, if you know you are running your tests within a TIBCO StreamBase node environment, you can use TIBCO StreamBase configuration services to run a flow by loading and activating a flow configuration.

        Parameters:
        flowConfig - the flow to run
        Throws:
        TCSRuntimeException - if the flow has errors
      • close

        public void close()

        Shut down this tester. The tester cannot be used after invoking this method.

        Specified by:
        close in interface AutoCloseable
      • enqueueTuple

        public void enqueueTuple​(String blockInstanceID,
                                 FlowTester.ITupleInitializer initializer)
                          throws TCSRuntimeException

        Enqueue a tuple on the specified flow block instance.

        Parameters:
        blockInstanceID - block to enqueue the tuple on. Must be of type com.tibco.ep.tcs.runtime.block.builtin.StreamInput
        initializer - tuple initializer, called after the tuple is created and prior to its enqueue
        Throws:
        TCSRuntimeException - the engine isn't running a flow, the block doesn't exist, or it's the wrong type
      • initTupleDequeue

        public FlowTester.TupleDequeueHandle initTupleDequeue​(String blockInstanceID,
                                                              long pollMS)
                                                       throws TCSRuntimeException

        Initialize tuple dequeueing from the specified block instance ID.

        Parameters:
        blockInstanceID - block to dequeue tuples from. Must be of type com.tibco.ep.tcs.runtime.block.builtin.StreamOutput
        pollMS - number of milliseconds to poll when executing dequeue operations on the returned handle
        Returns:
        a dequeue handle used to dequeue tuples
        Throws:
        TCSRuntimeException - the engine isn't running a flow, the block doesn't exist, or it's the wrong type
      • createBlockTesterFor

        public BlockTester createBlockTesterFor​(String blockID)
                                         throws TCSRuntimeException

        Create a block tester for the specified block ID.

        Parameters:
        blockID - block type identifier
        Returns:
        block tester
        Throws:
        TCSRuntimeException - if the block doesn't exist
      • setTupleLogging

        public Collection<FlowEngine.TupleLoggingInfo> setTupleLogging​(Optional<String> portPathRegexp,
                                                                       boolean enabled)
                                                                throws TCSRuntimeException

        Set tuple logging.

        Parameters:
        portPathRegexp - optional port path - if non null, setting applies only to those FQ port names matching the supplied unanchored regexp. If null, setting applies to tuple logging on all ports.
        enabled - true if logging is enabled, false if disabled
        Returns:
        a collection of tuple logging status information showing what was done
        Throws:
        TCSRuntimeException - if the supplied regular expression is invalid
      • getTupleLogging

        public Collection<FlowEngine.TupleLoggingInfo> getTupleLogging​(Optional<String> portPathRegexp)
                                                                throws TCSRuntimeException

        Display tuple logging info as a map of logging status (enabled or disabled), indexed by port path

        Parameters:
        portPathRegexp - optional port path - if non null, display applies only to those FQ port names matching the supplied unanchored regexp. If null, display tuple logging status on all ports.
        Returns:
        a collection of tuple logging status information
        Throws:
        TCSRuntimeException - if the supplied regular expression is invalid