Search in sources :

Example 1 with ContentsUserCondition

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

the class HandlerTesterRuntime method testStateFromConditions.

protected final TestState testStateFromConditions(boolean complete, boolean checkCounters) {
    TestState state = VALID;
    if (checkCounters && lastConditionState == null)
        lastConditionState = new HashMap<>();
    for (UserCondition<?> condition : allConditions) {
        if (condition.failed()) {
            // fail one fail all!
            state = FAIL;
            break;
        } else if (!condition.valid()) {
            if (complete) {
                state = FAIL;
                break;
            } else if (checkCounters) {
                if (condition instanceof CounterUserCondition) {
                    CounterUserCondition counter = (CounterUserCondition) condition;
                    long result = counter.getResult();
                    Long last = lastConditionState.get(counter);
                    if (last == null || result <= last)
                        state = NO_PROGRESS;
                    else
                        state = PROGRESS;
                    lastConditionState.put(counter, result);
                } else if (condition instanceof ContentsUserCondition) {
                    ContentsUserCondition<?> contents = (ContentsUserCondition<?>) condition;
                    if (!contents.getExpected().isEmpty()) {
                        long result = contents.getResult().size();
                        Long last = lastConditionState.get(contents);
                        if (last == null || result <= last)
                            state = NO_PROGRESS;
                        else
                            state = PROGRESS;
                        lastConditionState.put(contents, result);
                    }
                }
            } else
                state = NO_PROGRESS;
        }
        if (state == FAIL)
            break;
    }
    return state;
}
Also used : HashMap(java.util.HashMap) ContentsUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.ContentsUserCondition) CounterUserCondition(com.ibm.streamsx.topology.internal.tester.conditions.CounterUserCondition)

Example 2 with ContentsUserCondition

use of com.ibm.streamsx.topology.internal.tester.conditions.ContentsUserCondition 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

ContentsUserCondition (com.ibm.streamsx.topology.internal.tester.conditions.ContentsUserCondition)2 CounterUserCondition (com.ibm.streamsx.topology.internal.tester.conditions.CounterUserCondition)2 JsonObject (com.google.gson.JsonObject)1 TSink (com.ibm.streamsx.topology.TSink)1 TStream (com.ibm.streamsx.topology.TStream)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 HashMap (java.util.HashMap)1