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;
}
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);
}
Aggregations