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