com.ibm.streamsx.topology.tester

Interface Condition<T>



  • public interface Condition<T>
    A test condition on a stream or application under test. A condition is created on a stream to allow testing of the contents of the stream. Conditions are also used to define when a execution of a topology for testing is completed, for example at least N tuples have been seen on the stream.
    While the topology is executing then the state of the condition may change.

    In a consistent region a condition exhibits exactly once behavior. For example an exact tuple count condition placed against the stream will become valid when the tuple count is reached taking the resets into account, even though more tuples may have been seen on the stream. This is because the conditions are stateful and part of the consistent region.
    After a region reset or failure the condition's state is reset to the last consistent state. For example with a tuple count condition on a stream of 1,000 tuples assume the region became consistent after 800 tuples. Subsequently a failure occurs after 950 tuples, the region is reset, and the tuple counter condition is reset to 800 tuples. The source operator then replays any required tuples and after another 200 tuples the condition becomes valid, even though the stream actually processed 1,150 tuples.
    If at least once behavior is required for a condition on a stream then it can be placed outside of the region by applying it to an autonomous stream created from the stream in the region:

     
     TStream s = ...;
     
     // Add a condition that will perform at least once behavior
     // and count all tuples seen on s including any replayed tuples.
     s.autonomous().atLeastTupleCount(1150);
     
     

    Since:
    1.9 Support for consistent region added., 1.11 getResult() deprecated.
    See Also:
    Tester.atLeastTupleCount(com.ibm.streamsx.topology.TStream, long), Tester.tupleCount(com.ibm.streamsx.topology.TStream, long), Tester.tupleContents(com.ibm.streamsx.topology.spl.SPLStream, com.ibm.streams.operator.Tuple...), Tester.stringContents(com.ibm.streamsx.topology.TStream, String...), Tester.stringContentsUnordered(com.ibm.streamsx.topology.TStream, String...)
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method and Description
      static Condition<java.lang.Boolean> all(Condition<?>... conditions)
      Return a condition that is true if all conditions are valid.
      default Condition<java.lang.Boolean> and(Condition<?>... conditions)
      Return a condition that is true if this AND all conditions are valid.
      boolean failed()
      Has the condition failed.
      T getResult()
      Deprecated. 
      Since 1.11. In most distributed environments specific results cannot be obtained from conditions (such as stream contents) due to network isolation. While the condition will correct report its failed or valid state tests should no longer rely on using this method to perform additional testing. An alternative is to use stringTupleTester to perform a per-tuple check.
      boolean valid()
      Test if this condition is valid.
    • Method Detail

      • valid

        boolean valid()
        Test if this condition is valid.
        Returns:
        true if this condition is valid, false otherwise.
      • getResult

        T getResult()
        Deprecated. Since 1.11. In most distributed environments specific results cannot be obtained from conditions (such as stream contents) due to network isolation. While the condition will correct report its failed or valid state tests should no longer rely on using this method to perform additional testing. An alternative is to use stringTupleTester to perform a per-tuple check.
        Get the result for this condition.
        Returns:
        result for this condition.
        Throws:
        java.lang.UnsupportedOperationException - Test environment does not support fetching results.
      • failed

        boolean failed()
        Has the condition failed. Once a condition fails, it can no longer become valid, for example a Tester.tupleCount(com.ibm.streamsx.topology.TStream, long) fails once it the stream has received more tuples than the expected count.
        Returns:
        True if the condition can not become valid, false otherwise.
        Since:
        1.7
      • and

        default Condition<java.lang.Boolean> and(Condition<?>... conditions)
        Return a condition that is true if this AND all conditions are valid. The result is a Boolean that indicates if all conditions is valid.
        Parameters:
        conditions - Conditions to be ANDed together.
        Returns:
        Condition that is valid if all conditions are valid.
      • all

        static Condition<java.lang.Boolean> all(Condition<?>... conditions)
        Return a condition that is true if all conditions are valid. The result is a Boolean that indicates if all conditions is valid.
        Parameters:
        conditions - Conditions to be ANDed together.
        Returns:
        Condition that is valid if all conditions are valid.
streamsx.topology 2.1 @ IBMStreams GitHub