Search in sources :

Example 1 with StringPredicateUserCondition

use of com.ibm.streamsx.topology.internal.tester.conditions.StringPredicateUserCondition in project streamsx.topology by IBMStreams.

the class RESTTesterRuntime method addConditionToStream.

/**
 * Add the conditions as for each operators that monitor the
 * condition and sets metrics.
 *
 * Then create a condition implementation that will monitor the
 * metrics using the REST api and link it to the user condition.
 */
@SuppressWarnings("unchecked")
private void addConditionToStream(TStream<?> stream, UserCondition<?> userCondition) {
    MetricCondition<?> condition = null;
    String name = null;
    Consumer<Object> fn = null;
    if (userCondition instanceof CounterUserCondition) {
        CounterUserCondition uc = (CounterUserCondition) userCondition;
        name = "count_" + id++;
        fn = new TupleCount<Object>(name, uc.getExpected(), uc.isExact());
        condition = new CounterMetricCondition(name, uc);
    } else if (userCondition instanceof ContentsUserCondition) {
        ContentsUserCondition<Object> uc = (ContentsUserCondition<Object>) userCondition;
        name = "contents_" + id++;
        fn = new TupleContents<Object>(name, uc.isOrdered(), uc.getExpected());
        condition = new MetricCondition<Object>(name, (UserCondition<Object>) userCondition);
    } else if (userCondition instanceof StringPredicateUserCondition) {
        StringPredicateUserCondition uc = (StringPredicateUserCondition) userCondition;
        name = "stringChecker_" + id++;
        fn = new StringPredicateChecker(name, uc.getPredicate());
        condition = new MetricCondition<Object>(name, (UserCondition<Object>) userCondition);
    }
    if (metricsChecker == null)
        throw new UnsupportedOperationException(userCondition.toString());
    TStream<Object> os = (TStream<Object>) stream;
    TSink end = os.forEach(fn);
    end.operator().layout().addProperty("hidden", true);
    if (os.isPlaceable())
        end.colocate(os);
    metricsChecker.addCondition(name, condition);
}
Also used : TupleContents(com.ibm.streamsx.topology.internal.tester.fns.TupleContents) TSink(com.ibm.streamsx.topology.TSink) UserCondition(com.ibm.streamsx.topology.internal.tester.conditions.UserCondition) CounterUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.CounterUserCondition) StringPredicateUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.StringPredicateUserCondition) ContentsUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.ContentsUserCondition) ContentsUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.ContentsUserCondition) TStream(com.ibm.streamsx.topology.TStream) StringPredicateUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.StringPredicateUserCondition) JsonObject(com.google.gson.JsonObject) StringPredicateChecker(com.ibm.streamsx.topology.internal.tester.fns.StringPredicateChecker) CounterUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.CounterUserCondition)

Aggregations

JsonObject (com.google.gson.JsonObject)1 TSink (com.ibm.streamsx.topology.TSink)1 TStream (com.ibm.streamsx.topology.TStream)1 ContentsUserCondition (com.ibm.streamsx.topology.internal.tester.conditions.ContentsUserCondition)1 CounterUserCondition (com.ibm.streamsx.topology.internal.tester.conditions.CounterUserCondition)1 StringPredicateUserCondition (com.ibm.streamsx.topology.internal.tester.conditions.StringPredicateUserCondition)1 UserCondition (com.ibm.streamsx.topology.internal.tester.conditions.UserCondition)1 StringPredicateChecker (com.ibm.streamsx.topology.internal.tester.fns.StringPredicateChecker)1 TupleContents (com.ibm.streamsx.topology.internal.tester.fns.TupleContents)1